Important Linux Commands With Syntax – Part 5
1. Important Linux Commands
In this tutorial, you will learn important Linux commands that are required to become a Linux expert and would help you in learning Linux programming. These are some of the top Linux commands with syntax and examples. You have already seen basic commands in Linux commands Part 1 and Linux commands Part 2. Commands on Linux Part 3 and Linux commands for programming Part 4 covered some advanced commands. This linux tutorial covers commands like history, sudo, clear, su, wc, exit, sort, date, cal, gzip that will further help you in enhancing Linux knowledge.
So, let’s start Important Linux Commands.
2. Important Linux Commands
Here, we are going to discuss a list of Important Linux Commands:
History of all the work done on the terminal is stored on bash shell secretly.
$ history –c
This command clears the history of commands from memory to show the list of command which have word cd from history
$ history | grep cd
This command shows the commands from history which have word cd
$ history | tail<or head>
This command shows last or first 10 commands in history
This command shows the path where the bash of history is residing in memory. It is a dotfile.
$ echo > ~/. bash_history
This command will delete the history from the file.
It will clear the command prompt but not erase everything. You can get the previous commands by scrolling upwards
This command will quit the current session.
$ mkdir /directory-name # permission denied $ sudo mkdir /directory-name # permission granted $ sudo rmdir /directory-name # permission granted
sudo is a user which acts like a root, eg if u want to create any directory in root so you will be denied. But if you use sudo command, you will be asked for a password to create a directory in root. You can also get the permission to remove the directory
$ su <username>
This command switches the user in the terminal for e.g to change to the user <username>
$ cat file.txt | wc –l
This command returns the number of lines in the file
$ cat file.txt | wc -w
This command returns the number of words in the file
$ cat file.txt | wc -c
This command returns the number of characters in the file
$ sort filr.txt
This command sorts the file column-wise, it first sorts the first column and the corresponding value of other columns will be also the same.
$ sort -n file.txt
This command is used for numeric sort
$ sort -r file.txt
This command is used for reverse sort
$ sort -kn,m file.txt
eg:- $ sort -k2,2n file.txt
This command sorts file by column range; n is starting range, m is ending range and second n stands for numeric sort
$ sort -u file.txt
This command uniquely sorts the file
This command prints the date
$ date "+%m/%y/%d"
This command prints the date is the specified format
$ date "+%s"
This command prints the date in seconds
This command prints the calendar of the current month
$ cal –y
This command prints the calendar for the whole year
$ cal 12 2009
This command prints the calendar for December 2009
$ gzip file
Using this command, original file will be compressed in zip format and it will disappear leaving behind .gz
So, this was all about Important Linux Commands with syntax. Hope you like our explanation.
Furthermore, if you have any query, feel free to ask in the comment box.