15 Very Useful Linux Commands that everyone should master!
- Details
- Parent Category: ROOT
- Category: Blog
- Created: Wednesday, 07 June 2023 04:39
- Last Updated: Wednesday, 07 June 2023 04:39
- Published: Wednesday, 07 June 2023 04:39
- Written by Edukasyon Online
- Hits: 2077
knowing these commands will make your life a whole lot easier!
I am also showing examples on how to use the command as well.
Let's get started!
-------------------------------------------------------------------------------------------------------------------------------------------------
# 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 <--
#2: man
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".
#3: ls
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.
Example: ls
It shows us the directories available.
#4: cp
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.
#5 mv
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!
#6 mkdir
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.
#7 rmdir
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.
#8 touch
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.
#9 rm
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.
#10 tar
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.
#11 pwd
Sometimes you really wonder where you are in the system. PWD is the solution for that problem.
PWD stands for Path Working Directory.
Example: pwd
#12 ifconfig
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.
Example: ifconfig
note: To gain information about the wireless adapters on your system type iwconfig.
#13 locate
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.
#14 ping
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.
#15 chmod
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:
7 | full |
6 | read and write |
5 | read and execute |
4 | read only |
3 | write and execute |
2 | write only |
1 | execute only |
0 | none |
source: http://en.wikipedia.org/wiki/Chmod
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
3rd: Others
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:
- Read
- Write
- Execute
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)
[membersgroupbit],[others],[alloftheabove]
if we want to give everyone, and i mean everyone access to the directory i can do:
chmod 777 mijndagboek
[read=4+Write=2+Execute=1=7],[read=4+Write=2+Execute=1=7],[read=4+Write=2+Execute=1=7]
This is not good!
We want to restrict the access for the file offcourse so a better chmod would be:
chmod 700
[read=4+Write=2+Execute=1],[0][0]
--------------------------------------------------------------------------------------------------------------------
This is the end of the top 15 i made for you. I hope you enjoyed it, and hopefully even learned something as well.
Comments: