5 Useful Linux Command Tips for Beginners

Channel: Linux Commands Linux
Abstract: Explanation of commands and switches. man – Linux Man pages ls – Linux Listing Commands /bin – System Binary file Location shuf – Generate Random Perm

Are you making the most out of Linux? There are lots of helpful features which 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.

Here we are starting a new series, where we will be writing some tips and tricks and will try to yield as more as we can in small time.

1. Linux History Command

To audit the commands we’d run in the past, we use the history command. Here is a sample output of the history command.

# history

As obvious from the output, the history command does not output the time stamp with the log of the last executed commands.

To set the timestamp in bash history, run:

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

If you want to permanently enable timestamp in bash history, add the below line to ~/.bashrc.

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

and then, from the terminal run,

# source ~/.bashrc

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 the shell
  • .bashrc – is a shell script that BASH runs whenever it is started interactively.

2. Linux dd Command

The next gem in the list is – how to check Linux disk write speed. Well, the 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

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 comma-separated symbol list.
  • rm – Removes files and folder
  • -rf – (-r) removes directories and contents recursively and (-f) Forces the removal without prompt.
3. Linux du Command

How will you check the top six files that are eating out your space? A simple one-liner script made from the du command, which is primarily used for file space usage.

# du -hsx * | sort -rh | head -6

Explanation of commands and switches.

  • du – Estimate file space usage
  • -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) to compare the human-readable format.
  • head – output first n lines of file.
4. Linux stat Command

The next step involves statistics in the terminal of a file of every kind. We can output the statistics related to a file with the help of the stat (output file/fileSystem status) command.

# stat filename_ext  (viz., stat abc.pdf)

5. Linux Man Pages

Next and 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.

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

That’s all for now. If you know any such tips and tricks you may share them with us and we will post the same in your words on our reputed website.

Don’t Miss:

  • 10 Useful Commandline Tricks for Newbies – Part 2
  • 5 Useful Commands to Manage Linux File Types and System Time – Part 3

Ref From: tecmint

Related articles