Saturday, September 25, 2004

Linux Cheat Sheet

alias
Create an alias

Usagealias [name[=’value’]]
Examplealias la=’ls -la --color=auto’
ExplanationCreates an alias for the ls command which displays a detailed list with various file types in different colours.
Windows equivalentN/A

cat
Display the contents of a file

Usagecat [options] [file1] [file2] ...
Examplecat index.html
ExplanationDisplays the contents of the index.html file.
Windows equivalenttype

cd
Change directory

Usagecd [-LP] [directory]
Examplecd /usr/local/bin
ExplanationChanges the /usr/local/bin directory.
Windows equivalentcd

chgrp
Change group ownership

Usagechgrp [options] group file1 file2 ...
Examplechgrp apache index.html
ExplanationChanges the group ownership of the index.html file to the apache group.
Windows equivalentN/A

chmod
Change access permissions

Usagechmod [options] mode file1 file2 ...
Examplechmod 755 script.cgi
Explanation"Changes the permissions of script.cgi so that everyone can execute and read it
Windows equivalent but only the owner can write to it."

chown
Change file owner and group

Usagechown [options] new-owner file1 file2 ...
Examplechown root index.html
ExplanationChanges the ownership of the index.html file to root.
Windows equivalentN/A

cmp
Character-by-character compare between two files

Usagecmp [options] from-file to-file
Examplecmp index.html default.htm
Explanation"Compares each character in index.html and default.htm
Windows equivalent and displays the differences."

cp
Copy one or more files to another location

Usagecp [options] source destination
Examplecp index.html index.html.bak
ExplanationMakes a second copy of the index.html file in the same directory. The new copy has the BAK extension.
Windows equivalent"copy

df
Display free disk space

Usagedf [options] [file]
Exampledf
ExplanationDisplays the used and free disk space on all mounted filesystems.
Windows equivalentdir

du
Estimate file space usage

Usagedu [options] [file]
Exampledu
ExplanationDisplays the disk usage of the current directory.
Windows equivalentdir

echo
Display message on screen

Usageecho [options] [string]
Exampleecho Hello World!
ExplanationDisplays the Hello World! message on the screen.
Windows equivalentecho

env
"Display

Usage set or remove environment variables"
Exampleenv [options] [name[=value]] [comand [args]]
Explanationenv HOME=/home/username
Windows equivalentChanges the HOME environment variable to /home/username.

exit
Exit the shell

Usageexit
Exampleexit
ExplanationExits from the current shell.
Windows equivalentN/A

free
Display memory usage

Usagefree [options]
Examplefree -s 5
Explanation"Displays current memory usage
Windows equivalent updating it every five seconds."

fsck
Filesystem consistency check and repair

Usagefsck [options] [filesystem]
Examplefsck /dev/hda1
ExplanationPerforms a filesystem check on the first partition of the primary master IDE drive.
Windows equivalentchkdsk

grep
Search file(s) for lines that match a given pattern

Usagegrep [options] string [file1] [file2] ...
Example"grep ""search string"" /home/*"
Explanation"Searches all files in /home for the occurence of the ""search string""."
Windows equivalentN/A

gzip
Compress or decompress named file(s)

Usagegzip [options] file
Examplegzip index.html
ExplanationCompressed index.html into a file named index.html.gz.
Windows equivalentN/A

kill
Stop a process from running

Usagekill [options] pid
Examplekill 1234
ExplanationTerminates the process with id 1234. Use ps to determine a processes id.
Windows equivalentkill

less
Display content one screen at a time

Usageless [options]
Examplecat index.html | less
Explanation"Displays the index.html file on the screen
Windows equivalent one screen at a time."

ln
Make links between files

Usageln [options] target [linkname]
Exampleln -s /var/www/html /home/user/website
ExplanationCreates a shortcut named website from the user’s home directory to the /var/www/html directory.
Windows equivalentshortcut

locate
Find files

Usagelocate [options] string
Examplelocate perl
ExplanationSearches filesystem databases for files containing the term perl.
Windows equivalentdir /s

ls
List information about file(s)

Usagels [options] [file/directory]
Examplels -la /var/www/html
ExplanationPrints a detailed list of all files and directories located in the /var/www/html directory.
Windows equivalentN/A

