Unix commands have the general format:
command [options] [item]
Items in brackets are optional, and words in italics are generic identifiers (i.e. options must be replaced by a particular option, e.g. -a).
Commands are case sensitive. The command ls is different from LS. In fact LS is not recognised as a valid command.
Command options consist of a single character. The command to list all the files in a directory is ls -a and could not be ls -all (the latter would have to mean a combination of options.)
Command options can usually be combined or listed separately. For example:
ls -al or ls -a -l
The command item is given last. This is very often a file name. For example:
ls -a file1.f not ls file1.f -a
The echo command 'echoes' its argument to the standard output. This means that in its simplest form it prints something out on screen. For example:
% echo Hello - you type Hello - response from the shell%
The command who gives a list of logged on users:
% who root console Jan 4 10:34 men6matw ttyp1 Jan 6 09:45 (ecusun1) cbl6nd ttyp2 Jan 6 10:10 (cblslcd) cbl6ar ttyp3 Jan 6 16:03 (cblsuna) csc6ea ttyp4 Jan 6 14:15 (csuna1) root ttyp5 Jan 6 10:40 (sun032) ecl6rsh ttyp6 Jan 6 15:39 csc6ea ttyp8 Jan 6 14:15 (csuna1) lnp5mw ttyUf Jan 6 16:16 lnp5jb ttyp3 Jan 6 15:20 (sun051)
Also try the command finger. This command gives the full name of logged in users.
Type finger to get information on yourself and other users.
% mkdir directory_name
Jenny Brown stores her unix scripts in a directory called scripts beneath her home directory. In order to create this directory she uses the command:
% mkdir scripts
% rmdir directory_name
Jenny Brown stores files for project work in a directory called proj. When the project has been completed she deletes the directory using the command:
% rmdir proj
Note that the directory must be empty before it can be deleted.
% ls file1 scripts test.f test
Notice that directories are listed as well as files. To list all files, including hidden files, give the command:
% ls -a .cshrc file1 bin test.f test
Hidden files begin with . (a full stop). Hidden files are normally system files, and will normally include the following:
% ls -a .cshrc .forward .history .login .logout
The purpose of some hidden files.
To identify directories in a listing give the command:
% ls -F file1 bin/ test.f test
Notice how the directory is identified by the slash (/) character.
Files can be deleted using the rm command. For example:
% rm test.f
The command cat is used to display the contents of a file on the screen.
% cat file1
The command cat can also be used to create a file. For example:
% cat > test.f When typing in a new file the input must be terminated by ^D
NOTE ^D means press the <ctrl> and the d keys simultaneously. Be careful not to type ^D when you have the shell prompt, because this might log you out. Normally you would use an editor for creating files. This example is given since it illustrates how to create a small file without needing to learn the use of an editor.
The command cp is used to copy a file. It takes the format:
% cp old_file new_file
% cp file1 file2
The command mv is used to rename a file.
% mv file2 temp
changes the name of file2 to temp.
The command mv is also used to move a file to a new location in the filestore hierarchy. For example:
% mv file2 bin
moves the file file2 into the subdirectory bin.
Commands such as rm and cp can be dangerous if not used with care. The command:
% cp file1 file2
will delete file2 if a file of that name already exists. If you have spelled the name of the new file incorrectly you may accidentally overwrite the contents of a file. Using the wildcard symbol * with the command rm can also be very dangerous. The command:
% rm test*
will delete all files starting with test. However if you inadvertently type an extra space (do not try this!):
% rm test * -do not try this!
the file test will be deleted if it exists. Then all other files in the directory will be deleted! Often no warning will be given.
To prevent accidental deletion of files you can use the -i option with commands such as rm. The format of the command is:
% rm -i file
You will be asked to confirm that files are to be deleted. You may find that this is set as the default on your system.
Wildcard characters can be used to identify directory and file names. The wildcard character * is used to refer to any combination of characters. For example:
% ls * - refers to all files % cat test* - refers to all files starting with 'test', e.g. 'test', 'testing', 'test.c', etc.
The wildcard character ? is used to refer to a single character. For example:
% ls test? - refers to files starting with 'test' followed by a single character e.g. 'test1', 'test2', 'testz', etc.% cat test.? - refers to all files starting with 'test' with a single character after the full stop, e.g. 'test.c, test.f'
water, water everywhere and all the boards did shrink; water, water everywhere, Nor drop to drink