LukeSpence.com

basic UNIX commands & utilities

 

date displays the date and time

pwd print working directory. Displays your current working directory

ls list files and directories; try with options -a, -l

man displays the manual pages for a command. For example, typing man ls displays the manual pages for the ls command.

clear clears the screen

passwd changes your password. You will be prompted to enter your current password and your newly chosen password twice (for verification).

stty -a displays a list of terminal metacharacters

mkdir make directory. Creates directories. For example, if you are currently in your home directory you can create a subdirectory called vim by typing mkdir vim.

cd change directories. Lets you move from one directory to another. Just typing cd and then hitting Enter will send you to your home directory. Typing cd ~ will do the same. For example, if you just created the directory vim as in the example above, you can change to that directory by typing cd vim at your prompt. After doing so, I suggest typing pwd to display your working directory. Note the difference as compared with your earlier use of the pwd command. Then type cd .. to take you to the parent directory of your current working directory. Again, type pwd to display your current working directory. Type ls to see a listing of your directories and files. You should see your vim directory in the list.

cp copy. Lets you create copies of other files. The files can be located in any other user's directories, as long as they are readable. For example, from your home directory type cp ~zieglerm/vim/vitutor vitutor. You have just copied a file in my vim subdirectory named vitutor and copied it to your home directory. If you type ls, you will see a file called vitutor in your home directory.

mv move. Lets you move files from one directory to another. Also lets you rename files. You just move the file to the same directory but give it a different name. For example, if you are in your home directory, entering mv vitutor ./vim/vitutor will move the file called vitutor from your current working directory (your home directory) to your vim directory. If you type ls you will see the file vitutor is no longer there. Type cd vim to change directories to your vim directory and type ls. You should see your file there now.

To see how mv lets you rename files, lets first make another copy of vitutor called tutor by entering cp vitutor tutor. Type ls. You should see 2 files in your vim directory. One is called vitutor and the second is called tutor. Type mv tutor tutor2 to rename the file tutor to tutor2. Type ls to verify this. While we're at it, let's make a third copy of our file called tutor3 by typing cp tutor2 tutor3. Type ls to verify you now have three files: vitutor, tutor2, tutor3.

rm remove. Lets you remove or delete files. For example, to remove the file tutor3 we just created above, we would enter rm tutor3. Type ls to verify the file is no longer there. Note: If you were in you home directory instead of the vim subdirectory, we would have typed rm ./vim/tutor3. Remember that stuff about relative pathnames?

rmdir remove directory. Lets you delete directories. For example, lets type cd to get back to your home directory. Then create a directory called test1 by typing mkdir test1. Type ls to verify this subdirectory exists. Then change to this directory by typing cd test1. Type ls -al to see that the test1 directory is empty. We do this to make sure the directory is empty. Since the directory is empty, we can delete it with rmdir. Note: Never try to remove a directory that contains other files and directories. You may end up causing yourself more headaches than you need. First, move back one directory to your home directory by typing cd ... Type ls to see your test1 directory. Then type rmdir test1 to remove the directory. Type ls again to see that the test1 directory has been removed.

more displays a file one screen at a time. For example, change directories to your vim subdirectory by typing cd vim. Type ls to display your files. One of your files should be called vitutor. Enter more vitutor to display this file one screen at a time. Press the space bar to display the next screen. If the file is really long, you may want to exit without hitting the space bar 1,000 times. Simple type Control-C to terminate the command.

page displays a file one page at a time. Very similar to more. For example, typing page vitutor displays the file one page at a time. Again, you may type Control-C to exit.

head displays the first 10 lines of a file by default. For example, typing head vitutor will display the first 10 lines of the file vitutor. Typing head -2 vitutor will display the first 2 lines of the file.

tail displays the last 10 lines of a file by default. For example, typing tail vitutor will display the last 10 lines of the file vitutor. Typing tail -2 vitutor will display the last 2 lines of the file.

vi the vi editor. We will use the vi editor to write our programs. To open the vitutor file with the vi editor, we type vi vitutor. Note: Do not be confused because I have the letters vi in the name of the file we are opening. You are automatically in command mode when you open the file. You cannot just start typing on the screen. To exit the vi editor, we simply type ESC followed by :q!. You should notice the :q! on the bottom left-hand corner of the screen. Then hit ENTER. You should be back at your prompt.

exit exit your account. Type exit to end your UNIX session.