man
Help manual

Usageman [options] [command]
Exampleman man
ExplanationDisplays the manual for the man command.
Windows equivalentN/A

mkdir
Create new folder(s)

Usagemkdir [options] directory
Examplemkdir html
ExplanationCreates a directory named html under the current directory.
Windows equivalentmd

mount
Mount a file system

Usagemount [options] [device/directory]
Examplemount cdrom
ExplanationMounts the CD-ROM drive.
Windows equivalentN/A

mv
Move or rename files or directories

Usagemv [options] source destination
Examplemv index.html /var/www/html
ExplanationMoves the index.html file from the current directory to /var/www/html.
Windows equivalentmove

nice
Set the priority of a command or job

Usagenice [options] [comand [args]]
Examplenice -n 19 httpd
ExplanationRuns the httpd process with the lowest possible priority (-20 is the highest priority).
Windows equivalentN/A

passwd
Modify a user password

Usagepasswd [options]
Examplepasswd
ExplanationPrompts you to change the password for the current user. It will prompt for the old password first.
Windows equivalentN/A

ping
Sends and echo packet to a host

Usageping [options] host
Exampleping www.apcmag.com
ExplanationContinually sends echo packets to the www.apcmag.com host.
Windows equivalentping

ps
Process status

Usageps [options]
Exampleps -ef
ExplanationDisplays full list of all running processes.
Windows equivalentmem

pwd
Print working directory

Usagepwd [options]
Examplepwd
ExplanationPrints the directory the terminal is presently in.
Windows equivalentcd

rm
Remove files

Usagerm [options] file1 file 2 ...
Examplerm -rf /var/www/html
ExplanationForces the removal of the /var/www/html directory and all files and subdirectories indside it.
Windows equivalentdel

rmdir
Remove folder(s)

Usagermdir [options] directory1 directory2 ...
Examplermdir /var/www/html
ExplanationRemoves the /var/www/html directory (assuming it’s empty).
Windows equivalentrd

shutdown
Shutdown or restart Linux

Usageshutdown [options] when [message]
Exampleshutdown -r 20:00
ExplanationReboots the system at 8pm.
Windows equivalentshutdown

sleep
Delay for a specified time

Usagesleep [number]
Examplesleep 30
ExplanationPauses for 30 seconds — useful in some scripts.
Windows equivalentsleep

su
Substitute user identity

Usagesu [options] [username [args]]
Examplesu
ExplanationSwitches to the root user.
Windows equivalent"su

tail
Output the last part of files

Usagetail [options] [file1] [file2] ...
Exampletail /var/log/error.log
ExplanationDisplays the last 10 lines of the error log.
Windows equivalentN/A

tar
Tape archiver

Usagetar [options] file1 [file2] ...
Exampletar - czvf archive.tar.gz /var/www/html
ExplanationCompresses the contents of the /var/www/html directory into a gzipped tarball named archive.tar.gz.
Windows equivalentN/A

touch
Change file timestamps

Usagetouch [options] file1 ...
Exampletouch /var/www/html/index.html
Explanation"Updates the timestamp on /var/www/html/index.html
Windows equivalent or creates the file if it doesn’t exist."

top
List processes running on the system

Usagetop [options]
Exampletop
ExplanationProvides an automatically-updating list of the most CPU intensive processes running on the system.
Windows equivalentN/A

traceroute
Trace route to host

Usagetraceroute [options] host [packetsize]
Exampletraceroute www.apcmag.com
ExplanationPrints a list of all routers (and IP addresses) that IP datagrams pass through en route to the www.apcmag.com server.
Windows equivalenttracert

umount
Unmount a device

Usageumount [options] [device/directory]
Exampleumount cdrom
ExplanationUnmounts the CD-ROM drive.
Windows equivalentN/A

unalias
Remove an alias

Usageunalias [options] [name]
Exampleunalias la
ExplanationRemoves the alias named la.
Windows equivalentN/A

uname
Print system information

Usageuname [options]
Exampleuname -a
ExplanationPrints all system information relating to the machine and OS.
Windows equivalentN/A

which
Locate a program file in the user’s path

Usagewhich [options] file ...
Examplewhich perl
Explanation"Same as locate
Windows equivalent but restricts the search to the user’s path."