This page describes the eight most frequently-used Linux/UNIX commands and examples of how to use them. For additional information about any of these commands, log onto a COMS linux machine and type man command.
The cd command changes the current (working) directory.
|cd||Changes to your home directory.|
|cd foo||Changes to the foo directory.|
|cd ..||Changes to the parent directory (i.e., move up one directory).|
The cp command copies files and directories.
|cp src-file dest-file||Creates a copy of the file src-file named dest-file.|
|cp src-file dest-dir||Copies the file src-file into the dest-dir directory.|
|cp -R src-dir dest-dir||Copies all files and subdirectories within the src-dir directory into the dest-dir directory. (The -R stands for “recursive”.)|
|cp -i src dest||Copies the file/directory src to the file/directory dest, but prompts if any files or directories would be overwritten. (The -i stands for “interactive”.)|
The du command displays the amount of disk usage for specific files and directories.
UNIX> du -sh ~ 450M .
In the above example, the files in the user's home area (denoted by ~) are occupying 450 megabytes of storage. The two options s and h stand for “summarize” and “human-readable”, respectively.
By sorting the output, you can see which directories and files are consuming the most space:
UNIX> du -sk ~ | sort -n 0 fork.c 0 nohup.out 1 Calendar 1 afile 1 cactus ... 16773 www-home 20922 classes 96336 gcc 196762 mail
The k option stands for “show number of kilobytes”.
The ls command lists directory contents.
|ls||Lists the contents of the current working directory.|
|ls dir-name||Lists the contents of the dir-name directory.|
|ls -a||Lists the contents of the current working directory, including files that begin with a dot. (Dot-files are not listed unless the -a option is used.)|
|ls -l||Lists the contents of the current working directory in long format.|
The mkdir command makes (i.e., creates) a new directory.
|mkdir foo||Creates a new directory named foo.|
The mv command moves or renames files and directories.
|mv old-file new-file||Renames the file old-file to new-file.|
|mv src-file dest-dir||Moves the file src-file into the dest-dir directory.|
|mv old-dir new-dir||Renames the old-dir directory to new-dir.|
|mv -i src dest||Moves or renames src to dest, but prompts if any files or directories would be overwritten. (The -i stands for “interactive”.)|
The rm command removes (i.e., deletes) files. (To remove directories, see the rmdir command below.)
|rm foo||Deletes the file foo.|
|rm -r dir||Deletes the foo directory, including all of its files and subdirectories. (The -r stands for “recursive”.)|
|rm -i file||Deletes the file foo, but prompts before actually deleting it. (The -i stands for “interactive”.)|
The rmdir command removes empty directories.
|rmdir foo||Deletes the foo directory.|