Advance

5 Interesting Command Line Tips and Tricks in Linux

5 Interesting Command Line Tips and Tricks in Linux – Part 1
1
(1)

A Linux system administrator needs to know some Linux tricks. In this article, you will learn 5 Interesting Command Line Tips and Tricks in Linux.

 

While you are making most out of the Linux, there are lots of helpful features that appear to be Tips and Tricks for many Linux Users. Sometimes Tips and Tricks become the need. It helps you get productive with the same set of commands yet with enhanced functionality.

 

5 Interesting Command Line Tips and Tricks in Linux

In this guide, we are starting a new series, where we will be writing some tips and tricks and will try to yield as much as we can in a small-time. So join us to learn 5 Interesting Command Line Tips and Tricks in Linux – Part 1.

1- To audit the commands we’d run in the past, we use history command.

history

As the history command does not output the time stamp with the log of last executed commands. you can solve it by running the below command.

HISTTIMEFORMAT="%d/%m/%y %T " history

also, if you want to permanently append this change, add the below line to ~/.bashrc.

export HISTTIMEFORMAT="%d/%m/%y %T " 

Now,  from the terminal run:

source ~/.bashrc 

Have a look at the explanation of commands and switches.

  1. history – GNU History Library
  2. HISTIMEFORMAT – Environmental Variable
  3. %d – Day
  4. %m – Month
  5. %y – Year
  6. %T – Time Stamp
  7. source – in short, send the contents of the file to shell
  8. .bashrc – is a shell script that BASH runs whenever it is started interactively.

Recommended Article: How To Install And Run SonarQube On Centos 7

2- The next gem in the list is – how to check disk write speed? Well, a one-liner dd command script serves the purpose.

dd if=/dev/zero of=/tmp/output.img bs=8k count=256k conv=fdatasync; rm -rf /tmp/output.img 

 

5 Interesting Command Line Tips and Tricks in Linux – Part 1

Again, here is the explanation of commands and switches.

  1. dd – Convert and Copy a file
  2. if=/dev/zero – Read the file and not stdin
  3. of=/tmp/output.img – Write to file and not stdout
  4. bs – Read and Write maximum up to M bytes, at one-time
  5. count – Copy N input block
  6. conv – Convert the file as per the comma-separated symbol list.
  7. rm – Removes files and folder
  8. -rf – (-r) removes directories and contents recursively and (-f) Force the removal without prompt.

3- If you wish to check the top six files that are eating out your space, you can use a simple one-liner script made from du command, which is primarily used as file space usages.du -hsx * | sort -rh | head -6

 

And to see the explanation of commands and switches.

  1. du – Estimate file space usages
  2. -hsx – (-h) Human Readable Format, (-s) Summaries Output, (-x) One File Format, skip directories on other file formats.
  3. sort – Sort text file lines
  4. -rh – (-r) Reverse the result of the comparison, (-h) for compare human-readable format.
  5. head – output first n lines of file.

 

buy vps with cryptocurrency

 

4- It is time to see the statistics in the terminal of a file of every kind. We can output the statistics related to a file with the help of stat (output file/fileSystem status) command.

stat filename_ext  (viz., stat abc.pdf) 

 

5- Finally, the last but not least, this one line script is for those, who are newbies. if you are an experienced user you probably don’t need it, unless you want some fun out of it. Well, newbies are Linux-command-line phobic and the below one-liner will generate random man pages. The benefit is as a newbie you always get something to learn and never get bored.

man $(ls /bin | shuf | head -1) 

Explanation of commands and switches.

  1. man – Linux Man pages
  2. ls – Linux Listing Commands
  3. /bin – System Binary file Location
  4. shuf – Generate Random Permutation
  5. head – Output first n line of the file.

 

Good job! By touching this point, you have successfully learned 5 Interesting Command Line Tips and Tricks in Linux.

Dear user, we wish this tutorial would be helpful for you, to ask any question or review the conversation of our users about this article, please visit Ask page. Also to improve your knowledge, there are so many useful tutorials ready for Eldernode training.

How useful was this post?

Click on a star to rate it!

Average rating 1 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

View More Posts
Tom Veitch
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

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

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day