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
^C shortcut is the universal cancel or stop command to stop a running process. There are other programms who use the
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
$ ./script.sh > /dev/null ignores the output of
script.sh by forwarding the output into
>> - 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.py >> foo.log appends all output generated by
folders and files
||current working directory|
||the parent directory|
||home directory of the current user|
||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
$ ./script.sh execute the file
script.sh inside the current folder
$ cd ~/Downloads change to the Downloads foler in your home directory
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]
$ 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.
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
..) in a list
$ ls /var/www displays the contents of
sl - steam locomotive )
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
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
bar.txt in the current ddirectory
cp - copy
$ cp [options] [source] [destination]
$ cp hello.txt /var/www/html copies
$ cp -r ~/Downloads /mnt/usb recursively copies all the contents inside
$ 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
$ cp hello.txt hello-world.txt renaming a file
rm - remove / delete files
$ rm [options] [files]
$ rm foo.sh 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
$ man ls shows the man page to the command
chmod - change the file mod bits
Each file has permissions. There are three types of permissions,
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.
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.
755 - everyone can execute the file, but only you can change (write) it.
$ chmod [mode] [file]
$ chmod +x foo.sh make
$ chmod -w foo.sh remove write permissions for
$ chmod 731 foo.sh 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 foo.sh change the permissions on
foo.sh 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
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 https://www.debian.org/ downloads the
index.html of debians's frontpage
$ wget -O logo.png https://www.debian.org/Pics/openlogo-50.png with the
-O option, a filename can be set
change the password
$ passwd or
$ passwd user
who am i?
print the current working directory
zip some files
$ zip [filename.zip] [files]
$ zip test.zip foo.txt bar.txt
$ zip -r home.zip /home/user/ (
delete a folder
$ rmdir folder
install /update a package
$ sudo apt-get install package
$ sudo apt-get update package
run a python file
$ pyhton file.py
run something in the background
$ nohup [command] > /dev/null 2>&1
clone something from github
$ git clone https://github.com/...
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