More UNIX Commands

The Commands

zmail
- How you will mail your files to me. You will most likely be able to do the same things through the Zmail graphical user interface.
cp
- This command can copy a file into the same directory or into a different directory.
mv
- This command is similar to copy, but instead of copying the file, it moves the file. This can be used for renaming files also.
mkdir
- This allows you to make a directory.
rm
- This command lets you remove or delete a file.
rmdir
- This works the same way as the MS-DOS rmdir and removes an empty directory.
head
- This command allows you to display only the top lines of a file.
head -n filename displays the top 'n' lines of the file called filename.
tail
- This command is similar to head except that it displays the last lines of a file.
tail -n filename displays the last 'n' lines of the file called filename.
man
- Look at the on-line manual pages. If you don't remember how to use a command, just look it up in the manual pages. For example, if you forgot how to use the ls command or need to know more about its options, type man ls.
sort
- Allows you to sort a file (or standard input - I'll explain standard input and standard output later).
cal
- Displays a calendar.

Some Exercises

  1. Go to your home directory
    cd 
  2. Take a look at the file ~escobj/public/emacs
    cat ~escobj/public/emacs
  3. Now copy the emacs file into your home directory. A dot (.) is the current working directory which in this case is your home directory
    cp ~escobj/public/emacs .
  4. Now take a look at the files in your home directory and see if you find the emacs file.
    ls
  5. Among the other files and directories in your home directory, you should see the emacs file. Take a look at this file.
    cat emacs
  6. It should look the same as the ~escobj/public/emacs file. Now rename the file. Call the new name mac.
    mv emacs mac



  7. Did it work? How can you tell if it worked? (list the contents of the directory and make sure that emacs is not there and that mac is there.)
    ls
  8. Now move the mac file into your public directory.
    mv mac public
  9. Check to see if it worked. Make sure it's not in your home directory then go into your public directory and see if it's there.
    ls
    cd public
    ls
  10. Let's move the mac file back to your home directory. There are a few ways of doing this - here is one.
    mv mac ..
  11. Go back to your home directory and verify that the mac file is back in your home directory (I'm not going to tell you how to do it this time). Then make a new directory called new_dir.
    cd
    mkdir new_dir
  12. List the contents again, but this time put a -F option on the ls command and see what happens. (Note : If you type ls -l and look at the output, you'll see a string something like 'drwxr-xr-x' next to the directories and something like '-rw-r-r-' next to the files. The 'd' in that string tells you that the file is actually a directory.)
    ls -F
  13. You should see that the directories are followed by a slash (/), normal files look the same, executables (we haven't talked about that yet) have an asterisk (*), and links (haven't talked about this either) have an at sign (@) at the end. You should have seen the directory you just created, new_dir. Now, copy your mac file into the new_dir directory.
    cp mac new_dir
  14. Verify that this happened and then cd into the new directory. (Try it on your own this time.)

  15. Copy the mac file to a file in the same directory. Name the file junk.
    cp mac junk
  16. Again, verify with the ls command. Now, get rid of the mac file with the rm command and verify that it's gone. ( From now on, I'm not going to ask you to verify anything - just do it if you want to, else don't bother)
    rm mac
    
    
    
    
    
  17. We are currently in the new_dir directory. Go back to your home directory and TRY to remove the new_dir directory.
    cd
    rmdir new_dir
  18. You should have gotten an error message that said ``rmdir: junk: File exists''. rmdir will only remove directories that are empty. So, go back into the new_dir directory and remove the file called junk, cd back to your home directory and try again to remove the new_dir directory. It should work this time. (Note : You can use rm -r new_dir to remove the directory and all the files it contains)
    cd new_dir
    rm junk
    cd ..
    rmdir new_dir
  19. Now rename your first copy of mac to .emacs by using the mv command. Don't forget the dot.
    mv mac .emacs
    
  20. Now TRY to find the file be using ls.

  21. It's not there! To see it, use the -a option. a for ALL.
    ls -a
    
  22. What happened was the prefix . made the .emacs file into a hidden file. You were probably surprised to see that you had a lot more files than you had originally thought. These files are usually command files for different programs and you usually don't want to fool around with them unless you know what you're doing. The .emacs adds some cool functionality to your original emacs program. What it does is colorize C and C++ code. Try it by editing one of my old C++ files from computing languages. It is in my public directory called sample.C. First copy the file to your home directory.
    cp ~escobj/public/sample.C .
    emacs sample.C
    
  23. Now that you have emacs up, call me up to verify that it worked correctly. I also want to copy down your USER ID so that I can make a link to your future homepage on our Computer Science I web-site!
  24. Practice cutting and pasting in emacs by highlighting text and using the cut and paste options from the Edit window.
  25. Finally, figure out how to use the cal command yourself by looking it up in the manual pages.
    man cal