5 Useful Linux Command Tips for Beginners

[‘

n

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.

n

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.

n

1. Linux History Command

n

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

n

# historyrn

n

Linux history Command Usage

n

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

n

To set the timestamp in bash history, run:

n

# HISTTIMEFORMAT="%d/%m/%y %T "rn# historyrn

n

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

n

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

n

and then, from the terminal run,

n

# source ~/.bashrcrn

n

Explanation of commands and switches.

n

    n

  • history – GNU History Library
  • n

  • HISTIMEFORMAT – Environmental Variable
  • n

  • %d – Day
  • n

  • %m – Month
  • n

  • %y – Year
  • n

  • %T – Time Stamp
  • n

  • source – in short, send the contents of the file to the shell
  • n

  • .bashrc – is a shell script that BASH runs whenever it is started interactively.
  • n

n

history Command Logs

n

2. Linux dd Command

n

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

n

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

n

dd Command Example

n

Explanation of commands and switches.

n

    n

  • dd – Convert and Copy a file
  • n

  • if=/dev/zero – Read the file and not stdin
  • n

  • of=/tmp/output.img – Write to file and not stdout
  • n

  • bs – Read and Write maximum up to M bytes, at one-time
  • n

  • count – Copy N input block
  • n

  • conv – Convert the file as per comma-separated symbol list.
  • n

  • rm – Removes files and folder
  • n

  • -rf – (-r) removes directories and contents recursively and (-f) Forces the removal without prompt.
  • n

n

3. Linux du Command

n

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.

n

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

n

Check Disk Space Usage

n

Explanation of commands and switches.

n

    n

  • du – Estimate file space usage
  • n

  • -hsx – (-h) Human Readable Format, (-s) Summaries Output, (-x) One File Format, skip directories on other file formats.
  • n

  • sort – Sort text file lines
  • n

  • -rh – (-r) Reverse the result of the comparison, (-h) to compare the human-readable format.
  • n

  • head – output first n lines of file.
  • n

n

4. Linux stat Command

n

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 statxa0(output file/fileSystem status) command.

n

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

n

Check File Statistics

n

5. Linux Man Pages

n

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.

n

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.

n

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

n

Generate Random Man Pages

n

Explanation of commands and switches.

n

    n

  • man – Linux Man pages
  • n

  • ls – Linux Listing Commands
  • n

  • /bin – System Binary file Location
  • n

  • shuf – Generate Random Permutation
  • n

  • head – Output the first n line of the file.
  • n

n

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.

n

Don’t Miss:

n

n

‘]