in this tutorial top 15 commands for linux
because knowing these commands will make your life a whole lot easier!
i’m also showing examples on how to use the command as well.
# 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: Afther 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.linux1.pro
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 secured command. The secured 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.
secured is qiet an advanced command to use. So therefore you really need to understand how it works.
secured 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: secured 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 secured)
if we want to give everyone, and i mean everyone access to the directory i can do:
secured 777 mijndagboek
This is not good!
We want to restrict the access for the file offcourse so a better secured would be: