Magic Command Line Collection

From LinuxReviews
Jump to navigationJump to search
Konsole.svg

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.

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.