25 cool Linux terminal commands for Newbies

terminalSo you’ve just installed Ubuntu or PcLinuxOS and you’ve decided that all those GUI’s and point ‘n’ click applications are just like Windows. You’ve had Linux for a week or so and you’ve caught the Über-Geek-Hacker bug and have decided to see what you can do via the terminal like the real Geeks do.

How about connecting to a remote server, getting system information, making zip files?. What about listing directories, searching for files, moving files around, creating directories and deleting stuff? Cool huh?

Well, fire up your terminal and work your way from 25 to 1 and get into some real Geekness!

25) host

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

24) dig

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

23) mkdir

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

22) rm

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

21) cp

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

20) grep

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

19) ls

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

18) startx

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)

17) nano

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)


Vi is a screen oriented text editor. Ex is a line-oriented text edi- tor. Ex and vi are different interfaces to the same program, and it is possible to switch back and forth during an edit session. View is the equivalent of using the -R (read-only) option of vi.


$vi test

(Added on request)
to start typing on test use: i when your done type (esc)  to save type :wq! to not save use :q!

16) pwd

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


$ pwd

15) cat

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(Cool.


$ cat test
this is the contents of the file test

14) man

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

13) kill

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)

12) locate

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)

11) ifconfig

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

10) ssh

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)

9) gzip

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

8) bzip2

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

7) zip

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

6) tar

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)

5) mount

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’)

4) passwd

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:

3) ping

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

2) tail

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

1) top

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


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s