Advanced Unix Commands

Take a look at some of these beginning Unix commands before you continue. Once you're ready, let's have some fun...


Before I start here are a few nifty things you will not normally find in a manual:

  • Hitting the tab key after typing the first few letters of a filename will complete the filename if it exists in the directory.

  • The up and down arrow key will scroll through commands you already typed and allow you to use them again.


    Commands to get help

    This is the most important command you will learn in Unix - how to get help!

    man [command name] - gets the help page for a command

    man -k [keyword] - finds the commands that pertain to the keyword


    Commands to view files

    more [filename] - views a file

    less [filename] - views a file


    Commands to find files

    find [directory] -name '[string]' -print - finds a file in a given directory tree

    whereis [filename] - finds the location of a program

    grep -i [pattern] [directory]/* - searches a directory of files (mail/* is all of the subdirectories and files under mail) for a given string of text [pattern]


    Piping Commands

    [command] | [command] - pipes one command to another

    [command] > [filename] - sends output of a command to a file


    Internet address commands

    ping [server name] - checks to see if a machine is on the net

    dig [server name] - finds the IP address for a server whose name you know

    whois [name] - finds the IP addresses for servers whose name is listed


    File Permissions

    If you type ls -al you will get a listing of the files in a given directory with their permissions. This will look something like:

    drwxr-xr-x  2 wertheim      512 May  5 10:35 .
    drwxr-xr-x  4 wertheim     1024 May  5 10:04 ..
    -rw-r--r--  1 wertheim     2110 May  5 10:05 archive.html
    -rw-r--r--  1 wertheim      262 May  5 10:35 permissions.html
    -rw-r--r--  1 wertheim      439 May  5 10:31 stuff.html
    -rw-r--r--  1 wertheim      414 May  5 10:24 unix.html
    
    Each file has 10 bits of information associated with it:

    -rwxrwxrwx

    The first tells whether it is a file or directory, the next group of three tell the permissions on the file for the individual who owns the file, the next three tell the permissions for the group, and the final three tell the permissions for the entire world. The permissions available are read, write, and execute. For example, the file unix.html above was last edited on May 5 at 10:24. The individual who created it has permission to read and write to it. The group and the world may read the file. By group, this means any group of individuals that is defined on your server by the system administrator.

    The owner of the file may change permissions using the command chmod. For example to make the file unix.html readable and writable to everyone in the world the command would be:

    chmod a+rw unix.html

    U represents the individuals permissions, G represents the groups permissions, and A stands for the worlds permissions.

    You can also change permissions using a number system. Here is how it works.

    	user		group		all
    _	_ _ _		_ _ _		_ _ _
    _	r w x		r w x		r w x
    _	4 2 1 		4 2 1		4 2 1
    
    
    To change permissions using this method you sum the numbers for each permission. Therefore to make unix.html readable to everyone and writable by the user and the group the command would be:

    chmod 664 unix.html

    The first 6 comes from 4+2 (r+w), the second 6 comes from 4+2 (r+w) and the 4 comes from 4 (r).


    Multitasking

    Control-Z - suspends a job

    ps - shows processes by their PID

    jobs - shows the active jobs and their ID #s

    fg %[job #] - returns to a specific job number

    kill [PID] - kills a process using its PID


    Disk Usage

    df - shows system hard drive partitions and use

    du - shows your personal disk usage


    Miscellaneous Neat Stuff

    date - date and time is returned

    wc [filename] - provides the number of lines, words and characters in a file