You are on page 1of 2

WORKSHOP

Linux commands cheat sheet


With this list of basic Linux commands and sample usages, you’ll never have to
A printable PDF version of
worry about forgotten commands again. The items contained within brackets
the cheat sheet is included
on this month’s cover CD set. are optional, and type man <command> at a shell for more information.

Equivalent
Windows
Command Description Usage Example Example description command
Creates an alias for the ls command
alias alias la=’ls -la -- which displays a detailed list
alias Create an alias N/A
[name[=’value’]] color=auto’ with different file types in
different colours.
Display the con- cat [options] Displays the contents of the
cat cat index.html type
tents of a file [file1] [file2] ... index.html file.
Changes the /usr/local/bin
cd Change directory cd [-LP] [directory] cd /usr/local/bin cd
directory.
chgrp [options] Changes the group ownership of
Change group chgrp apache
chgrp group file1 file2 the index.html file to the apache N/A
ownership index.html
... group.
Changes the permissions of
Change access chmod [options] mode script.cgi so that everyone can
chmod chmod 755 script.cgi attrib
permissions file1 file2 ... execute and read it, but only the
owner can write to it.
chown [options] new-
Change file chown root Changes the ownership of the
chown owner file1 file2 N/A
owner and group index.html index.html file to root.
...
Character-by-
Compares each character in
character cmp [options] from- cmp index.html
cmp index.html and default.htm, and comp
compare between file to-file default.htm
displays the differences.
two files
Makes a second copy of the
Copy one or more
cp [options] source cp index.html index.html file in the same copy,
cp files to another
destination index.html.bak directory. The new copy has the xcopy
location
BAK extension.
Display free Displays the used and free disk
df df [options] [file] df dir
disk space space on all mounted filesystems.
Estimate file Displays the disk usage of the
du du [options] [file] du dir
space usage current directory.
Display message echo [options] Displays the Hello World! message
echo echo Hello World! echo
on screen [string] on the screen.
Display, set or env [options]
env HOME=/home/ Changes the HOME environment
env remove environ- [name[=value]] [co- set
username variable to /home/username.
ment variables mand [args]]
exit Exit the shell exit exit Exits from the current shell. N/A
Displays current memory usage,
Display memory
free free [options] free -s 5 updating the display every five N/A
usage
seconds.
Filesystem Performs a filesystem check on the
fsck [options]
fsck consistency fsck /dev/hda1 first partition of the primary chkdsk
[filesystem]
check and repair master IDE drive.
Search file(s)
grep [options]
for lines that grep "search string" Searches all files in /home for the
grep string [file1] N/A
match a given /home/* occurence of the "search string".
[file2] ...
pattern
Compress or
Compressed index.html into a file
gzip decompress named gzip [options] file gzip index.html N/A
named index.html.gz.
file(s)
Terminates the process with
Stop a process
kill kill [options] pid kill 1234 id 1234. Use ps to determine a kill
from running
processes id.
Display content
cat index.html Displays the index.html file on the
less one screen at a less [options] more
| less screen, one screen at a time.
time

1 apcmag.com  august 04  workshop  linux commands


resource linux commands

Equivalent
Windows
Command Description Usage Example Example description command
Creates a shortcut named website
Make links ln [options] target ln -s /var/www/html
ln from the user’s home directory to shortcut
between files [linkname] /home/user/website
the /var/www/html directory.
locate [options] Searches filesystem databases for
locate Find files locate perl dir /s
string files containing the term perl.
Prints a detailed list of all files
List information ls [options] [file/
ls ls -la /var/www/html and directories located in the N/A
about file(s) directory]
/var/www/html directory.
man [options] Displays the manual for the man
man Help manual man man N/A
[command] command.
Create new mkdir [options] Creates a directory named html
mkdir mkdir html md
folder(s) directory under the current directory.
Mount a file mount [options]
mount mount cdrom Mounts the CD-ROM drive. N/A
system [device/directory]
Move or rename
mv [options] source mv index.html /var/ Moves the index.html file from the
mv files or move
destination www/html current directory to /var/www/html.
directories
Set the priority Runs the httpd process with the
nice [options]
nice of a command nice -n 19 httpd lowest possible priority (-20 is N/A
[comand [args]]
or job the highest priority).
Prompts you to change the password
Modify a user
passwd passwd [options] passwd for the current user. It will N/A
password
prompt for the old password first.
Sends and echo Continually sends echo packets to
ping ping [options] host ping www.apcmag.com ping
packet to a host the www.apcmag.com host.
Displays full list of all running
ps Process status ps [options] ps -ef mem
processes.
Print working Prints the directory the terminal
pwd pwd [options] pwd cd
directory is presently in.
Forces the removal of the /var/www/
rm [options] file1
rm Remove files rm -rf /var/www/html html directory and all files and del
file 2 ...
subdirectories indside it.
rmdir [options] di-
Removes the /var/www/html directory
rmdir Remove folder(s) rectory1 directory2 rmdir /var/www/html rd
(assuming it’s empty).
...
Shutdown or shutdown [options]
shutdown shutdown -r 20:00 Reboots the system at 8pm. shutdown
restart Linux when [message]
Delay for a Pauses for 30 seconds — useful in
sleep sleep [number] sleep 30 sleep
specified time some scripts.
Substitute user su [options] [user- su,
su su Switches to the root user.
identity name [args]] runas
Output the last tail [options] tail /var/log/ Displays the last 10 lines of the
tail N/A
part of files [file1] [file2] ... error.log error log.
tar - czvf Compresses the contents of the /var/
tar [options] file1
tar Tape archiver archive.tar.gz /var/ www/html directory into a gzipped N/A
[file2] ...
www/html tarball named archive.tar.gz.
Updates the timestamp on /var/www/
Change file touch [options] touch /var/www/html/
touch html/index.html, or creates the touch
timestamps file1 ... index.html
file if it doesn’t exist.
List processes Provides an automatically-updating
top running on the top [options] top list of the most CPU intensive N/A
system processes running on the system.
Prints a list of all routers
tracer- Trace route to traceroute [options] traceroute (and IP addresses) that IP
tracert
oute host host [packetsize] www.apcmag.com datagrams pass through en route to
the www.apcmag.com server.
umount [options]
umount Unmount a device umount cdrom Unmounts the CD-ROM drive. N/A
[device/directory]
unalias [options]
unalias Remove an alias unalias la Removes the alias named la. N/A
[name]
Print system Prints all system information
uname uname [options] uname -a N/A
information relating to the machine and OS.
Locate a program
which [options] file Same as locate, but restricts the
which file in the which perl N/A
... search to the user’s path.
user’s path

apcmag.com  august 04  workshop  linux commands 2

You might also like