It has been a very long time since I started using a linux distribution for the first time. There have been many cases when I did not know what I was doing but as the time passed I got better and better. Many errors, many problems and a lot of fun with the different utilities being used by linux geeks.
The terminal is scary for so many people new to it but once you have learned the basics I got to tell that you will have hunger for learning more commands, learning different tricks and hacks to get the best out of your operating system.
The ls command
Before using linux I had no idea about the power of the terminal and it is absolutely fair if you know nothing about this power either. For example if you want to list files in a directory you just run the ls command like shown below.
ls
But the above command becomes very helpful when you are looking for a specific file. Lets suppose you have a directory with so many files and you want to see if test.txt exists in there. To find out you can easily pipe the output of the ls command to the grep command. The grep command then filters the output and greps the file you are looking for.
ls | grep test.txt
If the file test.txt exists then it should be displayed on your console like shown below.
oltjano@baby:~/Desktop$ ls | grep test.txt test.txt~
There are cases when you have to deal with files that start with a dot. Files that start with a . are hidden in a directory. Running the normal ls command is not going to list them. The -a option is needed in this case.
ls -a
The above command lists all files including the hidden ones. There are many other options you can use when working with the ls command such as -l option which stands for a long listing format, -s to print the allocated size of each file in blocks, -t to sort by modification time (newest first), -h to print file sizes in a human readable format so everyone can read the output even if they have no idea about computers in general.
If you are new to linux and to the ls command then you can learn how to use it by typing the following command on your console.
man ls
Most of the times not only you will get the usage manual of a command when using man but you will also get practical examples that help to get a real world experience.
The pwd command
There will be many cases when you want to display the current working directory. That is what the pwd command does. It prints the current working directory.
pwd
Running the above command on my console displays the following output.
/home/oltjano/Desktop
The above output means that I am working on my Desktop. I find the pwd command very useful when working on different projects.
The cd command
You will not always work on the same directory so you need a command to change the working directory. The cd command command can do that for you.
pwd
As you can see it prints the following. It means I am on my Desktop.
/home/oltjano/Desktop
Then I can use the cd command to change directory like shown below.
cd MyLab
For now all you should know about the cd command is just to change the working directory.
The cat command
The cat command is very helpful when you want to display the content of a file on your console. For example to display the content of the test.txt file I have to type the following command.
cat test.txt
The cp command
The cp command is used to copy files and directories. This is very useful when you have files that start with the same name as it helps to do a bulk copy.
cp same_name* /home/oltjano/Desktop
The above command is going to copy all files that start with same_name in my Desktop. Time is money so save it. And to save time while working on linux you should make use of this great utility.
The chmod command
The chmod command is used to change permissions to file system objects. I mainly used this command to change file permissions of python scripts I use.
The following command helps me to make my scripts executable.
chmod +x myscript.py
In this case myscript.py is a python script which can be used in a linux operating system by typing the command shown below.
./myscript.py
Usually you run the following command to execute a python script, but since we used chmod +x to make it executable a shorter command can be used.
python myscript.py
Some examples of using the chmod command are shown below. Make sure to study them for future usage on your linux distribution because they are very useful.
- chmod a+r mytest.txt read is added for all classes (i.e. User, Group and Others).
- chmod +r mytest.txt omitting the class defaults to all classes, but the resultant permissions are dependent on umask
- chmod a-x mytest.txt execute permission is removed for all classes.
- chmod 664 mytest.txt sets read and write and no execution access for the user and group, and read, no write, no execute for all others.
- chmod 0744 mytest.txt equivalent to u=rwx (400+200+100),go=r (40+ 4). The 0 specifies no special modes.
The wget command
Downloading files in linux from the terminal can be done in many ways. On of them is to use the wget utility which can be used to retrieve files using the HTTP, HTTPS and FTP protocols. This non-interactive commandline tool has many cool features and also supports HTTP proxies.
To download a file just use the following command.
wget link_of_file_which_is_available_for_download_here
By using the wget utility you can also resume aborted downloads, using REST and RANGE. For more information on the wget commandline tool visit the official page.
The ssh command
When doing freelance work for a client usually they give you the ssh credentials of their servers so you can start working there. Once you got the right shh login credentials you need to use an ssh client to connect to the server. In case you do not know what ssh is let me explain it to you in short words: ssh stands for secure shell and is to access remote Linux and Unix-like servers, such as VPS instances.
The basic usage is shown in the following example.
ssh remote_host
The uname command
I use the uname command all the time to print system information. For example the following command is used to print all information of your system.
uname -a
As you can see the -a stands for all.
You can also print the kernel name by using the -s option.
uname -s
When running the above command on my system I get the following output.
Linux
It means that I am using a Linux kernel.
To get the kernel release just use the uname command with the -r option like shown in the following example.
uname -r
Running the above command prints the following output on my console.
3.8.0-36-generic
What about the kernel version? Is there any option to display it? Yes the -v option can be used in this case.
uname -v
The above command displays the following information on my console.
#52~precise1-Ubuntu SMP Mon Feb 3 21:54:46 UTC 2014
There are many other useful options that the uname utility supports but the purpose of this article is not to discuss them here. Maybe we will take a deep look on the uname utility in another article.
Conclusion
In this article I took a look at some command I have been using while working on Linux. But it does not end here. There are many other commands I use daily and would love to share each one of them with you guys.
Also, read: