Linux tools notes

Following along from linuxjourney.com

Use

info ls

to get more information about a tool. It is often better than man pages.

File redirection

ls /fake/directory 2> peanuts.txt

to redirect stderr

To redirect both stdout and stderr:

ls /loo /var/log > /dev/null 2>&1

stderr file descriptor is 2, and the above reads send stderr output to wherever file descriptor 1 (stdout) is located.

Tee

To output to multiple file descriptors use "tee"

ls | tee peanuts.txt

This would output ls to stdout AND peanuts.txt

Cut

This command uses pattern flags to extract text the way you want it from a corpus.

echo 'The quick brown; fox jumps over the lazy dog' > sample.txt

To extract contents by character number:

cut -c 5 sample.txt

This will extract the 2nd field:

cut -f 2 sample.txt

To extract contents by field (default delimiter is tab): cut -f 1 -d ";" sample.txt

Paste

This command is like cat, but it facilitates merging text from multiple lines. Default delimiter for merge is tab sample2.txt: sample2.txt The quick brown fox

paste -s sample2.txt

paste -d ' ' -s sample2.txt

Comments

Popular Posts