You’re new to the Linux Command Line and truth be told, you might be a little intimidated. Coming from the comfort of a PC or Mac desktop, the Linux Command Line (CLI) looks nothing like what you normally use. The Linux CLI is dark, it’s secretive, it’s bare bones minimal and it’s anything but friendly to newcomers. And yet, the Linux CLI is highly useful, essential to using your Linux box or virtual machine and can, if done right, provide you with more insight and practical use than the Windows or Mac desktop ever could.
For those reasons, from someone who was also once a Linux newb, I present the top ten Linux CLI commands you need to master for basic Linux CLI comprehension.
# 1: cd
The “Change Directory” command enables you to navigate to another directory.
The cd command is THE most important command there is in linux i think. As the command suggests, it enables the user to change / jump to a directory.
Example: cd Downloads
Example: cd /etc/
Example: cd .. (Directory up!)
Note: After you have typed cd and entering the first or two letters of the directory you can press the TAB key to autocomplete the directory! so… cd Do (press tabkey) will autocomplete it to Downloads. i use this a lot <–
The man command shows the users the “manual” of the command. In some situation you might need to get more information about the command you are using. The man command shows you this information about the command.
Example: man cp
This will open up the “cp” manual document for us in the shell. The manual shows us the parameters available for the commands.
Note: To close the manual simply press “Q”.
In the absolute top 15 there’s no way the ls command is missing. On the third place, the ls command. The ls command is used to list the files/directories within a directory.
It shows us the directories available.
The cp command is available for us to “Copy” things. This might be usefull for duplicating files f.e.
Example: cp file file2
note: file is on this case the file the user wants to be copied… file2 is the name of the copied file. It’s that simple.
The mv command is used for “Move” operations. The mv commands enables the users to move a file/directory to a specified location.
Example: mv /home/bas/Desktop/bla /home/bas/Desktop/fiets
Note: the first part of the command is the file that has to be moved. The second part (after the whitespace) is the target directory. Make sure you type in the full path using this command!
This command is used to “make” directories, NOT Files.. (thit is possible with another command which i will bring up later in this tutorial)
Example: mkdir testdirectory
Note: The name of the directory is case sensitive which means that Testdirectory is a complete different directory as testdirectory.
When you are able to make directories, you also want to know how to remove them. Removing directories is done by the rmdir command and belongs to the absolute basic commands in shell bashing.
Example: rmdir fiets
Note: When the directory is not empty the command will prompt an error message:
rmdir: failed to remove `fiets’: Directory not empty
So make sure it’s completely empty before removing it.
Now we know how to make directories and deleting them, i now want to use the touch command. The touch command is used to make files.
Example: touch vogel
This will create the file vogel for us in the directory.
The rm command stand for remove. The rm command is used in order the delete files instead of directories.
Example: rm vogel
Note: To remove files you must have the right permission bits set on the specific file.
Sometimes you have to archive files. Archiving files is a way to pack a set of files to one single file. The operation is done by the tar command.
Example: tar -cvf test.tar test (Creating a tar file from directory or file test)
Example: tar -xvf test.tar myexctractfolder (Extracts the particular tar file in the current working directory)
In the example i used parameters. These parameters are telling the tar command how to behave and how to execute. After the parameters i entered the name of the file which is test.tar. The second part is the source directory/file of the tar file. In this situation a directory called test.
Sometimes you really wonder where you are in the system. PWD is the solution for that problem.
PWD stands for Path Working Directory.
ifconfig is a command showing you information about the ethernet adapters on your system. It contains very usefull information like gateway, ip, and packet statistics. For the average user this command is rarely used, but i think it’s worth knowing it.
Note: To gain information about the wireless adapters on your system type iwconfig.
Locate is an extremely fast seaching command. It shows the directories or files each on a new line.
Example: locate syslog
Example: locate syslog | more (Piping structure used to invert the data from locate to the more command)
Note: Some keywords returns enormous ammounts of hits. Use MORE to (see example) clear things up a bit.
Ping is used as a network diagnostic command by professionals. Ping offers information about the network we are on and if the other system responds to us. In cases of troubleshooting network related problems, ping can do a great job to determine the domain of the problem.
Example: ping www.google.com
The command returns the interval and % of loss during the test.
Note: You can stop ping bij pressing crtl-c at the same time.
The chmod command. The chmod command comes from “Change Mode” back to the unix times. It’s a great command to restrict access to directories or files. But before i show you an example on how to use it, some theory.
Chmod is qiet an advanced command to use. So therefore you really need to understand how it works.
chmod works with so called persmission bits. These bits can be set to a certain level of restrictions.
We have the following bits available:
|6||read and write|
|5||read and execute|
|3||write and execute|
The bits shown above are the permissions for a particular group or class.
Files or directories contain four classes:
1st: The owner itself
2nd: Member of the file group
4th: All of the above
To set the right permission bits the a particular group or class it is very important to select to right amount of permission bits.
for example, i will create a file and protect this file for being modified by anyone else besides me. Also will i protect the file for being deleted.
This is how i do it: chmod 400 mijndagboek
In this command i gave up the 4 bit in the “members of the group” 0 to others and 0 to all.
Now not even me is able to delete the file anymore without using the sudo command.
But.. there is more. The classes i talked about earlier are devided into three seperate like actions.. those are:
In order to add very specific restrictions to a file or folder you can use a trick to do that. I will show you how.
If we want to restrict access to a file without knowing the exact bit number we can do the following.
RWX = 7 Which is the permission bit of Read, Write, and Execture together.
Seperating these bits gives us the following values individually:
Read = 4 bits.
Write = 2 bits.
Exec = 1 bit.
So we have 3 groups to take care of (the first group which is the owner is optional in chmod)
if we want to give everyone, and i mean everyone access to the directory i can do:
chmod 777 mijndagboek
This is not good!
We want to restrict the access for the file offcourse so a better chmod would be: