Unix Reference

Tuesday, August 21, 2007

25 Unix Commands and their Usage.


host is a simple utility for performing DNS lookups. It is normally used to convert names to IP addresses and vice versa. When no arguments or options are given, host prints a short summary of its command line arguments and options.

$ host mail.yahoo.com
mail.yahoo.com is an alias for login.yahoo.com.
login.yahoo.com is an alias for login-global.yahoo8.akadns.net.
login-global.yahoo8.akadns.net is an alias for login.yahoo.akadns.net.
login.yahoo.akadns.net has address


dig (domain information groper) is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. Most DNS administrators use dig to troubleshoot DNS problems because of its flexibility, ease of use and clarity of output. Other lookup tools tend to have less functionality than dig.

$ dig mail.yahoo.com

; <<>> DiG 9.4.1-P1 <<>> mail.yahoo.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9867
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 8, ADDITIONAL: 8

;mail.yahoo.com. IN A

mail.yahoo.com. 195 IN CNAME login.yahoo.com.
login.yahoo.com. 65 IN CNAME login-global.yahoo8.akadns.net.
login-global.yahoo8.akadns.net. 122 IN CNAME login.yahoo.akadns.net.
login.yahoo.akadns.net. 51 IN A

akadns.net. 84671 IN NS zc.akadns.org.
akadns.net. 84671 IN NS zd.akadns.org.
akadns.net. 84671 IN NS eur1.akadns.net.
akadns.net. 84671 IN NS use3.akadns.net.
akadns.net. 84671 IN NS usw2.akadns.net.
akadns.net. 84671 IN NS asia9.akadns.net.
akadns.net. 84671 IN NS za.akadns.org.
akadns.net. 84671 IN NS zb.akadns.org.

za.akadns.org. 23366 IN A
zb.akadns.org. 23366 IN A
zc.akadns.org. 23366 IN A
zd.akadns.org. 23366 IN A
eur1.akadns.net. 17773 IN A
use3.akadns.net. 17773 IN A
usw2.akadns.net. 17773 IN A
asia9.akadns.net. 17773 IN A

;; Query time: 27 msec
;; WHEN: Mon Aug 20 13:34:17 2007
;; MSG SIZE rcvd: 421


The mkdir utility creates the directories named as operands, in the order specified, using mode ``rwxrwxrwx'' (0777) as modified by the current umask(2).

$ mkdir test
$ ls -l | grep test
drwxr-xr-x 2 owner group 512 Aug 20 13:35 test


The rm utility attempts to remove the non-directory type files specified on the command line. If the permissions of the file do not permit writ- ing, and the standard input device is a terminal, the user is prompted (on the standard error output) for confirmation.

Example (file):

$ rm test2
$ ls -l | grep test2

Example (dir):
what you get when you try to rm a dir is:

$ rm test
rm: test: is a directory

to get around this do:

$ rm -r test
$ ls -l | grep test


In the first synopsis form, the cp utility copies the contents of the source_file to the target_file. In the second synopsis form, the con- tents of each named source_file is copied to the destination target_directory. The names of the files themselves are not changed. If cp detects an attempt to copy a file to itself, the copy will fail.


$ cp test test2
$ ls -l | grep test
-rw-r--r-- 1 owner group 0 Aug 20 13:40 test
-rw-r--r-- 1 owner group 0 Aug 20 13:41 test2

copy a directory do:

$ cp -r test test2
$ ls -l | grep test
drwxr-xr-x 2 owner group 512 Aug 20 13:42 test
drwxr-xr-x 2 owner group 512 Aug 20 13:42 test2


grep searches the named input FILEs (or standard input if no files are named, or the file name - is given) for lines containing a match to the given PATTERN. By default, grep prints the matching lines.


$ ls
example test three
$ ls | grep th


For each operand that names a file of a type other than directory, ls displays its name as well as any requested, associated information. For each operand that names a file of type directory, ls displays the names of files contained within that directory, as well as any requested, asso- ciated information.


$ ls
example test three
$ ls -l
total 0
-rw-r--r-- 1 owner group 0 Aug 20 13:44 example
-rw-r--r-- 1 owner group 0 Aug 20 13:44 test
-rw-r--r-- 1 owner group 0 Aug 20 13:44 three


