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.
- history – GNU History Library
- HISTIMEFORMAT – Environmental Variable
- %d – Day
- %m – Month
- %y – Year
- %T – Time Stamp
- source – in short, send the contents of the file to shell
- .bashrc – is a shell script that BASH runs whenever it is started interactively.
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.
- dd – Convert and Copy a file
- if=/dev/zero – Read the file and not stdin
- of=/tmp/output.img – Write to file and not stdout
- bs – Read and Write maximum up to M bytes, at one-time
- count – Copy N input block
- conv – Convert the file as per the comma-separated symbol list.
- rm – Removes files and folder
- -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.
- du – Estimate file space usages
- -hsx – (-h) Human Readable Format, (-s) Summaries Output, (-x) One File Format, skip directories on other file formats.
- sort – Sort text file lines
- -rh – (-r) Reverse the result of the comparison, (-h) for compare human-readable format.
- head – output first n lines of file.
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)