Program No: 1: Aim:-Unix Overview and Its Basic Commands
Program No: 1: Aim:-Unix Overview and Its Basic Commands
12013029
12013029
12013029
$ls
Here is the sample output of the above command:
$ls
bin
ch07
hosts lib
hw1
ch07.bak hw2
docs
hw3
res.03
pub
test_results
res.01 users
res.02 work
The command ls supports the -l option which would help you to get more
information about the listed files:
$ls -l
total1962188
drwxrwxr-x 2amroodamrood4096Dec2509:59uml
-rw-rw-r--1amroodamrood5341Dec2508:38 uml.jpg
drwxr-xr-x 2amroodamrood4096Feb152006univ
drwxr-xr-x 2 root root4096Dec92007urlspedia
Here is the information about all the listed columns:
1.
First Column: represents file type and permission given on the file. Below is
the description
of all type of files.
2.
Second Column: represents the number of memory blocks taken by the file or
directory.
3.
Third Column: represents owner of the file. This is the Unix user who created
this file.
4.
Fourth Column: represents group of the owner. Every Unix user would have
an associated group.
12013029
5.
6.
7.
Description
Meta Characters:
Meta
characters
have
special
meaning
in
Unix.
For
example * and ? aremetacharacters. We use * to match 0 or more characters, a
question mark ? matches with single character.
For Example:
$ls ch*.doc
Displays all the files whose name start with ch and ends with .doc:
ch01-1.doc ch010.doc ch02.doc ch03-2.doc
12013029
..profile
docs
lib
...rhosts
hosts pub
test_results
users
.emacs bin
hw1
res.01 work
.exrc
hw2
res.02
ch07
.kshrc ch07.bak
hw3
res.03
12013029
Note: I have put stars (*) just to show you the location where you would need to
enter the current and new passwords otherwise at your system, it would not show
you any character when you would type.
Creating Files:
You can use vi editor to create ordinary files on any Unix system. You simply need to
give following command:
$ vi filename
Above command would open a file with the given filename. You would need to press
key i to come into edit mode. Once you are in edit mode you can start writing your
content in the file as below:
Thisisunix file....I created it for the first time.....
I'm going to save this content in this file.
Once you are done, do the following steps:
1.
2.
3.
Third Column: represents total number of bytes in the file. This is actual size
of the file.
4.
12013029
12013029
$cd $
Absolute/Relative Pathnames:
Directories are arranged in a hierarchy with root (/) at the top. The position of any
file within the hierarchy is described by its pathname. Elements of a pathname are
separated by a /. A pathname is absolute if it is described in relation to root, so
absolute pathnames always begin with a /.
These are some example of absolute filenames.
/etc/passwd
/users/sjones/chem/notes
/dev/rdsk/Os3
A pathname can also be relative to your current working directory. Relative
pathnames never begin with /. Relative to user amrood' home directory, some
pathnames might look like this:
chem/notes
personal/res
To determine where you are within the filesystem hierarchy at any time, enter the
command pwd to print the current working directory:
$pwd
/user0/home/amrood
$
Listing Directories:
To list the files in a directory you can use the following syntax:
$ls dirname
Following is the example to list all the files contained in /usr/local directory:
12013029
$ls /usr/local
X11
bin
gimp
jikessbin
ace
doc
include lib
share
atalketc
info
man
ami
Creating Directories:
Directories are created by the following command:
$mkdirdirname
Here, directory is the absolute or relative pathname of the directory you want to
create. For example, the command:
$mkdirmydir
$
Creates the directory mydir in the current directory. Here is another example:
$mkdir/tmp/test-dir
$
This command creates the directory test-dir in the /tmp directory.
The mkdir command produces no output if it successfully creates the requested
directory. If you give more than one directory on the command line, mkdir creates
each of the directories. For example:
$mkdir docs pub
$
Creates the directories docs and pub under the current directory.
12013029
Sometimes when you want to create a directory, its parent directory or directories
might not exist. In this case, mkdir issues an error message as follows:
$mkdir/tmp/amrood/test
mkdir:Failed to make directory "/tmp/amrood/test";
No such file or directory
$
In such cases, you can specify the -p option to the mkdir command. It creates all the
necessary directories for you. For example:
$mkdir-p /tmp/amrood/test
$
Above command creates all the required parent directories.
Removing Directories:
Directories can be deleted using the rmdir command as follows:
$rmdirdirname
$
Note: To remove a directory make sure it is empty which means there should not be
any file or sub-directory inside this directory.
You can create multiple directories at a time as follows:
$rmdir dirname1 dirname2 dirname3
$
Above command removes the directories dirname1, dirname2, and dirname2 if they
are empty. The rmdir command produces no output if it is successful.
Changing Directories:
You can use the cd command to do more than change to a home directory: You can
use it to change to any directory by specifying a valid absolute or relative path. The
syntax is as follows:
12013029
$cd dirname
$
Here, dirname is the name of the directory that you want to change to. For example,
the command:
$cd /usr/local/bin
$
Changes to the directory /usr/local/bin. From this directory you can cd to the
directory /usr/home/amrood using the following relative path:
$cd ../../home/amrood
$
PROGRAM NO:-2
AIM:-WRITE A PROGRAM OF CALCULATOR.
echo enter two numbers
read a b
12013029
PROGRAM NO:-3
AIM:-WRITE A PROGRAM USING CASE STRUCTURE.
while [ true ]
12013029
do
echo Enter choice
echo "1.Check present working directory"
echo "2.check date"
echo "3.Calender"
echo "4.Current process"
echo "5. exit"
read a
case "$a" in
1) pwd ;;
2) date ;;
3) cal ;;
4) ps -f ;;
5) exit ;;
*) echo Invalid option
esac
done
PROGRAM NO:-4
AIM:-WRITE A PROGRAM TO FIND NUMBER IS EVEN OR ODD.
echo enter the number
12013029
read a
if [ `expr $a % 2` -eq 0 ]
then
echo number is even number
else
echo number is odd number
fi
PROGRAM NO:-5
AIM:-WRITE A PROGRAM TO FIND FACTORIAL OF A NUMBER.
12013029
PROGRAM NO:-6
12013029
PROGRAM NO:-7
12013029
PROGRAM NO:-8
12013029
PROGRAM NO:-9
12013029
PROGRAM NO:-10
12013029
PROGRAM NO:-11
12013029
PROGRAM NO:-12
12013029
PROGRAM NO:-13
12013029
12013029