When hearing about Linux, the first thing that comes to your mind is programmers, hackers and technology specialists. But it is not that intimidating to work with, as you might think on contrary.
Linux is a open source computer operating system widely used by programmers, techies and in servers for its powerful functions and features. It was first created in the early 1990s by a Finnish software engineer Linus Torvalds and the Free Software Foundation (FSF). System administrators really love working with this, because it is easy to maintain and has better stability and security than the Windows operating system. It can have plenty of free and open source software from repositories and contributors from all over the world. Linux has a powerful Command Line Interface (CLI) through which a lot of tasks can be done in one command, unlike through a Graphical User Interface (GUI). Many people find GUI easier than CLI because of steep learning curve. But with repeated practice, this picture gets clearer. In this article, I will explain ten Linux commands that you should know.
1. ls command:
The ls command shows the contents of a directory. But you must set the current working directory with the “cd” command which I will explain next.
For example: if you want to view files in home directory, type cd /home to set directory. Then type ls to view its contents.
2. cd command:
To navigate through the directories use this command. This requires the full path of the directory or sometimes only the name of directory, which depends. This command is case-sensitive and directory path should not contain any spaces, which will cause error.
For instance, if you have a folder named “Documents” and you want to set your current working directory to it. Type cd /home/<username>/Documents to achieve that.
There are few variations of this command:
- cd .. to move one directory up.
- cd to go to home folder.
- cd / to move to root directory of entire system.
3. cp and mv command:
cp and mv commands are noted together as they similar looking. Here cp is used to copy files and mv used to move files. Additionally mv can be used to rename a file as well.
To copy files, cp command is used. For example if you want to copy a file named xyz.pdf from current working directory to documents directory, type this command: cp xyz.pdf /home/<username>/Documents.
To move files, mv command is used. For example if you want to move a file named xyz.pdf from current working directory to documents directory, type this command: mv xyz.pdf /home/<username>/Documents.
mv command can be used to rename a file or a directory too. Type mv dir1 dir2 to rename this directory and mv xyz.pdf abc.pdf to rename this file.
Unnecessary spaces in commands will cause error and your file(s) or directory will not be copied, moved or renamed.
4. mkdir and rmdir command:
To create a new directory use the command mkdir. Type mkdir Music to create a directory/folder named Music. You can use this command to create directory inside a directory as well. In that case, type mkdir dir1/Music. Results will be similar.
In case of rmdir, it will delete a directory including its sub-directories. Before you can do that, you may need file permissions, which I have explained in point 5.
5. chmod command:
This command helps to set the permission of files or directories. Read, write and execute permissions of file(s) can be managed using this command. This command is a lengthy one, so I will mention one important but common way to use this:
Usually this is the command structure: chmod options permissions filename
Let’s take an example, chmod 777 music.wav, here we have three digits where each represents a permission i.e “user”, “group” and “others” respectively. Each digit is a summation of 0, 1, 2 and 4. Rest others are combination of these mentioned.
- 0 represents “no permission”,
- 1 represents “execute”,
- 2 represents “write”, and
- 4 represents “read”.
So in the given permission notation, we have first digit from left, 7 i.e 4+2+1 (read, write and execute). Rest two digits are same. So permission for all three owners i.e “user”, “group” and “others” are same, in other words, they have full permission over this given file.
Find the full tutorial for this command here.
6. chown command:
All files in Linux are owned by root user. But sometimes it becomes essential to change ownership of a given file or directory from one user to another. Here chown allows you to do this, where you can change ownership from one specific user to another.
For instance, chown user1 music.wav will make user1 as the owner of the file.
7. ping command:
If your Linux machine is a server which is connected to internet, then this command is very useful in determining the connectivity status of that machine. Simply you can run ping <domain name or ip-address> to get a reply and response time measured in milliseconds. This command can work on a local area network too.
8. whoami command:
This command is simple to understand as whoami stands for ‘who’, ‘am’ and ‘i’ written together. It displays the username of the current user of the Linux machine.
9. head and tail command:
These two commands are similar. They print lines from a file specified by user using option (-n). The head command prints the first ten lines from a file and the tail command prints the last ten lines by default.
head command: head -n 20 artists.txt
tail command: tail -n 20 artists.txt
10. sudo command:
Abbreviation for “superuser do”, this command allows you to execute programs and do various administrative tasks on the system. An user with sudo privileges has virtually unlimited control and ownership over a system. It allows full access and modification of all the files.
Because this command is so powerful, only very few people i.e system administrators, owners, root users have access to these accounts in a system. It is not recommended to use this command often and for simple tasks as it poses a security risk and instability to the system.
Example: sudo apt-get update (downloads and installs update packages from all configured sources on a Ubuntu system)
Installing, upgrading and updating of packages are administrative tasks, therefore sudo command is required.
CONCLUSION:
Linux commands are hard to remember and understand in the first gaze. But these basics will get you started. One can run a simple update operation to an entire system administration tasks in just command line interface. Of course you cannot play games and edit videos in CLI, right? For example, there is a server OS called Ubuntu Server, which exclusively runs on CLI. Generally, most users are accustomed to a Graphical User Interface or GUI, however, CLI skills sets them apart from the rest. Therefore it is pretty evident that how much valuable these skills really are.
See you in next blog post. Peace 🙂
Leave a Reply