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 into a COM S Linux machine and type: man command.
cd
The cd command changes the current (working) directory.
Command | Effect |
---|---|
cd | Changes to you home directory. |
cd foo | Changes to the foo directory. |
cd .. | Changes to the parent directory (i.e. move up one directory). |
cp
The cp command copies files and directories.
Command | Effect |
---|---|
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 "recurisive"). |
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"). |
du
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
196792 mail
The k option stands for "show numbers of kilobytes".
ls
The ls command lists directory contents.
Command | Effect |
---|---|
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. |
mkdir
The mkdir command makes (i.e. creates) a new directory.
Command | Effect |
---|---|
mkdir foo | Creates a new directory named foo. |
mv
The mv command moves or renames files and directories.
Command | Effect |
---|---|
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"). |
rm
The rm command removes (i.e. deletes) files. (To remove directories, see the rmdir command below.)
Command | Effect |
---|---|
rm foo | Deletes the file foo. |
rm -r dir | Deletes the foo directory, includeing 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"). |
rmdir
The rmdir command removes empty directories.
Command | Effect |
---|---|
rmdir foo | Deletes the foo directory, only if it is empty. |