Linux intro for n00bs

general things about the unix shell

-> - TAB

The tabulator key acts as an auto completition function.

$ cd /ho press tab

$ cd /home/

If there are multiple options to complete the word, it will list you the possibilites.

$ sudo apt-get up press tab a few times

$ sudo apt-get up
update upgrade
$ sudo apt-get up

^C - CTRL + C

The ^C shortcut is the universal cancel or stop command to stop a running process. There are other programms who use the ESC or q (quit) keys to stop the process.

| - pipe

This is not a command, but an instruction that tells the shell to forward standard output to the standard input of another programm. This way, we can chain commands to each other.


$ echo -e "Hello, \nWorld!" | grep -i "hello"
$ Hello,

> - single arrow

Appending an arrow to a command means, that the output of this command shall be forwarded into a file. The single arrow overwrites the contents of the destination file.


$ echo "Hello, World!" > hello.txt creates hello.txt and writes Hello, World! into it

$ ./ > /dev/null ignores the output of by forwarding the output into /dev/null

>> - double arrow

Appending a double arrow is like using a single arrow. But this time, the forwarded text does not overwrite the contents of the destination file. The double arrow appends the forwarded text to the destination file.


$ python ./ >> foo.log appends all output generated by to foo.log

folders and files

synopsis meaning
/ root
. current working directory
.. the parent directory
~ home directory of the current user
* all files
*.foo all .foo files


$ ls /home list the contents of the home directory (starting at root /)

$ cd .. change to the parrent directory

$ rm -rf *.txt delete all .txt files

$ ./ execute the file inside the current folder

$ cd ~/Downloads change to the Downloads foler in your home directory

Text editors

There is litterally a war on which text editor is better. namo is a simple lightweith editor that works for most thihngs. vim or vi is more complex but offers mor functionality. emacs is another complex one.


$ nano [file]

key command
^X quit
^O save
^V next page
^Y previous page
^W search

vim or vi

$ vim [file]

There is a normal mode where you can navigate with the arrow keys and an insert mode. Press i to enter the insert mode and write stuff where the cursor is.

Ah fuck it, I hate vim! Try the tutorial if you want to know more about it.

$ vimtutor

some essential tools

cd - change directory

this is used to change your position in the file system


$ cd [directory]


$ cd .. change to the parent folder

$ cd /home/user change to a users home directory

ls - list folder contents

this command displays the files and folders inside a folder


$ls [option] [directory]


$ ls is the same as $ ls . displays the contents of the current folder

$ ls -l displays the contents in a more detailed list

$ ls -la displays all the content (including . and ..) in a list

$ ls /var/www displays the contents of /var/www

( sl - steam locomotive )

Only if sl is installed on the system. When you mistype ls, something funny happens.

mkdir - create directory

This command creates a folder.


$ mkdir [path]


$ mkdir foo create the folder foo inside the current folder $ mkdit /home/user/Public/foo create the folder foo inside the home/Public folder

touch - create file

This command actually changes timestamps, but is also used to create files.


$ touch [options] [files]


$ touch foo.txt bar.txt creates the files foo.txt and bar.txt in the current ddirectory

cp - copy


$ cp [options] [source] [destination]


$ cp hello.txt /var/www/html copies hello.txt to /var/www/html

$ cp -r ~/Downloads /mnt/usb recursively copies all the contents inside Downloads to /mnt/usb

$ cp hello.txt hello.txt.backup makes a copy of hello.txt at the same place

mv - move (rename) files


$ mv [options] [source] [destination]


$ mv hello.txt /var/www/html moves hello.txt to /var/www/html

$ cp hello.txt hello-world.txt renaming a file

rm - remove / delete files


$ rm [options] [files]


$ rm deletes

$ rm -r /home/user/folder recursively deletes folder and its contents

$ rm -rf folder recursively removes folder without asking (forcefully)

man - manual

Almost every command has a manual on how to use it. All available options are explained there.


$ man [command]

You can quit the man page by pressing q.


$ man ls shows the man page to the command ls

chmod - change the file mod bits

Each file has permissions. There are three types of permissions, r, w and x. They stand for read, write and execute. You can see the permissions for example when you use the ls -l command. The permissions are set by three bits like so.

permission r w x
bit 4 2 1

Also you have to set the bits for each group. There are again three groups: user, group and public.

The maximum permission you can give is 777, so everyone can do everything. Or 755 - everyone can execute the file, but only you can change (write) it.


$ chmod [mode] [file]


$ chmod +x make executable

$ chmod -w remove write permissions for

$ chmod 731 be more specific on the permissions for

sudo - super user do

Sometimes sou need root privileges to do something. That's the moment you use sudo. It grants you root privileges for only the command you are about to execute.


$ sudo [command]


$ sudo chmod +x change the permissions on with root privileges

execute the previous command with root privileges

$ mkdir /etc/bar
$ mkdir: cannot create directory ‘/etc/bar’: Permission denied
$ sudo !!

cat - print files to the standard output

This one prints out the contents of the file to the standard output (into the terminal).


$cat [option] [file]


$ cat foo.txt just prints the text inside foo.txt to the console

$ cat -n foo.txt also numbers all outputted lines

grep - print lines matching a pattern

Grep is a very good tool to filter output to highlight only the stuff that is interessting to you.


$ grep [options] [pattern] [file]


$ grep "user" foo.txt prints out only the lines inside foo.txt containing the word user

$ grep user foo.txt does the same thing as the line above

$ grep -i "password" bar.txt the -i option ignores upper case / lower case

$ grep --color "alias" ./bashrc prints all the aliases defined in .bashrc and highlights all occurrences

$ ps aux | grep root prints all processes started by root

wget - download

You can download files from the internet using the wget command. This programm is capable of many things like posting data before downloading or saving just the request / response headers without downloading the file.


$ wget [options] [url]


$ wget downloads the index.html of debians's frontpage

$ wget -O logo.png with the -O option, a filename can be set

Other commands

change the password

$ passwd or $ passwd user

who am i?

$ whoami

print the current working directory

$ pwd

zip some files

$ zip [] [files]

$ zip foo.txt bar.txt

$ zip -r /home/user/ (-r recursively)

delete a folder

$ rmdir folder

install /update a package

$ sudo apt-get install package

$ sudo apt-get update package

run a python file

$ pyhton

run something in the background

$ nohup [command] > /dev/null 2>&1

clone something from github

$ git clone

print running processes

$ ps aux

$ ps aux | grep user

execute commands right after each other using &&

$ rm -rf /var/www/html/index.html && cp -rp index.php /var/www/html