1. The basic output shows the process ID (PID) of the programs, the terminal (TTY) that they are
running from, and the CPU time the process has used.
$ ps
PID TTY TIME CMD
3081 pts/0 00:00:00 bash
3209 pts/0 00:00:00 ps
2. see everything running on the system
$ ps -ef
3. The kill command allows you to send signals to processes based on their process ID (PID).
$ kill 3940
4. see how much disk space is available on an individual device. The df command allows us to easily see what’s happening on all of the mounted disks
$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 6813412 2889540 3577760 45% /
none 1024880 212 1024668 1% /dev
none 1030476 644 1029832 1% /dev/shm
none 1030476 96 1030380 1% /var/run
none 1030476 0 1030476 0% /var/lock
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 6.5G 2.8G 3.5G 45% /
none 1001M 212K 1001M 1% /dev
none 1007M 644K 1006M 1% /dev/shm
none 1007M 96K 1007M 1% /var/run
none 1007M 0 1007M 0% /var/lock
5. The du command shows the disk usage for a specific directory (by default, the current directory). This is a quick way to determine if you have any obvious disk hogs on the system.
t$ du
8 ./testfold
116 .
$ du -c
8 ./testfold
116 .
116 total
$ du -h
8.0K ./testfold
116K .
$ du -s
116 .
6. sort
$ cat test8
8
93
5
6
28
$ sort test8
28
5
6
8
93
$ sort -n test8
5
6
8
28
93
$ sort -M file3
The -n parameter is great for sorting numerical outputs, such as the output of the du command:
$ du -sh * | sort -nr
7.
$ cat > file1
one
two
three
four
five
$ grep three file1
three
$ grep t file1
two
three
$ grep -v t file1
one
four
five
$ grep -n t file1
2:two
3:three
$ grep -c t file1
2
$ grep -e t -e f file1
two
three
four
five
$ grep [tf] file1
two
three
four
five
8. Compressing data
■ bzip2 for compressing files
■ bzcat for displaying the contents of compressed text files
■ bunzip2 for uncompressing compressed .bz2 files
■ bzip2recover for attempting to recover damaged compressed files
$ ls -l
total 4
-rw-r--r-- 1 linna linna 9 2011-02-24 02:20 test1
$ bzip2 test1
$ ls -l
total 4
-rw-r--r-- 1 linna linna 45 2011-02-24 02:20 test1.bz2
$ more test1.bz2
BZh91AY&SYøG²
$ bzcat test1.bz2
test
test
$ bunzip2 test1.bz2
$ ls -l
total 4
-rw-r--r-- 1 linna linna 9 2011-02-24 02:20 test1
$ more test1
test
test
9. The gzip utility
■ gzip for compressing files
■ gzcat for displaying the contents of compressed text files
■ gunzip for uncompressing files
10. Archiving data
By far the most popular archiving tool used in Unix and Linux is the tar command.