Some basic Linux commandsOctober 12, 2013

On most modern Linux distributions you can use the graphical user interface to do just about everything. It is, however, sometimes easier to use the command line in a terminal and type the commands out. In these cases it’s good to have a handy reference that includes only the most common Linux commands and their options.

How dare you! When you don’t have permission to do that

sudo super user do when you don’t have permission to do something, just put this in front of your command; just like magic, all will suddenly be right in the world again
su superman up when you want to change into your costume inside a phone booth rather than using your powers in a more secretive manner
exit exit when you don’t want to be super anymore… It happens

Navigation… The non-visual way

pwd print working directory shows you where you are /home/duster/cat videos
cd change directory with .. meaning up one, and ~ meaning your home directory cd ..
you can navigate more succinctly by typing the whole directory cd ~/pictures

Lighting a match when you find yourself stumbling around in the dark

ls list stuff see a file listing for the directory you’re in mouse.jpg fish.svg yarn.png
ls /var/www type a directory after ls to see a listing for that directory index.html style.css
ls -l /var/www list stuff longer see permissions, owner, filesize, datge and time last modified drwxr-xr-x 1 root 36 2013-08-13 10:36 index.html
drwxr-xr-x 1 root 1019 2013-08-10 15:07 style.css
ls -a /var/www list stuff all also see hidden files .htaccess index.html style.css


r = read = 4
w = write = 2
x = execute = 1

Owner Group Everyone Stuff inside Owner Group Size Date modified Time Name Example of stuff inside this folder
Folder 7 7 7
d rwx rwx rwx 5 me me 4096 2013-08-01 17:06 folder .      ..   folder file.jpg file2.txt
File 7 5 5 Standalone
rwx r-x r-x 1 me me 328 2013-06-24 21:04 file.txt

Changing it up

chown change owner sudo chown duster ~/public_html/index.html
chgrp change group sudo chgrp cats ~/cat videos
chmod change mode sudo chmod -R 755 /public_html


touch create an empty file seems to only be practical for text files touch newfile.txt
mkdir create a directory mkdir newdir

Copy Paste & Rename

cp copy+paste cp olddir/file.txt newdir/filecopy.txt
mv move/rename mv olddir/goodbye.txt newdir/hello.txt


rm remove file rm me.txt
rm -r remove directory rm -r us


sudo apt-get install package_name i.e: apache2, mysql, php5, libapache2-mod-php5
You can also use ‘Software Manager’ via the GUI in Ubuntu-like systems
tar xvzf something.tar.gz Sometimes you will have to download a something.tar.bz2 or a tar.gz and extract it
tar xjvf something.tar.bz2 x = extract, v = verbose, f = file, z = gzip and j = bzip2
tar cvzf something.tar.gz If you ever want to archive something yourself
tar cvjf something.tar.bz2 c = create

Finding things

find -name var/www/index* search for files by name
find -user var/www/ Duster search for files by owner
grep -i head var/www/index.htm search for the word head in index.htm, ignoring the case of letters
grep -r head var/www/ search for the word head in all files in www/
grep -c head var/www/index.htm count the number of occurrences of the word head in index.htm
egrep ‘(head|footer)’ var/www/index.htm search with regular expressions

Other devices & computers

mnt mnt/win mount a network share
unmount mnt/win umount

Category: Cheat Sheets

Leave a Reply

Your email address will not be published. Required fields are marked *