In the second part of the Linux Tutorial, we will learn about dealing with files and folders (directory).

First move to your home directory with (change directory):

Now let us create a directory, named „garage“, with the „make directory“ command:

You have created the garage directory, but you are still inside your home directory. Go into the garage directory with:

Notice,  that the „change directory“ is by far the most important command. You will see, that you will use this command very often.
In the next step, you go „one directory up“, so that you will be in your home directory again. This can be achieved with:

Don’t forget the space between „cd“ and the two dots. The two dots is a sign for the directory above. There is a top-level directory, called the root. There is no directory above the root directory. You can go there with:

Again, there is a space between „cd“ and the „slash“. If you are curious whats inside the root folder, type:

The list command, with the parameter „l“, shows you the directories content. Time to back into our garage directory inside our home directory. Go there with:

The tilde (press Alt-key + tilde-sign) is a sign for our home folder. And we want to go inside the garage folder, which is inside our home folder. We create now a file called „mycar.txt“ and write „bmw“ inside this file. Here we go:

The echo command simply displays the word in quotes, in this case „bmw“. The > character redirects the result („bmw“) into the file, which came behind the „>“ sign. Btw: a single „>“ always create an empty file, even when the file already exists. When you want to attach something to a file simply use „>>“. Let’s look into the file:

We want to copy the file mycar.txt:

And now we want to attach something to our new file:

Check the content of our new file with:

And check the contet of our garage folder with:

 

Veröffentlicht unter linux.

tcptrack

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

and start it with

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

Netstat

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

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:

 

lsof

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

 

Let’s have a look which packages are already installed and show only those with „php“ in the name. A fresh system usually shouldn’t give any results.

Next you can check what kind of modules are available. Do it like this:

Now install the php7 base packages with the command:

Now install some other packages for php:

 

Try this out:

 

Veröffentlicht unter linux.

Sometimes it happens that you can’t use your services cause they deal with blocked ports. For exampel you use mysql on the commandline and it is by some reason denied. A proxy can help you. Tsocks helps you to use a proxy. Tsocks is a library for intercepting outgoing network connections and redirecting them through a SOCKS server.

install tsocks with

Configure the file /etc/tsocks.conf

and finally call your command like this:

 

 

List all Instances

Stop an EC2 instance

Start an EC2 instance

 

First find all the files you want to convert and store their filenames in a file

Iterate through that files and make a jpeg from them

Finally move all jpgs to a separate location if necessary

 

In reality you have quite often perform a certain command on several files. First i detect all files I’m looking for and store them in a filelist.

Second i run through this file, line by line and perform my command on all filename I’ve received one step before.

You need to replace in several files. You can do it with sed. Be aware about masking special chars. In the example below the string „my\folder“ is replaced with „your\folder“.
Replacing with sed works like this: sed -i s#old#new#g
The delimiter (in this case the #) can be changed. The first sign after the s acts as delimiter.

 

Getting the size of all files and folders inside the current directory can be done by typing:

Get filesize in descending order from all files in a recursive folder structure

Another quite handy tool is ncdu. It provides you the disc usage in a graphical way on the shell. Install it like this:

List folders bigger 1Mb and list them in descending order

List the ten largest folders inside a recursive folder structure

 

A handy tool for dealing with different bash sessions is tmux. It’s comparable with gnu screen but by far more advanced. You can get it with:

Launch it by typing:

Dealing with sessions brings great power. You can set up your multi-windows panes on a remote machine, in a seperate session. Now you can detach from this session and log out. When you later ssh back into this machine you can reattach this session and all your views are restored.

Executing commands tmux specific is usually prefixed with the key combination ctrl+b. See the following list what you can do with tmux.