A basic break down of unix-based commands
1. man - Accessing On-Line Manual Pages In the terminal, the "man" command looks up the manual page for a command. The format of man is man for example:
man ls
man pwd
man cat
2. pwd - Print the Working Directory The "pwd" command prints the full pathname of your current working directory. The syntax for pwd is: pwd for example:
$pwd
/home/gunz
3. cd - Changing Directory The "cd" command changes the current working directory to the directory specified. The format of cd is: cd . If you do not specify directory, cd changes to your home directory for example:
$ cd /
/$ pwd / (notice that the directory has changed to the root folder)
/$ cd ~
$ pwd /home/gunz (realize we have returned to the original home directory)
4. ls - Listing the Contents of Directories The "ls" command lists the contents of one or more specified directories or lists information about one or more specified files. By default, it lists only files which are not hidden/ without a dot (".") at the beginning. Therfore, one has to add options to it in order to view such files for example:
ls -a Lists all files, including those that begin with a “.”.
-F Marks directories with a / and executable files with a *.
-l Produces a longer, more informative listing
5. mkdir - Making Directories The "mkdir" command makes directories with specified names. The syntax of the mkdir command is:
mkdir <directory1> <directory2> <directory(n)>
6. rmdir - Removing Directories The rmdir command removes empty directories with specified names. The format of the rmdir command is rmdir directory(1) directory(2)... directory(n). The rmdir command will not remove a directory with files in it - for this use the rm -r command, described later in this section, but be careful!. For example:
$ ls -F Mail/ prog/ thesis/ zeta/ zeta.f
$ rmdir zeta
$ ls -F Mail/ prog/ thesis/ zeta.f
7. cp - Copying a File The "cp" command makes a copy of a file or copies multiple files into a directory. The format of the cp command is:
cp <source-file> <destination-file> or
cp <source-file(1) source-file(2)... source-file(n)> <destination-directory>.
The first form makes a copy of the file source-file called destination-file and the second copies series of files source-file(1..n) into directory destination-directory.
8. cat - Printing Files Onto the Screen The "cat" command prints out the contents of a series of files one after the other. The syntax of the at command is:
cat filename(1) filename(2)... filename(n).For example, to read the “message of the day”:
$ cat /etc/motd.
9. more - Printing Files One Screen at a Time The "more" command prints out the contents of named files, one screen full at a time. The format of the more command is:
more filename(1) filename(2)... filename(n).
To quit more, press the q key, to move one line at a time press the RETURN key or the SPACE bar to move one screen full at a time.
10. mv - Moving and Renaming Files The "mv" command changes the name or location of a file or directory. The formats of the mv command are:
mv <oldfile> <newfile> or
mv file(1) file(2)... file(n)directory or
mv olddir newdir
11. rm - Removing Files and Directories The rm command removes files and directories. Caution: There is no way to reverse this process The format of the rm command is :
rm [-i] [-r] fd(1) fd(2)... fd(n)
where fd(1..n) are files or directories.
-i Inquire before removing a file (“y” to delete, anything else to not delete).
-r Recursively remove a directory and all its contents and subdirectories (To be used with extreme care).
12. chmod - Changing Access Permissions The chmod command changes the “permissions” on a file or directory. It gives or removes access for another user or group of users to read, change or run one of the files owned by you. Users on the system fall into three categories: user You, group Anyone in the same class as yourself, such as pg 1999, staff or postdoc. other Anyone who uses the Institute Computers (sometimes called world). The format of the chmod command is: chmod ugo+-=rwx fd(1) fd(2)... fd(n) where fd(1..n) may be a file or directory where:
ugo Specify u (user), g (group) or o (other).
+-= Specify + (add), - (subtract) or = (set).
rwx Specify r (read), w (write) or x (execute).
13. grep - Searching for Strings in Files The "grep" command scans a file for the occurrence of a word or string and prints out any line in which it is found. The format of grep is:
grep [-i] ’string’ filename(1) filename(2)...
14. wc - Counting Words The "wc" command counts the lines, words and characters in a file. The syntax of wc is:
wc [-l] [-w] [-c] filename...
-l Prints the number of lines in the files.
-w Prints the number of words in the files.
-c Prints the number of characters in the files.
15. Wildcards Most shells have a mechanism which indicates groups of letters. For example:
$ ls abc* - to list all the files in a directory which begin with the letters abc
$ ls ???h - to list all the four–letter files which end in h
$ cp [0-9]* <dir>: copies all files ranging from 0-9 irrespective of its format or extensions
$ cp [[:upper:]]* <dir>: copies all files with upper case letters irrespective of its format or extensions
$ cp [[:lower:]]* <dir>: copies all files with lower case letters irrespective of its format or extensions
$ cp *[[:digit:]] <dir>: copies all files that end with digits
$ cp [[:alnum:]] <dir>: copies all files with letters & numerals