Use a terminal session to:

  1. Find the following files and directories: Put the full path names in a file called Eureka. (0.75%)

  2. Write a script that accepts two file name extensions as arguments, and renames all files with the first extension to have the second extension. For example, ChangeExtensions txt text would change all .txt files to be .text files. Hint: read the man pages for basename. The script must check that two arguments have been provided, and exit with an error message if not. The script must check if there are any files with the first extension, and exit with an error message if there are none. If all goes well, a message must be output for each filename that is changed. (1.0%)
    Answer
    #!/bin/tcsh
    
    if ($#argv != 2) then
        echo "You must provide two file extensions as arguments"
        exit
    endif
    
    if (`ls *.$1 |& grep -c "No match"` == 1) then
        echo "There are no files with the extension .$1"
        exit
    endif
    
    foreach file (*.$1)
        mv $file `basename $file .$1`.$2
        echo "Renamed $file to `basename $file .$1`.$2"
    end
    

  3. Making files and directories
    • Make a directory called LabTask2 off your home directory.
      Answer
      mkdir LabTask2
      cd LabTask2 
    • Off LabTask2, a subdirectory called Originals
      Answer
      mkdir Originals 
    • In Originals two files, HardStuff and SoftStuff (put any garbage in them)
      Answer
      cd Originals
      touch HardStuff SoftStuff 
      cd .. 
    • Off LabTask2, a subdirectory called Links
      Answer
      mkdir Links 
      cd Links 
    • In Links
      • A hard link named LinkToHardStuff that links to HardStuff in Originals.
        Answer
        ln /home/ugrad/xxxx322/LabTask2/Originals/HardStuff LinkToHardStuff 
      • A relative soft (symbolic link) link named RelativeToSoftStuff to SoftStuff in Originals.
        Answer
        ln -s ../Originals/SoftStuff RelativeToSoftStuff 
      Put the commands that you used to do these into a file named Links. (0.75%)

  4. Create a directory called IveGotRights off LabTask2. Set its permissions to:
    • Read, write, and execute permission for the owner
    • Read and execute permission for the group
    • Execute permission for others
    Put the commands that you used to do these into a file named Permissions. (0.5%)
    Answer
    mkdir IveGotRights
    chmod 751 IveGotRights 
    or, for wimps ...
    chmod o=rwx,g=rx,o=x IveGotRights 
    or, for very wimps ...
    chmod u=rwx IveGotRights 
    chmod g=rx IveGotRights
    chmod o=x IveGotRights