Magic Command Line Collection

From LinuxReviews
Jump to navigationJump to search

The command line can be used to do a whole lot of interesting things. Many of them can be done in a variety of ways. Here is a collection of random useful command line commands in no particular order.

Please add to this collection.

Fun commands that don't modify your system

Some of these require additional packages; if you get an output such as command not found: neofetch, do sudo apt install neofetch (or the equivalent) on your distribution.

What are your most used commands?

history | awk '{print $2}' | sort | uniq -c | sort -nr | head -n 10

Show off your pimped system - With STYLE!

neofetch | lolcat

Like cows?

echo is cool | xcowsay

List the name and contents of files in a directory

These commands can be useful for browsing files in the Linux /sys/ folder:

fgrep -r '' /sys/devices/system/cpu/vulnerabilities

You can get a identical-looking list using grep -H '':

grep -H '' /sys/devices/system/cpu/vulnerabilities/*

You can also get a list of files followed by their contents with awk:

awk 'FNR==1{print "==>"FILENAME"\n"}1' /sys/devices/system/cpu/vulnerabilities/*

It can also be done by creating a function that prints a filename followed by its contents and running it:

header-cat () { local f; for f in "$@" ; do printf '=== %s ===\n' "$f"; cat "$f"; done; }

header-cat /sys/devices/system/cpu/vulnerabilities/*

Having this function in .bashrc can be quite handy.

You can get a similar output from the less and possibly least elegant:

for f in /sys/devices/system/cpu/vulnerabilities/*;do echo $f;cat $f;done

Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.