UNIX COMMANDS

(Other Unix Commands)

The Other Unix Commands that will come handy are listed below:

1. ls

The ls command is used for listing all the contents of the directory in alphabetical order.

<machine>% ls
a    etc.tar    net     tmp
awk  export     nsmail  usr

Other options available with the ls command are :

<machine>% ls -t

This command causes the files to be listed in time order, the order in whoch they were last changed most recent first.

<machine>% ls -l
This option gives the "long" listing of the files that providing more information about each file.
-rw-r--r--    1 jumbo students 7102 Apr 25 00:55 a
drwxr-xr-x    3 jumbo students 4096 Oct 16 2001  startrek

From the above listing we can identify the file permissions.
- = permission is not set
r = read permission is set
w = write permission is set
x = execute permission is set
d = file is a directory

Starting from the left, these are the three sets:
a. user: These permissions control the access that the owner of the file has.
b. group: These permissions control the access that people in the file's group have.
c. others: These permissions control the access that people other than owner and those who are not in the group.

2. chmod
We can change the permiission for each of the three sets of access controls on a file by using the command chmod.
<machine>% chmod mode files

There are two ways in which we can change. One using numeric hex values. say
<machine>% ls -l lab1.script
-rw-r--r-- 1 user 817 May 17 11:08 lab1.script


To change the options for users
<machine>% chmod 744 lab1.script
<machine>% ls -l lab1.script
-rwxr--r-- 1 user817 May 17 11:08 lab1.script


The above command to set the user we use 744 - expanded as 0-111-100-100. So the x bit gets set.

To change the options for others.
<machine>% chmod 745 lab1.script
<machine>% ls -l lab1.script
-rwxr--r-x 1 user 817 May 17 11:08 lab1.script


In the above example ,we use 745 - expanded as 0-111-100-101. So the x bit in the others is set.

The other convention that is follwed is specifying the group by name. For example,

<machine>% ls -l lab1.script
-rw-r--r-- 1 user 817 May 17 11:08 lab1.script


To change the options for users
<machine>% chmod u+x lab1.script
<machine>% ls -l lab1.script
-rwxr--r-- 1 user817 May 17 11:08 lab1.script

The above command to set the user we use u+x meaning set the execute permission for the user.

2. man

The most important command that is very helpful in Unix is man. man, which is short for manual, gives you information about a command and the parameters it takes, including its syntax.

<machine>% man ls
Will result in the Manual page for the ls command. The manual page for the ls looks like the following.

User Commands ls(1)

NAME

ls - list contents of directory

SYNOPSIS
/usr/bin/ls [ -aAbcCdfFgilLmnopqrRstux1 ] [ __f__i__l__e ... ]


followed by the description and all the other details.

3. cat

This is one of the most flexible Unix commands. We can use to create, view and concatenate files. For our first example we create a three-item English-Spanish dictionary in a file called "dict."

<machine>% cat >star
this is just a test
for flying the star ship enterprise
no man has ever done before
<control-D>
<machine>%
<control-D> stands for "hold the control key down, then tap 'd' ". The symbol > tells the computer that what is typed is to be put into the file star. To view a file we use cat in a different way:

<machine>% cat star
this is just a test
for flying the star ship enterprise
no man has ever done before
<machine>%

If we wish to add text to an existing file we do this:

<machine>% cat >>star
we boldly go where no man has gone before
<control-D>
<machine>%
<machine>% cat star
this is just a test
for flying the star ship enterprise
no man has ever done before
we boldly go where no man has gone before
<machine>%

Now suppose that we have another file star_trek that looks like this:
<machine>% cat star_trek
check this out
<machine>%
Then we can join star and star_trek like this:

<machine>% cat star star_trek>star_wars
this is just a test
for flying the star ship enterprise
no man has ever done before
we boldly go where no man has gone before
check this out


4. grep

This command searches files for lines that match a pattern. For example, suppose that we have a file star whose contents are

this is just a test
for flying the star ship enterprise
no man has ever done before
we boldly go where no man has gone before


Then we can look up items in our file like this;

<machine>% grep for star
for flying the star ship enterprise
<machine>% grep flying star
for flying the star ship enterprise
<machine>% grep brown star
<machine>%


Notice that no output was returned by grep brown. This is because "brown" is not in our star file.
Grep can also be combined with other commands. For example, if one had a file of phone numbers named "ph", one entry per line, then the following command would give an alphabetical list of all persons whose name contains the string "Fred".

<machine>% grep Fred ph | sort
Alpha, Fred: 333-6565
Beta, Freddie: 656-0099
Frederickson, Molly: 444-0981
Gamma, Fred-George: 111-7676
Zeta, Frederick: 431-0987

The symbol | is called "pipe." It pipes the output of the grep command into the input of the sort command.

For more information on grep, use
<machine> man grep

PREVIOUS HOME NEXT