Simple stuff for Linux

Man(ual) pages

To get help on a particular command:
$ man
eg. man printf
Man stands for manual. It is split in to sections.

Section # Topic
1 Commands available to users
2 Unix and C system calls
3 C library routines for C programs
4 Special file names
5 File formats and conventions for files used by Unix
6 Games
7 Word processing packages
8 System administration commands and procedures

In the example above it pulls the printf man page from the shell which is most likely not the one wanted.
So run:
$ man 3 printf
to get the C library printf routine
To quit from a man page, press "q"
To search a man page, type "/"

To search the man pages
$ apropos


Shell shortcuts


^D - logout
cd - - return to the previous directory you were in
!$ - use the last arguement from the previous command
(ctrl)c - cancel a command


Unix utilities

To search through all the .h files in the projects directory and directories below for the definition of "Cont_"
find ~/projects -name "*.h" -exec grep -H "typedef struct Cont_" {} \; -print

Use awk to print one column from a text file.
eg: Given a file, ctr.log, with lines like
ctr key: 1983224, iso: 2210, ctr no: TTNU1519344 , etd: 1215752400
ctr key: 1983225, iso: 22G1, ctr no: FSCU3621588 , etd: 1215752400

$ grep "iso: 22G1" ctr.log | awk ' { print $8 } ' | sort | uniq
This will find all of the containers with the iso 22G1 in the ctr.log file; print the 8th column, the container number; sort them and remove any duplicates.

$ grep "iso: 22G1" ctr.log | wc -l
This will count how many 22G1 containers there are by counting the number of lines.