Linux Cheatsheet
My personal compilation of Linux cheatsheet throughout the years. I am putting up here so I can easily access whenever I need to recall.
>>
print output to target file
Examples list files and output to a txt file
| (pipeline)
command combinations using pipe
Examples creating a long list of files and piping the output into the more command
./program name
Run an executable in the current directory
Examples
[Tab]
autocompletion function
Examples
[ctrl] + [c]
terminate the process (kill pid)
Examples
[ctrl] + [z]
suspend the process (suspend pid)
Examples
[ctrl] + [a]
go to beginning of line
Examples
[ctrl] + [e]
go to end of line
Examples
[shift] + [delete]
copy from terminal
Examples
[shift] + [insert]
paste from terminal
Examples
[shift] + [PageUp]
scroll terminal output up
Examples
alias
create a 'shortcut' to a command
Examples create an alias called home which will put you in the /home/test/public_html directory
cat
displays the contents of a file to screen. It can also display multiple files concatenated together, and using the shell, its standard output can be redirected from the screen to the file.
Useful options
-n :line numbering
-s :squeeze sequences of blank lines into one
-v :show non-printing characters
Examples
displays content of example.txt
cd
changes the current directory.
Examples
change to web directory
clear
clear screen
Examples
cp
copies a file
Useful options
-r : copies directories (recursively)
-p : preserves permissions, ownership, and timestamps
-i : prompt before overwrite
-v : verbose, show filenames as they are being copied
-f : copies directories (force)
Examples
copy test.txt to /home/user/ directory
chmod
changes permissions of files. 3 permissions: read(r), write(w) & execute(x). Sets of permissions for the owning user of the file(u), for the group of the file(g) & for other users(o).
Useful options
-R : recursively change or set permissions on an entire directory tree
Examples
chmod usr|grp|othr operator permission (chmod u=rw o=x file)
chmod test.html 777 (rwx rwx rwx)
chown
changes the owner and group of files.
Useful options
-R : recursively change owner/group on an entire directory tree
-h : do not follow symbolic links i.e. changes owner of the link, not the target file
-f : indicate no errors if change failed
Examples
change the ownership to user root, group web.
date
displays date and time.
Examples
df
reports the amount of free disk space available on each partition.
Useful options
-h : reports disk usage in human readable format with block-sizes in Kilo,Mega,Gigabytes.
Examples
find
search the entire filesystem for one or more files that you specify. It's an extremely helpful Linux command to understand, especially when you need to find a file or directory
Examples
find a file or directory named 'test' somewhere below your current directory
finger
display the user's login name, real name, login time, ect ...
Useful options
-l : print all the information described by -s option
-m : match arguments only on user name
-p : supress the printing format of -l
-s : print output in short format
Examples
free
This command displays statistics on memory usage. The values represent KB's.
Examples
grep
uses to search for text strings and regular expressions within one or more files
Examples search for 'testuser' in the /etc/passwd
head
writes the first ten lines of a file to the screen
Examples
id
prints user group privileges
Examples
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
iptables
configure ip table. Entries are executed in order so entries at the bottom should be restrictions, entries at the top should be exceptions
Useful options
-L : limits to INPUT, OUTPUT, FORWARD, ect...
-n : shows numbers, not domains & port names
--line-numbers : the line number of the rule (allows you to delete it)
-A : add at the end of the defined table: INPUT, OUTPUT, FORWARD, etc.
-l : inserts at the beginning of the defined table
-p : Source IP
-sport : Source port(s) (optional)
-j : Action (ACCEPT, REJECT, DROP, etc.)
Examples
add basic entry
kill
terminate for example the emacs process, you would need to look up the process identifier (PID) in the table using command ps ux
Examples
-9 will ensure execution
last
uses to display the last logged in users list. Last logged in users informations are read from the file /var/log/wtmp.
Useful options
-n : specify how many lines to show
-R : suppresses the display of the hostname field
-a : display the hostname in the last column
Examples
display all the last logged in users list
history
shows last commands
Useful options -5 : show last 5 commands
Examples displays up to 1000 commands
ls
for listing the files in a directory.
Useful options
-a : all files (include files with . prefix)
-l : long detail (provide file statistics)
-t : order by creation time
-u : sort by access time (or show when last accessed together with -l)
-S : order by size
-r : reverse order
-s : show filesizes
-h : 'human readble'; show filesizes in kilobytes and megabytes (-h can be used together with -l or -s)
Examples
list long details
locate
find indexed files
Examples find index.html
more
display results one page at a time ([enter] moves on line down, [space] moves one page down)
Examples
rm
deletes a file from the filesystem
Useful options
-f : force, ignore nonexistent files, never prompt
-i : interactive, prompt before any removal
-r, -R : recursive, remove the contents of directories recursively (the force option must often be used to successully run rm recursively)
Examples remove a file by force
mv
move or rename files/directories
Examples move log1.txt to /home/web folder
passwd
changes passwords for user and group accounts. A normal user may only change the password for his/her own account, the super user may change the password for any account.
Examples
set or change user password
ps
lists process status.
Useful options
-a : list the processes of all users on the system rather than just those of the current user
-u : provide detailed information about each process
-x : add to the list processes that have no controlling terminal, such as daemons, which are programs that are launched during booting
-e : generate a list of information about every process currently running
-f : generate a listing that contains fewer items of information for each process than the -l option
-l : generate a long listing
Examples
show all active processes
pwd
print working directory
Examples
su
change user from shell
Examples
change user
tar
archive, extract archive files, create compressed archives
Useful options
c : create archive
v : verbose which tells tar to print all the filenames as they are added to the archive
f : the name of the archive appears next (right after these options)
z : compress this archive with gzip
x : extract
Examples create an archive project of a subdirectory project
uptime
displays a one line summary showing current time, number of days since last boot, number of users logged in, system utilization for the last 1,5 &15
Examples
useradd
adding a new user
Useful options
-d : home directory
-p : password
-g : primary group assigned to the user
-G : other groups the user belogs to
-m : create the user's home directory
Examples
to add a new user with primary group users, a second group sale, password test, home directory newuser, create home directory, a login name new user
userdel
deleting a user
Useful options
-r : remove home directory
Examples to remove the user 'newuser' and home directory
usermod
modifying existing user
Useful options
-d : home directory
-p : password
-g : primary group assigned to the user
-G : other groups the user belogs to
Examples
to add the group 'others' to the user newuser
w
show uptime and some users informations
Examples
who/whoiam
who will display all users logged in, tty device, when they logged in, iddle time, where they logged in from; whoami will display the current user login
Useful options
-i : display idle time
-H : print column headings
Examples
Latest News
8.08.2010
Migrated to Linux server
3.20.2010
Added Lightbox for YouTube Videos
2.22.2010
Added more Linux commands
2.6.2010
Added/updated content.
2.6.2010
Appied a simple, modern new template to the website.