Вы находитесь на странице: 1из 26

Enrollment No: [enter your number] Practical - 1

1. General- Purpose Utilities:


1.1 Cal : Print calendar
 Format: cal[ [month] year]
 Description: cal displays a calendar for the specified year on standard
output. If month is also specified, a calendar for just that month is
displayed. If year is not specified, a calendar for the present month is
displayed. A year starts on Jan 1. Year can be between 1 and 9999, month
can be between 1 and 12.

1.2 Date : set/list/convert dates


 Format: date [options][+format | date | file…]
 Description: date sets the current date and time (with appropriate
privilege), lists the current date or file dates, or converts dates.

OS Page 1
Enrollment No: [enter your number] Practical - 1

1.3 echo : Displaying a message

1.4 printf : An alternative to echo


Description: printf command in its simplest form can be used the same way as
echo command. But printf also used formatted strings in the same way the printf
function in the c language.

OS Page 2
Enrollment No: [enter your number] Practical - 1

1.5 bc – the calculator


Description: bc is a language that supports arbitrary precision on number with
interactive execution of statements. There are some similarities in the syntax to the C
programming language. A standard math library is available by command line option.
If requested, the math library is defined before processing any files. bc starts by
processing code from all the files listed on the command line in the order listed. After
all files have been processed, be reads from the standard input. All code is executed as
it is read. (If a file contain a command to halt the processor, bc will never read from
the standard input.)

OS Page 3
Enrollment No: [enter your number] Practical - 1

1.6 script : Recording your session


Description : command helps in recording your session in a file. We can later view
this file. If we are doing some important work and wish to keep a log of all your
activities, then we should invoke this command immediately after log in:

1.7 passwd : Changing your password


Format: passwd [options] [user_name]
Discription: passwd changes the password or shell associ-ated with the user given by
name or the current user if name is omitted. By default, the current password is prompted
for, and a new once must be entered and confirmed passwd command can also be used to
change the home directory where the path stands for the home directory.

OS Page 4
Enrollment No: [enter your number] Practical - 1

1.8 who : Display who is on the system


Format: who [options] [am I]

Description: who displays various piece of information about logged in users to


standard output. Who lists the user’s name, terminal line, login time, and remote host
name, if applicable, for each logged in user it reports. The second form, who am I is
equivalent to who –m.

1.9 uname : Identify the current system


Format: uname [options]

Description: By default uname writes the operating system name to standard output.
When options are specified, one or more system characteristics are written to standard

OS Page 5
Enrollment No: [enter your number] Practical - 1

output. When more than one options is specified the output is in the order specified by the
-1 option below.

1.10 tty : Knowing your terminal


Description: tty writes the name of the terminal that is connected to standard input
onto standard output. Command is very simple and needs no arguments.

1.11 stty : Displaying and setting terminal characteristics


Description: stty sets certain terminal I/O modes for device that is the current standard
input; without arguments, it writes the settings of certain modes to standard output.

OS Page 6
Enrollment No: [enter your number] Practical - 1

2. The File-System:

2.1 mkdir : Making directories


Format: mkdir [options] directory …

Description: the command is followed by the name of the directories to be created.

OS Page 7
Enrollment No: [enter your number] Practical - 1

2.2 rmdir : Removing directories


Format: rmdir [options] directory.

Description: removes empty directories.

rmdir command: Click Here..

2.3 pwd : Checking your current directory


Description: at a time of logging in user is the specific directory in the file system.
You can move around from one directory to another, but any positive time, you are
located in only one directory. This directory is known as your current directory. Pwd
command tells your current directory.

OS Page 8
Enrollment No: [enter your number] Practical - 1

2.4 cd : Changing the current directory


Format: cd [options] [directory] Cd [options] old new

Decription: you can move around in the file system the cd command. When used with
argument, it changes the current directory to the directory specified us as the argument.

2.5 ls : Listing directory contents


Format: ls [options] [files…]

