You are on page 1of 6

1.

1 Essential Linux Commands


To learn more about a particular command, view the manual page associated
with it - simply type man followed by the name of the command you want to
learn about. To exit from a manual page, press the q key (where “q” stands
for “quit”). Most commands have options associated with them - don’t try
to guess the options ... read the manual page!

Working with Files and Directories


cat type a disk-file to the screen
cd change directory (or return to %HOME directory)
chmod change the mode of a disk-file (e.g., to make it executable)
chown change the owner of a disk-file or directory
cp copy a disk-file/directory to a new location
find search for a disk-file on the system (see locate)
ftp transfer disk-files from one system to another
grep search for a text string in a group of disk-files
gzip/gunzip compress/uncompress a disk-file or group of disk-files
head display the first few lines of a disk-file on the screen
ispell spell-check a disk-file using the system dictionary
less type a disk-file to the screen one screen-full at a time
locate locate a specific disk-file on the system (see find)
ln create a symbolic link (alias/shortcut) to a disk-file
ls list the contents of a directory to the screen
mkdir create a new directory
mv move or rename a currently existing disk-file/directory
pwd display the name of current working directory
rm delete one or more disk-files
rmdir delete a directory
sort sort a disk-file (using various techniques)
tac type a disk-file to the screen in reverse order (see cat)
tail display the last few lines of a disk-file on the screen
wc display the character, word, or line count of a disk-file
zcat type the contents of a compressed disk-file to the screen
zmore like zcat, only display the disk-file a screen-full at a time

Printing Commands
lpq check the status of your entries on the print queue
lpr add an entry to the print queue
lprm remove an entry from the print queue

1
Networking Commands
netstat show the network status for this system
ping is there anybody out there? Check a host for existence
traceroute show me how to get from here to there

Working with Processes


kill stop a process (program) from running
ps report on the active processes
top who is doing what, and how much CPU are they using?
w display a summary of system usage on the screen

Working with Disks


df how much free disk space is there?
du how is the disk space being used?

Miscellaneous Commands
cal display a calendar on the screen
clear clear the screen
date display the current date and time on the screen
echo display a message on the screen
man read a manual page (type man man to learn more)
passwd change your password
perl run Perl (a great programming language . . . )
su create a shell under the ID of some other user
telnet log into a remote computer
uname display the machine and operating system name
users list the current login sessions on the system
vi run vi (a great text editor . . . )
whereis locate a binary (executable), source, or manual page disk-file
which list the path to a particular binary disk-file (executable)
who who is currently logged in
whoami ’cause I’ve forgotten . . .
Ctrl-D signal end-of-file to running process (key combination)

2
Essential Systems Administrator Commands
Note that you will need to be logged in as root to use these commands
effectively. Remember, as root you have complete power over Linux (so be
careful).

cron execute commands at scheduled times


dmesg display the system control messages
e2fsck check the health of a disk
fdisk fiddle with disk partitions (be very, very careful)
fdisk you are being careful with fdisk, aren’t you?
ifconfig configure your network interface card
kill see kill above . . . much more fun as root . . .
lilo install the Linux Loader (read the man page)
lpc control a print queue
mke2fs create a disk-file system (i.e., format a disk)
mount add a disk into the active disk-file system (read the man page)
reboot reboot now!
rpm the RedHat Package Manager
shutdown perform a nice safe, graceful, shutdown of the system
tar work with tarred disk-files (read the man page)
umount remove a disk from the active disk-file system

3
1.2 vi Quick Reference
This quick reference will get you started. To learn more, from the Linux
command-line, type: man vi.

Invoking the vi Text Editor


vi - start the vi editor with an empty edit buffer

vi file - edit a file called file

vi +n file - edit a file called file and go to line n

vi +/pattern file - edit a file called file and go to the first line that
matches the string pattern

vi’s modes
vi can be in one of three modes:

edit mode - keys typed are added to the edit buffer

non-edit mode - keys typed adjust or move around the edit buffer

ex mode - commands are executed within vi, and the commands affect
the edit buffer

To enter edit mode, press the Esc key then type i


To enter non-edit mode, simply press Esc
To enter ex mode, press Esc then type :

Non-edit mode keystrokes


ˆ go to start of current line (first non-blank character)
0 go to start of current line
$ go to end of current line
w go to next word
b go to previous word (back)

o insert blank line below current one, enter edit mode


O insert blank line above current one, enter edit mode

i enter edit mode by inserting text at current location


a enter edit mode by appending text after current location
A enter edit mode by appending to the end of the current line

4
J join the current line with that line immediately below it

Ctrl-G show current line number


nG go to line n within the edit buffer
G go to bottom of edit buffer

Deleting text (in non-edit mode)


dd delete current line
dw delete next word
dˆ delete to start of line
d$ delete to end of line
x delete a single character

Changing text (in non-edit mode)


cc change the current line, and enter edit mode
cw change the current word, and enter edit mode
r replace a single character
R replace characters until Esc is pressed

Cutting and Pasting (in non-edit mode)


yy copy current line (the line is now yanked )
nyy copy n current lines (multi-yank)
ye copy to the end of next word (little-yank)

p paste yanked text after or below cursor


P paste yanked text before or above cursor

Some ex mode commands


:w write the edit buffer (i.e., save the file)
:w file write a copy of the edit buffer as file
:wq write the edit buffer then quit
:q! quit without writing any changes (called ”force quit”)
:w! file overwrite file with current edit buffer

5
:sh temporarily exit vi to access a Linux shell

:help access the vi on-line help


:help cmd access the on-line help for subject cmd

:set used to set and unset vi settings


:set all display the entire list of vi’s current settings

Searching
/pattern search forward in edit buffer for a match to pattern
/ repeat last forward search
?pattern search backward in edit buffer for a match to pattern
? repeat last backward search
n repeat previous search (regardless of direction)