1. To audit the commands we’d run in past, we use history command. Here is a sample output of history command.
# historyObvious from output, the history command do not output the time stamp with the log of last executed commands. Any solution for this? Yeah! Run the below command.
# HISTTIMEFORMAT="%d/%m/%y %T " # historyIf you want to permanently append this change, add the below line to
~/.bashrc
.export HISTTIMEFORMAT="%d/%m/%y %T "and then, from terminal run,
# source ~/.bashrcExplanation 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 file to shell
- .bashrc – is a shell script that BASH runs whenever it is started interactively.
# dd if=/dev/zero of=/tmp/output.img bs=8k count=256k conv=fdatasync; rm -rf /tmp/output.imgExplanation 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 upto 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) Force the removal without prompt.
# du -hsx * | sort -rh | head -6Explanation 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 format.
- sort – Sort text file lines
- -rh – (-r) Reverse the result of comparison, (-h) for compare human readable format.
- head – output first n lines of file.
# stat filename_ext (viz., stat abc.pdf)5. The next and last but not the 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 first n line of file.