Linux Commands to Know

Most of you will be using X-Windows and various GUI tools or possibly even Webmin. However, as mentioned previously, my test computer is low on hardrive space so most everything was done via the command line. What follows are some very basic commands for manipulating files. There are much better resources out on the web than this. See the man pages for each command for more information as well.

Create, Copy, & Delete

cp [from] [to]
Copy files/directories from one location to another.

mv [from] [to]
Move files/directories from one location to another. Can also be used for renaming.

rm [options] [file]
Remove files/directories. Wildcards supported for [file].

mkdir [name]
Create a directory.

rmdir [name]
Remove a directory.

touch [name]
Creates the [name] if it does not exist or updates the time stamp.

Display

ls [options]
List files/directories. Commonly used options:
-l = full information
-a = show files who's name begins with . (aka hidden files)

find dir_to_start_in -name file_to_find -print
Seach for a file. Wildcards accepted.

pwd
Print the current directory path you are in.

df [options]
Show space available on disk. Without options shows for all mounted file systems

du
Show space used by current directory and sub-directories.

Modify Attributes

chown [name] [file]
Change the owner of the files/directories. Wildcards supported for [file].

chgrp [name] [file]
Change the group of the files/directories. Wildcards supported for [file].

chmod [permissions] [dir_or_file]
Change the access permissions of the files/directories. Wildcards supported for [dir_or_file].
A few common values for [permissions]:
777 = owner [rwx] group [rwx] world [rwx]
775 = owner [rwx] group [rwx] world [r-x]
"Sticky-bits":
0### = clear all sticky-bits
1### = only owner of file can do things to it
2### = group that "owns" directory will be assigned to all files created inside
4### =
This may give you more information.

Environment Variables

printenv
Show all environment variables

export [variable]="[value]"
Set an environment variable

unset [variable]
Remove a variable

Misc

ln [options] [target] [linkname]
Makes links to selected [target]s. Default is hard links. Typically you use -s, an option, for symbolic links.

rpm [do what] [options] [file]
Use RH's package manager to install, upgrade, or remove packages. Wildcards supported for [file].
Install = rpm -ivh [file]
Upgrade or install if not exist = rpm -Uvh [file]
Upgrade but don't install if not exist = rpm -Fvh [file]
Query = rpm -q [package name] (ex: rpm -q sendmail)
Query with grep = rpm -qa | grep [name]
Information = rpm -qi [package name]
Remove = rpm -e [package]
For options you can use, in most cases:
--nodep: ignore dependencies
--replacefiles: replace conflicting files
More info that you care to know about RPM http://www.rpm.org/max-rpm/index.html

e2fsck [options] [device]
Check and/or repair the file system. Use e2fsck --help for a full list of options.

mke2fs [options] [device]
Create a file system on a partion (aka format).
Example - check for bad blocks, ext3, 1% reserved, label:
mke2fs -c -j -m1 -L [label] /dev/hdxx

diff [options] original changed >patch_file
Make a patch of changed (a) file(s). Example:
diff -u3 -r file.c.orig file.c >file.patch

free
Display memory usage.

tar
A directory and sub directories & compress it:
With the directory name while you are in the parent:
tar clf - ./dir_name | compress > name.tar.Z
To list the contents of the resulting file:
zcat name.tar.Z | tar tvf - | more

top
Display process information real-time. Use h for help and q to quit.