The startx script is a front end to xinit that provides a somewhat nicer user interface for running a single session of the X Window Sys- tem. It is often run with no arguments.

To use startx user most have .xinitrc file in there home directory. Examples of the file are:

$ cat ~/.xinitrc
exec fluxbox
(this will start fluxbox)
$ cat ~/.xinitrc
exec gnome-session
(this will start gnome)
$ cat ~/.xinitrc
exec startkde
(this will start kde)


nano is a small, free and friendly editor which aims to replace Pico, the default editor included in the non-free Pine package. Rather than just copying Pico's look and feel, nano also implements some missing (or disabled by default) features in Pico, such as "search and replace" and "go to line and column number".


$nano test

(will open test file for edit to exit type: Ctrl+X)


The pwd utility writes the absolute pathname of the current working directory to the standard output.


$ pwd


The cat utility reads files sequentially, writing them to the standard output. The file operands are processed in command-line order. If file is a single dash (`-') or absent, cat reads from the standard input. If file is a UNIX domain socket, cat connects to it and then reads it until EOF. This complements the UNIX domain binding capability available in inetd(8).


$ cat test
this is the contents of the file test


The man utility formats and displays the on-line manual pages. This ver- sion knows about the MANPATH and PAGER environment variables, so you can have your own set(s) of personal man pages and choose whatever program you like to display the formatted pages. If section is specified, man only looks in that section of the manual. You may also specify the order to search the sections for entries and which preprocessors to run on the source files via command line options or environment variables. If enabled by the system administrator, formatted man pages will also be compressed with the ``/usr/bin/gzip -c'' command to save space.


$ man find

Show information about the command find


The kill utility sends a signal to the processes specified by the pid op- erands.


$ kill 694

(694 is the id of the program running)


The locate program searches a database for all pathnames which match the specified pattern. The database is recomputed periodically (usually weekly or daily), and contains the pathnames of all files which are pub- licly accessible.


#locate Xorg.0.log

(you man need to run /usr/libexec/locate.updatedb to update locate listing)


The ifconfig utility is used to assign an address to a network interface and/or configure network interface parameters. The ifconfig utility must be used at boot time to define the network address of each interface present on a machine; it may also be used at a later time to redefine an interface's address or other operating parameters.

# ifconfig
em0: flags=8843 metric 0 mtu 1500
ether 00:16:41:16:28:2a
inet netmask 0xffffff00 broadcast
media: Ethernet autoselect (1000baseTX )
status: active
lo0: flags=8049 metric 0 mtu 16384
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
inet6 ::1 prefixlen 128
inet netmask 0xff000000


ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. It is intended to replace rlogin and rsh, and provide secure encrypted communications between two untrusted hosts over an insecure network. X11 connections and arbitrary TCP ports can also be forwarded over the secure channel.


#ssh localhost
Welcome to FreeBSD-World

(you wouldn't use local host you would use the computer ip or hostname you are connecting to)


The gzip program compresses and decompresses files using Lempel-Ziv cod- ing (LZ77). If no files are specified, gzip will compress from standard input, or decompress to standard output. When in compression mode, each file will be replaced with another file with the suffix, set by the -S suffix option, added, if possible. In decompression mode, each file will be checked for existence, as will the file with the suffix added.


$ gzip -9 test.tar

$ gzip -d test.tar.gz
$ ls | grep test.tar


bzip2 compresses files using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding. Compression is generally considerably better than that achieved by more conventional LZ77/LZ78-based compressors, and approaches the performance of the PPM family of statistical compressors.


$ bzip2 -9 test.tar
$ ls | grep test.tar
$ bzip2 -d test.tar.bz2
$ ls | grep test.tar


zip is a compression and file packaging utility for Unix, VMS, MSDOS, OS/2, Windows NT, Minix, Atari and Macintosh, Amiga and Acorn RISC OS.


$ zip test.zip test
adding: test/ (stored 0%)
$ ls | grep test
$ unzip test.zip
Archive: test.zip


tar creates and manipulates streaming archive files. This implementation can extract from tar, pax, cpio, zip, jar, ar, and ISO 9660 cdrom images and can create tar, pax, cpio, ar, and shar archives.


$ tar -cf t2.tar example test three
$ ls | grep t2
$ tar -xf t2.tar
(files are now extracted)


The mount utility calls the nmount(2) system call to prepare and graft a special device or the remote node (rhost:path) on to the file system tree at the point node. If either special or node are not provided, the appropriate information is taken from the fstab(5) file.


# cat /etc/fstab
# Device Mountpoint FStype Options Dump Pass#
/dev/ad4s1b none swap sw 0 0
/dev/ad4s1a / ufs rw 1 1
/dev/acd0 /cdrom cd9660 ro,noauto 0 0
# mount /cdrom
# ls /cdrom
4.1 TRANS.TBL etc
# umount /cdrom
# ls /cdrom

(/cdrom is already listed in the fstab if it was not I would have to do 'mount /dev/acd0 /cdrom')


The passwd utility changes the user's local, Kerberos, or NIS password. If the user is not the super-user, passwd first prompts for the current password and will not continue unless the correct password is entered.


$ passwd
Changing local password for username
Old Password:
New Password:
Retype New Password:


The ping utility uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway. ECHO_REQUEST datagrams (``pings'') have an IP and ICMP header, followed by a ``struct timeval'' and then an arbitrary number of ``pad'' bytes used to fill out the packet.


$ ping -c 5 www.yahoo.com
PING www.yahoo-ht3.akadns.net ( 56 data bytes
64 bytes from icmp_seq=0 ttl=47 time=48.814 ms
64 bytes from icmp_seq=1 ttl=47 time=32.916 ms
64 bytes from icmp_seq=2 ttl=47 time=32.361 ms
64 bytes from icmp_seq=3 ttl=47 time=33.912 ms
64 bytes from icmp_seq=4 ttl=47 time=33.846 ms

--- www.yahoo-ht3.akadns.net ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 32.361/36.370/48.814/6.249 ms


The tail utility displays the contents of file or, by default, its stan- dard input, to the standard output.

# tail /var/log/auth.log
Aug 19 20:38:05 laptop su: username to root on /dev/ttyv0
Aug 20 00:10:38 laptop login: login on ttyv0 as username
Aug 20 00:11:30 laptop su: username to root on /dev/ttyp0
Aug 20 00:56:32 laptop su: username to root on /dev/ttyp1
Aug 20 01:31:26 laptop su: username to root on /dev/ttyv0
Aug 20 10:25:58 laptop login: login on ttyv0 as username
Aug 20 10:26:21 laptop su: username to root on /dev/ttyp0
Aug 20 13:58:06 laptop su: username to root on /dev/ttyp1
Aug 20 14:18:23 laptop su: username to root on /dev/ttyp1
Aug 20 14:27:39 laptop su: useranme to root on /dev/ttyp1


Top displays the top processes on the system and periodically updates this information.


last pid: 5327; load averages: 0.00, 0.00, 0.00 up 0+04:05:41 14:30:28
44 processes: 1 running, 43 sleeping
CPU states: 0.2% user, 0.0% nice, 1.3% system, 0.0% interrupt, 98.5% idle
Mem: 198M Active, 608M Inact, 128M Wired, 26M Cache, 111M Buf, 31M Free
Swap: 1024M Total, 8K Used, 1024M Free

694 username 1 96 0 53004K 48212K select 1 4:23 0.10% Xorg
10306 username 1 96 0 7496K 4300K select 1 0:04 0.05% xterm

Friday, August 3, 2007

Getting Compiz Fusion up and running on Linux

I recently installed Compiz Fusion on my Ubuntu (Feisty Fawn) box.
While most of the installation went off without a hitch, the following guide did have one mistake. Other than that, I highly recommend following this bloke's advice.

Fosswire's Guide to Compiz-Fusion Installation on Ubuntu - Feisty Fawn

**The mistake occurs during the gpg key step. What you ACTUALLY want to do is this:

gpg –keyserver subkeys.pgp.net –recv-keys 81836EBF
gpg –export –armor 81836EBF | sudo apt-key add -
gpg –delete-key 81836EBF

Some other resources:
Compiz homepage
Wiki Info

Friday, July 20, 2007

Unix Reference

Some unix reference links for those inclined to get started.

I'll post some more articles as we progress.

Guide to grep