Table of Contents

Basic UNIX commands

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.

cd

The cd command changes the current (working) directory.

Command Effect
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).

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 “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”.)

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
196762  mail

The k option stands for “show number 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, 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”.)

rmdir

The rmdir command removes empty directories.

Command Effect
rmdir foo Deletes the foo directory.
faq/linuxref/basic.txt · Last modified: 2011/03/29 18:10 (external edit)
GNU Free Documentation License 1.3
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0