The Linux Terminal

If you are not familiar with any command line interface I would request you first read this article.

The Linux Terminal is a wonderful tool (I know i have a bias against windows and you’ll have to bear with me).  In fact if you ever aspire to be a system administrator you can bet you’ll spend a lot of time in front of your terminal.

Now I am assuming you already know about commands and parameter from the cmd article. the only difference in linux is that parameters will be preceded by “-” instead of “/”.

the “cd” command works the same for linux as it does for windows. So I will not delve into it.

pwd

pwd results

This is one of the first commands I learnt so out of respect for that tradition I will start with it too. “pwd” stands for “print working directory” (remember that fancy name for folders? better get used to it). it does just that it shows you the current directory you are in.

At this point I feel obligated to tell you something unique about linux that people from the windows world may find peculiar at first. Linux does not separate its drives as windows does, it does not put a “drive C”, “drive D” and so on. Everything in linux begins from a folder called root directory depicted as “/”.

If you look at the output of pwd command it shows “/home/adiel” how we interpret this is that from the root directory, “/” we enter the directory called “home” then the directory “adiel”.

ls

ls results

ls” stands for list and it does just that. It lists the content of a directory. In the Graphical user interface world we click a folder and we see its content. In the terminal once we enter a directory we do not know anything about what is currently there. This is where “ls” comes in handy it helps us see what is there.

In the article on the command prompt we did mention parameters. The “ls” command has a couple of them but for the sake of this article we will only look at 2 that is the “-a” and “-l”

ls -a results

The “-a” parameter shows you all the files and directories in a folder including hidden files and folders. In linux any file or directory that begins with a dot “.” are hidden or means that a normal “ls” will not show them. Notice in our example above something like “.bash_history” was not shown when we just did “ls” because it was hidden.

ls -l results

The “-l” option tells ls to use a long listing format. This format shows a lot of information on the files and folders inside. In this article I will not delve into what that all means (in future I will have to write an article on permissions in Linux and that will make it all clear).

You can also combine 2 options in one argument in Linux like this.

ls -al results

Some File and Directory Manipulation

cp

cp in action

cp” stands for copy. All it does is copy a file from one place to another. If done with in the same folder you will have the same copy of the one file. The format is “cp path-to-file path-to-copy-location”. Notice how I copy test.txt to test2.txt and both of them appear now when I check the file contents.

mv

mv in action

mv” stands for move. All it does is take a file from one location to another. While copy will leave a copy of the original file in its place, move removes the original file from its location and moves it to the other location without retaining the original file. If applied within the same folder, “mv” acts like rename. Another analogy you may be familiar in with in the graphical user interface is that “cp” is like “copy + paste”  and “mv” is like “cut + paste”. The format is “mv path_to_file path_to_move_location”. But notice like in the example above we used it to rename the file “test.txt” to “changed.txt”

rm

rm in action

rm” stands for remove. What this does is remove or delete a file or a directory. Be careful with this one it deletes a file without asking if you are really sure and there is no recycle bin to come to your aid. So don’t say I did not warn you. By default rm will refuse to delete a folder that has files in it. Notice in the example above how I changed the file “

do not try this at home

There is this cruel joke (I say cruel because if someone where to actually try it they would wipe out their machine) that if you want your linux machine to perform faster run the command “rm -rf /*”.  Let us analyse what this command does. “rm” removes or delete as we previously said but what about the parameters we give it? “-f” is a parameter that tells rm to forcefully remove something. “-r” Tells “rm” to do so recursively that is to remove files and when it comes to directories delete the directory and all sub directories. The final parameter the “/*” tells it to start from the root folder. Remember what we said about the root folder? Everything starts from there so running that command is actually telling the system to delete everything including itself. Linux however with security in mind made it such that only the root user ( this is the user with all rights) can run that command.

file

file results

file” is a Linux command that tells you what a file consist of for example notice the difference when I query what the file “me.c” which is a text file and “me” which is a program.

Conclusion

You may ask yourself how do you know or see what other parameters do? The good news is Linux also has 2 main ways you can see and understand parameters of a command.

  1. Using “–help” parameter. If you use the “–help” parameter on a command it will list you parameters and what they do in an abbreviated format
  2. Using the “man” pages. You type man followed by the command you want to know about (e.g “man file“). That give you a longer explanation. Notice when in a man page you need to use arrow keys to scroll and q to exit.

Hopefully this has been insightful enough.

We value your feedback

Your email address will not be published. Required fields are marked *