Terminal basics: An easy Linux Terminal Tutorial

in #pc7 years ago (edited)

If you use a Linux distribution like Ubuntu or Linux Mint it is not necassary to do much terminal work. However, sometimes it is useful and much easier to do some terminal work. This tutorial will provide a brief introduction into some useful terminal commands.

First look into the Terminal
01.png

You see "[trashing88@manjaroBtrFS ~]$", where "trashing88" is in this case my username, and "manjaroBtrFS" is the name of the computer. The tilde "~" simply indicates that we are in our so called home directory which is the folder where your user data (like pictures, videos and documents) is located.

Which Linux distribution am I using?

"uname -r" give me the information "4.14.15-1-rt12-MANJARO". Where "4.14.15-1-rt12" stands for the so called Linux kernel version. The Linux kernel is the underlying layer which provides the functionality of the operating system. "MANJARO" is the name of my Linux distribution.

List the content of a directory

The "ls" (stands for "list") shows you the content where you currently are. In this case I am in my home directory (remember ~). But what if I don't want to show the content of my home directory?

The command "ls Bilder/" shows the content of the the directory "Bilder" which is a subdirectory of our home directory. If you want to show the content of the folder "Wallpapers" which is a subdirectory of "Bilder" simply type "ls Bilder/Wallpapers".

In this case only one picture "manjaro_polar_green.jpg" is in the folder.

Change directory
Until now we always have been in the home directory ~. Now we want to change this.

The "cd" (change directory) command provides this functionality. "cd Downloads/" changes the current directory into the "Downloads" directory. A simple check by ls shows that we ware indeed not in our home directory.
Note that [trashing88@manjaroBtrFS ~]$ has changed to [trashing88@manjaroBtrFS Downloads]$" which indicates that we are now in the directory Downloads.

Show content of files right from Terminal
Sometimes you want to see the content of textfiles. Instead of doing this in a graphical editor (which is sometimes a little bit long-winded) we can do this in the Terminal. In this example in my Downloads directory there is a file named "afile.txt". edit

The command "cat afile.txt" shows me the content of the file "afile.txt" which simply is "Here is much of content inside". Now we want to edit this file. We can do this right from the Terminal

"nano afile.txt" gives you the possibility to edit the content of the file "afile.txt".

I added the line "and we will provide more content soon". To save this we simply hit "STRG + O" which asks foyou really want to save the changesr a filename to save.

If you want to save the changes in the same file simply hit ENTER. To exit the editor hit "STRG + X".

Use autocompletion of long commands
Imagine you want to edit a file which is named "aVeryVeryLongFileNameWhichIsToComplicatedToTypeIn.txt". You have to type "nano aVeryVeryLongFileNameWhichIsToComplicatedToTypeIn.txt". But this is not very smart since the probability for a typo is high and even if you make no typo it will take you a while to type in this filename.
Fortunately, the Terminal provides autocompletion. Just type "nano aVery" and hit the tabulator key "TAB".

This also works for other commands, e.g. "cd" and "ls". If you want to change into the directory "/Bilder/Wallpapers" and you don't want to type in "Wallpapers" simply write "cd Bilder/W" and hit the tabulator key. The autocompletion then completes the command to "cd Bilder/Wallpapers".

Magic terminal hacking
We want to close with a view into the future where I will show more advanced Terminal commands. Imagine your pictures folder has 10.000 pictures inside. A simple "ls" command will give you

This is not very helpful. You don't see all pictures and maybe if you are only looking whether the picture "picture124.jpg" is in the folder, you can't see it with this command. Now it is time for a powerful Terminal tool called "grep".
The "ls" output is a text itself. Why not searching in the text for our picture "picture124.jpg"?
The command "ls | grep picture124.jpg" will do the following: The first part "ls" will produce the output text above. The pipe "|" redirects this text to the command "grep picture1234.jpg". Grep now searches for the text "picture124.jpg" in the text of all pictures names (which comes from the ls command).

Stay tuned for the next parts of our Terminal Tutorial! Hope you enjoyed it.

Sort:  

Congratulations @trashing88! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @trashing88! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

SteemitBoard Ranking update - A better rich list comparator
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.24
TRX 0.26
JST 0.041
BTC 95868.85
ETH 3448.93
USDT 1.00
SBD 3.40