Saturday, September 10, 2011

To give a listing of hidden directories


ls -al | grep "^d" | grep "\." | tr -s " " | cut -d" " -f8

The "ls" lists all files. The first grep chooses the directories only and not files. Remove this to select hidden files too. The second grep selects hidden files - files tarting with a “dot”. It has to be escaped with \ otherwise it matches all characters. tr compresses extra spaces in the listing. “cut” selects the last column which is the hidden directory names. Without the tr compressing the delimiting spaces “cut” will mistake extra spaces to be new columns so the penultimate step is crucial.

No comments:

Print chess board in command line

The following bash one-liner will print a chess board in a terminal (the script works for the shells bash and ksh only) for (( i = 1; i ...