Linux Tutorial Part1

These tutorials explain the Linux operating system (os) step by step. Starting with simple examples and getting more advanced each lesson.

The line where we type in the commands is called the prompt, the blinking something right to it is the cursor.

Lets show who is logged in:


And the hostname of the computer can be shown with:


As you can see, username and hostname are contained in the prompt.

If you want to know the name of the operating system, you can use:


How long the computer is up (not rebooted since) shows the following command:


Clear all the stuff on the screen with:


If you using the arrow keys (up and down), you can browse between the commands you already entered.

When you want to know in which folder you are, use:


It’s short for: print working directory.

Let’s go to your users home directory by typing:


At this location, all the files related to your current user are stored. You home-folder is a special folder. The tilde sign „~“ is a synonym for your home folder. Instead of typing „cd“ you can type „cd ~“ as well. When you’re in your home folder you can see the tilde in the prompt. The tilde sign is a variable. You can output its content to the screen:

echo ~

Create a directory named garage withe this command:

mkdir garage

mkdir is short for: make directory

Most important command of all is „cd“. It means change directory. With this command you can browse in the directory tree.
Let’s switch to the directory „garage“ you recently created by typing:

cd garage

The prompt, by the way, also shows you in which directory you are. (So you don’t have to type pwd all the time)


If I want to go back in the directory-tree, like one level up, we use:

cd ..

Don’t forget a space between cd and the two dots. The two dots are a symbol for the upper (superordinate) folder.

If you type the first letters of a command, try to press two times the tab-key, and the command will be completed.
This will save your time. It’s one of the most useful ways to increase your working speed.

Linux Tutorial Part2 >>


How to get size of whole mysql-db?

SELECT Round(Sum(data_length + index_length) / 1024 / 1024, 1) „size“ FROM information_schema.tables GROUP BY „size“;


If you want to search words that are not spelled correctly you can use mysql’s buildin SOUNDEX function:

SELECT * FROM po_images
  '%',SUBSTRING(SOUNDEX('wronk spellet wort'),2),'%'



centralization versus decentralization

Both of them, centralized and decentralized systems, have their unique strengths, advantages, and peculiarities. In this examination, I’ll dive into both concepts. It was an IT related issue that encouraged me to get in touch with this issue, but the concepts and thoughts can be applied to almost every area.
None of both is a better nor superior concept. It depends on the specific situation if centralization or decentralization is a better match. In reality, you will often find a combination of both of them. And sometimes an advantage can be a disadvantage as well, depending on the point of view.

Centralization can appear as decentralization. Imagine a system containing several redundant nodes (client-systems). If they are completely synchronized they seem like a centralized system. You can always wrap an imaginary container around a system, and handle it from outside as an atomic entity. No need to look into the system, as long as you can communicate from outside to it. Think about an enterprise. From a customer perspective, you’ll see one entity – like one centralized system. If you working inside that company, you possibly see yourself as one department, equal to other departments, supplementing the whole system.

Advantages of centralization:

  • easily maintainable
  • changes need’s to be done only in one place, the central-hub
  • no redundancy
  • client-systems dealing with the central-hub can easily be established
  • less complex than decentralized systems
  • Communication needs to be standardized

Advantages of decentralization:

  • Single client-system are dispensable
  • client-systems are more autonomous – can live for themselves
  • Direct communication between client-systems
  • No need for a standardized communication
  • more tolerant against attacks


Monitoring network traffic


You want to track all incomming http-Headers on your Webserver?

sudo tcpdump -A -s 10240 'tcp port 80' | egrep --line-buffered "^........(GET |HTTP\/|POST |HEAD )|^[A-Za-z0-9-]+: " | sed -r 's/^........(GET |HTTP\/|POST |HEAD )/\n\1/g'

Show the HTTP Requests only:

sudo tcpdump -A -s 10240 'tcp port 80' | egrep "^........(GET |HTTP\/|POST |HEAD )|^[:alnum:]+: " | sed -r 's/^........(GET |HTTP\/|POST |HEAD )/\n\1/g'


A quite handy tool for monitoring tcp traffic is tcptrack. Get it with:

sudo apt-get install tcptrack

and start it with

sudo tcptrack -i eth0 port 80

the interface parameter -i eth0 must be according to your needs, you can check your interfaces with ifconfig.

There is also tcpdump, tcpflow and other nice tools


Sometimes one like to figure out what programs listen at a port. Here we can get an overview with:

sudo netstat -tupln

Where t=tcp, u=udp, p=show program name, l=show listening ports, n= numeric (not resolve machine names)
The Output could look something like this:

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0* LISTEN 1338/mysqld 
tcp 0 0* LISTEN 1709/dnsmasq 
tcp 0 0* LISTEN 1303/sshd 
tcp 0 0* LISTEN 1900/xrdp-sesman
tcp 0 0* LISTEN 1356/tor 
tcp 0 0* LISTEN 1887/xrdp 
tcp6 0 0 :::80 :::* LISTEN 2064/apache2 
tcp6 0 0 :::22 :::* LISTEN 1303/sshd 
tcp6 0 0 :::443 :::* LISTEN 2064/apache2 
udp 0 0* 1709/dnsmasq 
udp 0 0* 7335/chrome 
udp 0 0* 1062/avahi-daemon: 
udp 0 0* 1062/avahi-daemon: 
udp 0 0* 1709/dnsmasq 
udp 0 0* 1698/dhclient 
udp 0 0* 4625/cups-browsed
udp6 0 0 :::51764 :::* 1709/dnsmasq 
udp6 0 0 :::45088 :::* 1062/avahi-daemon: 
udp6 0 0 :::5353 :::* 7335/chrome 
udp6 0 0 :::5353 :::* 1062/avahi-daemon:



With lsof you can determine easily which program listens on a port and under which user that program runs:

sudo lsof -i :80



Need Ping  and traceroute combined in a single application? Use mtr (matt’s traceroute)



dealing with local mta

MTA stands for „mail transfer agent“. Popular ones are sendmail, exim and postfix.

If you want to know what MTA is running locally you can check which program listens on port 25:

lsof -i :25

You might also telnet on port 25 and let the MTA himself respond who he is:

telnet localhost 25


For configuring exim4 the preferred way is to use the graphical interface, call it with:

dpkg-reconfigure exim4-config




Easiest way to check a connection for a MSSQL database:

Create a file called : myfile.udl

Paste the following content (make sure to use your settings):

; Everything after this line is an OLE DB initstring
Provider=SQLOLEDB.1;Persist Security Info=False;User ID=myUsername;Data Source=;Password=myPassword


show word occurence in pdfs on commandline

Do you want to know how often words occur in a pdf file? And sort them by the most occurring word:

pdftotext mypdf.pdf - | sed "s/[[:cntrl:][:digit:][:punct:]]//g" | tr '[:space:]' '[\n*]' | sort | uniq -c | sort -bnr

Let’s break it down step by step:

pdftotext mypdf.pdf -

displays the pdf content on the command-line


sed "s/[[:cntrl:][:digit:][:punct:]]//g"

replaces all control characters (cntrl), all numbers (digits) and all punctuation characters (punct) with an empty string.
See here for character classes.

tr '[:space:]' '[\n*]'

replaces all spaces with a newline


sort | uniq -c | sort -bnr

The last part sorts the output, groups unique lines and prefix them with the amount and finally sort them again
with ignored leading blanks (-b), sort numeric (-n), in reverse order (-r)