Description: for each directory argument ls lists the Contents; for each file argument
the name and requested Information are listed. The current directory is listed if no file
argument appear. The listing is sorted by file name by default, except that file arguments
are listed before directory.

OS Page 9
Enrollment No: [enter your number] Practical - 1

Options :
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file
-b, --escape print octal escapes for nongraphic characters
--block-size=SIZE use SIZE-byte blocks
-B, --ignore-backups do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last
modification of file status information)
with -l: show ctime and sort by name

OS Page 10
Enrollment No: [enter your number] Practical - 1

otherwise: sort by ctime


-C list entries by columns
--color[=WHEN] control whether color is used to distinguish file
types. WHEN may be `never', `always', or
`auto'
-d, --directory list directory entries instead of contents,
and do not dereference symbolic links
-D, --dired generate output designed for Emacs' dired mode
-f do not sort, enable -aU, disable -lst

3. Handling Ordinary Files :


3.1 cat : Displaying and creating files
Description: we can use cat command to create a file.

OS Page 11
Enrollment No: [enter your number] Practical - 1

3.2 cp : Copying a file


Format: cp [options] source destination cp [options] file … directory

Description: command copies a file or group of files. It creates an exact image of the
file on the disk with a different name. The syntax requires at least two file names. When
both are ordinary files first is copied to the s

OS Page 12
Enrollment No: [enter your number] Practical - 1

3.3 rm : Deleting files


Format: rm [options] file …
Description: files can deleted with rm. It can delete more than one file with as ingle
invocation. For deleting a single file we have to use rm command with filename to be
deleted.

OS Page 13
Enrollment No: [enter your number] Practical - 1

3.4 mv : Renaming file


Description: mv has two functions:
 renames a file
 it moves a group of files to a different directory.
 mv doesn’t create a copy of a file, it merely renames it.
No additional space is consumed on disk during renaming.
Example: we rename file os to os1 and then if we try to read file os we will get error
message as it is renamed to os1 there is no existence of file named os.
 If the destination file doesn’t exist it will be created. mv can also be used to
rename a directory.
 A group of files can also be moved to a directory.
 mv doesn’t prompt for overwriting destination file if it exists.

3.5 more : Paging output


Description: more commands displays its output a page at a time.
Example: we have a big file contains thousands of records and we want to read that
file then we should use more command.
 See example of employees
 Press q for exit from more command.

OS Page 14
Enrollment No: [enter your number] Practical - 1

3.6 file : Knowing the file types


Format: file [options] [file name]
Description: File command is used to determine file type and it can also be used with
one or more filenames as arguments.

Example: check the type of file os1

 We can use * to signify all files.


 File command identifies the file type by examining the magical number which is
unique for each and every files.
 File Command recognize text files ,dos exe ,PDF documents and even empty
files.

3.7 wc: Counting lines , words, and characters


Format : wc [options] [file name]
Description: wc command count lines,words and characters depending on options
used. It takes one or more filename as argument and displays fourcolumnar output.
Example:

OS Page 15
Enrollment No: [enter your number] Practical - 1

OPTIONS:
(1)-L, --lines : count the lines.
(2)-w, --words : count the words.
(3)-c, --bytes/chars : count the bytes.

3.8 od: Displaying data in octal


Format: od [options] [file name]
Description: Displaying data in octal

3.9 cmp: Comparing two files


Format: cmp [options] file1 file2
Description:Sometimes it is necessary to know which files are identical so one of them
can be deleted. Cmp command is one of the command for the comparing two files in
unix system.
 Cmp command compare two files byte by byte.

OS Page 16
Enrollment No: [enter your number] Practical - 1

3.10 comm: To find common


Description:comm compare two sorted files line by line. With no options and produce
three column output.
 lines unique to FILE1
 lines unique to FILE2
 lines that appear in both files.

OS Page 17
Enrollment No: [enter your number] Practical - 1

3.11 diff: Find difference between two files


Format: [options] file1 file2
Description: diff command use for compare contents of two files. The diff command
displays the changes made per line for text and binary files.

4. Basic file attributes:


4.1 chmod: Changing file permissions
Format: chmod [options] mode file

Description: chmod command changes the access mode of one file or


multiple files. It can only run by user and super user.

OS Page 18
Enrollment No: [enter your number] Practical - 1

Permissions
u - User who owns the file.
g - Group that owns the file.
o - Other.
a - All.
r - Read the file.
w - Write or edit the file.
x - Execute or run the file as a program.

Numeric Permissions:
CHMOD can also to attributed by using Numeric Permissions:

400 read by owner


040 read by group
004 read by anybody (other)
200 write by owner
020 write by group
002 write by anybody
100 execute by owner
010 execute by group
001 execute by anybody

Operator Description
+ adds the specified modes to the specified classes
- removes the specified modes from the specified classes
= the modes specified are to be made the exact modes for the specified classes

(1) Relative permissions:


When changing permission in a relative manner,chmod only changes the permissions
in command line and leave the other permission unchanged.
The expression contains three components:
 User category (user,group,others)
 The operation to be performed (assign or remove permission)
 The type of permission (read,write,execute)

4.2 Absolute permission :

 The second way to modify permissions with the chmod command is to use
a number to specify each set of permissions for the file.
 Each permission is assigned a value, as the following table shows, and the
total of each set of permissions provides a number for that set.

OS Page 19
Enrollment No: [enter your number] Practical - 1

Number Octal Permission Representation


Ref

0 No permission
---

1 Execute permission
--x
2 Write permission -w-
Execute and write permission: 1 (execute) + 2 (write) =
3 -wx
3
4 Read permission r--
5 Read and execute permission: 4 (read) + 1 (execute) = 5 r-x
6 Read and write permission: 4 (read) + 2 (write) = 6 rw-
7 All permissions: 4 (read) + 2 (write) + 1 (execute) = 7 rwx

5. Simple filters:

5.1 head: Displaying the beginning of file


Format: head [options]… [file]…

Description : Displays the top of the file.

OS Page 20
Enrollment No: [enter your number] Practical - 1

Short Long
Option Description
Option Option
-c –bytes to print N bytes from each input file.
-n –lines to print N lines from each input file.
–silent, – Prevent printing of header information that
-q
quiet contains file name
-v –verbose to print header information always.

 Without options it displays first ten lines of the file.

5.2 tail: displaying end of the file


Format: tail [options]… [file]…
Description:displays end of the file

OS Page 21
Enrollment No: [enter your number] Practical - 1

Short Long
Option Description
Option Option
-c –bytes to print last N bytes from each input file
-f –follow to print appended data as and when the file grows
-n –lines to print last N lines from each input file
–pid with -f, to terminate after PID dies
–silent, –
-q to prevent printing of header information
quiet
to keep retrying to open a file even when it is not exist
–retry
or becomes inaccessible. Useful when it is used with -f
–sleep-
-s to sleep for N seconds between iterations
interval
-v –verbose to print header information always

 without options it displays the last ten lines of files.

Options:
 –C : Extracting bytes rather than lines

5.3 cut: Splitting a file vertically


Format : cut [ option ] [ file ]
Description : The features of cut and paste commands will be illustrated with
specific reference to the file shortlist , which stores the first five lines of emp.lst. Note the
use of the tee facility that serves the output in shortlist file and also displays it on the
terminal. We can extract both columns and fields from the file with the cut command.
Columns are specified with the –c option and fields with –f.

Options:
 Cutting columns: to extract specific columns , we need to follow the –c
option with a list of columns numbers , delimited by a comma. Ranges can also be
used with hyphen. For example following command extracts the name from the
shortlist file. Cut can also be used with multiple ranges as follows which gives
columns from 6 to 15 and 22 to 26. And here 30- shows columns number 30 to
the end of the line.

OS Page 22
Enrollment No: [enter your number] Practical - 1

 Cutting fields: -c option is useful for fixed length lines. But suppose now we
want to cut 2 and 3 fields from our file then we can use –f option. For example
following command cuts 2 and 3 fields from our file. We have to use –d option to
specify the delimiter. In our file fields delimiter is symbol that we have specified
in double quotes. And we have to use –f option to specify field list.

5.4 paste: Pasting files.


Format : paste [ options] [ file … ]
Description : What you cut with cut can be used pasted back with paste command
– but vertically rather than horizontally. For example we are cutting first field from the
shortlist file and putting the output in output 1 and cutting the third field from shortlist file
and putting the output in output 2. Now we are using paste command to merge two files
output 1 and output 2. We can also use –d to specify the delimiter.
*** joining lines ( -s ) : consider the following file which contains detail of three persons ,
with three for each.
Here we want to join lines such a way that instead of nine lines we will have 3 lines , 1
for each person. We can use paste command here in the following manner.
Here we have use used –d option with the string “||\n ”. Here the first and the second lines
would be joined with the | as delimiter and the same would be true for the second and
third line. The third and fourth line would be separated by a newline.

5.5 sort : ordering a file


Format : sort [ options] [ file …. ]
Description: sort orders a file , it can identies field and it can sort on specified
fields. Consider the following command. Here by default sort reorders lines in ASCII
collating sequence – white space first , then numerals , uppercase letters and finally
lowercase letters. This default sorting sequence can be altered by using certain options.
We can sort on one or more keys ( fields ) or use different ordering rule.

Options :
-tchar : uses delimiter char to identify fields
-k n : sort in nth field
-k m,n : starts sort on mth field and ends sort on nth field
-k m.n : starts sort on nth columns of mth field
-u : removes repeated lines
-n : sorts numerically

OS Page 23
Enrollment No: [enter your number] Practical - 1

-r : reverses sort order


-f : folds lowercase to equivalent uppercase ( case – insensitive sort )
-m list : merges sorted files in list

-c : check if file is sorted


-o fname : places output in file fname

Examples : here –t option is used to specify the delimiter. Sort uses space as the
default separator.
 Orting on primary key (-k) : let’s now use –k option to sort on the second
field(name)
 Following command reverse the previous sorting order.

We can sort more than one key. If the primary key is the third field and secondary key is
the second field then we can use the following command where –k 3,3 indicates that sort
starts on third field and ends on the same field.

Numeric sort : consider the following file.


 Execute the following command and we will get some unexpected output.
 This is because ASCII collating sequence places 1 above 2 , and 2 , above 4. Now
execute the following command,

Removing repeated lines :


 We can use –u option to remove repeated lines from the sorted output. For
example consider the following command which cuts the designation field from
the shortlist file and puts the output in design file.

OS Page 24
Enrollment No: [enter your number] Practical - 1

5.6 uniq: Locate repeated and nonrepeated lines


Format : uniq [ options ] [ infile [outfile] ]
Description:
 When we concatenate or merge fields we may have duplicate entries in the file.
Consider the following sorted file that includes repeated lines. Consider the
following field.

Now we want to sort this file and want to remove the duplicate lines. For that we can use
the following command which sorts the designation file and uniq removes the duplicate
lines and puts the data in output file.

Options :
 -u, --unique Only print unique lines.
 -d, --repeated Only print duplicate lines.
 -c, --count Print the number of times each line occurred along with the line

5.7 tr : translating characters


Format : tr options expression1 expression2 standard input
Description :
 The tr filter manipulate individual characters in a line.
 It translate characters using one or more compact expressions.
 tr takes input only from standard input, it doesn’t take filename as
argument.

Options :

Complement the set of characters in string1, that is "-C ab" includes every character
-C
except for 'a' and 'b'.

-c Same as -C but complement the set of values in string1.

-d Delete characters in string1 from the input.

OS Page 25
Enrollment No: [enter your number] Practical - 1

Squeeze multiple occurrences of the characters listed in the last operand (either
-s string1 or string2) in the input into a single instance of the character. This occurs
after all deletion and translation is completed.

-u Guarantee that any output is unbuffered.

Conclusion:

Grade: _______ Sign:___________

OS Page 26

Вам также может понравиться