Important Linux Commands With Syntax – Part 5

Expert-led Online Courses: Elevate Your Skills, Get ready for Future - Enroll Now!

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.

Important Linux Commands With Syntax - Part 5

Important Linux Commands With Syntax – Part 5

2. Important Linux Commands

Here, we are going to discuss a list of Important Linux Commands:

2.1. history

a. Usage:

$ history

History of all the work done on the terminal is stored on bash shell secretly.

b. Usage:

$ history –c

This command clears the history of commands from memory to show the list of command which have word cd from history

c. Usage:

$ history | grep cd

Technology is evolving rapidly!
Stay updated with DataFlair on WhatsApp!!

This command shows the commands from history which have word cd

d. Usage:

$ history | tail<or head>

This command shows last or first 10 commands in history

e. Usage:

$ ~/.bash_history

This command shows the path where the bash of history is residing in memory. It is a dotfile.

f. Usage:

$ echo > ~/. bash_history

This command will delete the history from the file.

2.2. clear

a. Usage:

$ clear

It will clear the command prompt but not erase everything. You can get the previous commands by scrolling upwards

2.3. logout,exit

a. Usage:

$ exit

This command will quit the current session.

2.4. sudo

a. Usage:

$ 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

2.5. su

a. Usage:

$ su <username>

This command switches the user in the terminal for e.g to change to the user <username>

2.6. wc

a. Usage:

$ cat file.txt | wc –l

This command returns the number of lines in the file

b. Usage:

$ cat file.txt | wc -w

This command returns the number of words in the file

c. Usage:

$ cat file.txt | wc -c

This command returns the number of characters in the file

2.7. sort

a. Usage:

$ 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.

b. Usage:

$ sort -n file.txt

This command is used for numeric sort

c. Usage:

$ sort -r file.txt

This command is used for reverse sort

d. Usage:

$ 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

e. Usage:

$ sort -u file.txt

This command uniquely sorts the file

2.8. date

a. Usage:

$ date

This command prints the date

b. Usage:

$ date "+%m/%y/%d"

This command prints the date is the specified format

c. Usage:

$ date "+%s"

This command prints the date in seconds

2.9. cal

a. Usage:

$ cal

This command prints the calendar of the current month

b. Usage:

$ cal –y

This command prints the calendar for the whole year

c. Usage:

$ cal 12 2009

This command prints the calendar for December 2009

2.10. gzip

a. Usage:

$ 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.

Reference

You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

courses

DataFlair Team

DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.

Leave a Reply

Your email address will not be published. Required fields are marked *