35 important Linux commands you should know !

35 important Linux commands you should know !

ยท

9 min read

In this article we will explore about essential Linux commands and how to use them in your terminal.

Now, let's see what the Linux commands are, and what functions they perform.

๐Ÿ“man

this command is also referred as "manual page", which display the detailed view of any command that we run on the system.

This command will display a detailed view of command in Linux, which includes name, descriptions, files, versions , EXIT STATUS , REPORTING BUGS and many more.

$ man [command name]

You can just press the "Enter key" on your keyboard to see more detailed view of "ls" command.

๐Ÿ“ls

ls command stands for "list". This command is used to list all the files and directories in the current directory on the terminal.

$ ls

$ ls -a --> list of all the files and folders including hidden files & folders**.**

$ ls -l --> Use to see all the files and folders including file permissions as well.

$ ls -al --> combine the above two commands, hidden files and folders + details.

However, if you are a curious enough to know, then you can type "man ls" in terminal to see options and their functions.

Note:- In linux "directory" is same as "folder" in windows. so don't get confused.๐Ÿค”

๐Ÿ“mkdir

This command stands for "making directory". It is used to create a directory(folder) in your current directory.

$ mkdir [newdirectory]

You can also confirm whether the directory "India" has been created by using the command "ls".

You can see that the directory "India" has been created.

you can also create many directories, just by writing single line command. once the directories are created then user can confirmed by executing "ls" command.

$ mkdir [directory1], [directory2] ,[directory3]

๐Ÿ“mkdir -p

Using mkdir command, you can create a new directory in a specific location. However, if the parent directory doesnโ€™t exist, first you have to create the parent directory then youโ€™ll be able to create the desired directories in that specific location.

With the help of the -p option, we can create new directories along with the necessary parent directories using the "**mkdir -p" command by following the below process.

๐Ÿ“cat

It is used to read the data from a file and gives its content as output. It also helps us to create, view, and concatenate files.

$ cat >file1

this cat command is used to quickly create a file of a given filename and add some contents in that filename.

once the content is added just press "ctrl +d " to exit .

$ cat >>file1

this command is used to add content in that filename but you can't edit it. the lines will be continue added to last lines.

once the content is added just press "ctrl +d " to exit .

$ cat file1

To see the contents of the file.

$ cat file1 >file3

Copy the content from one file to another file.

$ cat file1 file2>file4

concatinate the contents of file1 and file2 into file4.

๐Ÿ“tac

tac is similar to cat command , it just display the contents in reverse order. It starts with last line.

๐Ÿ“touch

this command is used to create an empty file. similarly we can create multiple files by executing it once.

$ touch [filename1]

$ touch [filename1], [filename2], [filename3]

Note :- directories are displayed in "blue colour" while Files are displayed in "white colour" on the terminal.

๐Ÿ“echo

the echo command is used to displays defined text in terminal. just reflected the messages as simple as that.

$ echo "text"

$ echo "text" >[filename] --> if you want to add contents in file.

$ echo "text" >>[filename] --> if you want to add contents further in the same file.

$ echo >file --> if you want to delete the contents of file, rather want to empty the file.

๐Ÿ“Vi editor

A programmer text editor. It can be used to edit all kinds of plain text, it is specially useful for editing programs.

"Vi" is a standard whereas "nano" has to be available depending on the linux you use.

Note :-

:w --> to save

:wq --> To save and exit

:q --> To exit

:q! --> Force quit, no save

press "i" first to get into insert mood and then start typing the contents.

after writing the contents in editor . press "esc" from keyboard and then choose either of the options to get exit from editor, ":w", ":q!" ,":q" and ":wq".

๐Ÿ“Tree

The above tree like representation is by using tree command. The tree command actually shows the contents of the current directory and its subdirectories in a tree like fashion.

tree utility does not come pre installed in most of the Linux distributions. so we need to install it by using below command.

$ apt-get install tree

๐Ÿ“apt-get command

this command is used for handling Advanced Package Tool(APT) libaries in Linux. It lets you to fetch information from authenticated sources to manage , update, remove and install softwares.

Running apt-get commands requires you to use sudo or root privileges.

$ apt-get <command>

๐Ÿ“pwd

pwd command stands for "print working directory" used to display the current working directory.

$ pwd

When you want to know your current location, pwd will provide the absolute path.

๐Ÿ“cd

The cd command stands for "change directory", you can navigate through the file system. Use this command to change from one directory to specific directory.

$ cd [directory name]

here cd documents will take to documents directory, now the current working directory is "documents".

$ cd ..

To move back to parent directory level, use cd .. .

๐Ÿ“mv

The mv command stands for "move", enables you to rename or move files and directories from one location to another.

$ mv [source] [destination]

In above image we used mv command i.e. "mv sample folder" , to move sample directory to folder directory.

  • to rename file use command

$ mv <oldname> <newname>

In the above image we used mv command to rename the file. for example if you want to rename "folder" directory to "linux", just simply use the command, "mv folder linux".

๐Ÿ“cp

This command stands for "copy", enables you to copy files and directories. To copy a file use command

$ cp <sourcefile> < destinationfile>

๐Ÿ“clear

$ clear

this command is used to clear everything on your screen. Just type "clear" in your terminal.

๐Ÿ“rm

This command stands for "remove", used to remove/delete the files. Be cautious while using it, as deleted files cannot be recovered.

$ rm <filename>

๐Ÿ“rmdir/rm -d

This command is used to delete an empty directory.

$ rmdir <directory name>

$ rm -d <directory name>

$ rm -r <diectoryname>

This command is used to delete non empty directory, basically remove the directory and its contents recursively.

๐Ÿ“hostname

this command is used to know the system's hostname.

$ hostname

$ hostname -i --> this command is used to display the ip addresses of the machine.

๐Ÿ“df

$ df --> command will displays the free disk space available on file system with each file name's argument in kilobyte unit.

$ df -m --> command displays the amount of disk space available on the file system in megabyte unit.

$ df -h --> command displays the amount of disk space available on the file system in gigabyte unit.

"-h" is a flag which means human readable format.

๐Ÿ“du

$ du --> The du command allows a user to gain disk usage information.

$ du -h --> command shows disk usage statistics in human readable format.

๐Ÿ“head

this command display the first 10 lines of a file by default.

$ head <filename>

$ head -n4 <filename> --> display only the first four lines of the specific file.

๐Ÿ“tail

the tail by default print the last 10 lines of a file.

$ tail <filename>

$ tail -n5 <filename> --> this command will display the last 5 lines of the specific file.

๐Ÿ“grep

this grep command is a pattern matching command that we can use to search inside files and directories for specific text.

$ grep "text" <file>

search specified text in particular file.

$ grep "text" <file1> <file2> <file3>

search specified text in multiple files.

*$ grep "text"

suppose you need to search for a specified text, and you don't remember the files name where it exists. You can obviously write all the filenames present in the directory, but instead, you can simply use the โ€œ\โ€* .

๐Ÿ“sort

$ sort <filename> --> the sort command is used to display the contents in alphabetically order.

๐Ÿ“top

The top command used to display all the running processes and a dynamic real-time view of the current system. It sums up the resource utilization, from CPU to memory usage.

๐Ÿ“free

$ free

the free command displays the memory usage.

๐Ÿ“uptime

The uptime command does exactly as its name implies, it shows you how long itโ€™s been since the system was rebooted. It also outputs some other handy data โ€“ the current time, number of users logged in, and the CPU load average for the last 1, 5, and 15 minutes.

๐Ÿ“whereis

This command is used to know the exact location of any command.

$ whereis <command>

๐Ÿ“w

shows a list of currently logged-in user.

๐Ÿ“alias

We often have to use a single big command multiple times, in those cases, we create something called as "alias" for that command. "Alias" is like a shortcut command which will have same functionality instead of writing the whole command.

$ alias <name>= 'command'

๐Ÿ“find

The find command is used to find a particular file or directory. It also supports various options to find such as byname, by type, by date, and more.

The following symbols are used after the find command:

(.) : For current directory name

(/) : For root

$ find . -name <filename>

used to find the file from the current directory.

$ find / -type d -name "directory name"

used to find the directory from root.

๐Ÿ“cal

cal command is used to View Calendar in terminal.

$ cal

๐Ÿ“date

This command is frequently used to print the current day, date, time, time zone and year on the terminal window. By default, the time zone is the one on which the Linux system is configured.

$ date

๐Ÿ“history

with "history" command, the system will list up to previously executed commands, allowing user to reuse them without re-entering. it can be run only by the user having sudo privileges.

$ history

๐Ÿฆ‹Conclusion

Though we came to end of this article and I hope this article has helped you to understand about basic Linux commands.

Hope you like this article. So Stay Tuned for the next article .

Thank you. Happy learning!๐Ÿ“

๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง๐Ÿง

ย