0% found this document useful (0 votes)
16 views3 pages

Os Lab File

The document discusses shell scripting and vi editor commands. It provides descriptions and syntax examples of various commands for writing and executing shell scripts, manipulating files and directories, and using the vi text editor. It also covers shell scripting concepts like variables, control structures, and functions.

Uploaded by

yrofficial13
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
16 views3 pages

Os Lab File

The document discusses shell scripting and vi editor commands. It provides descriptions and syntax examples of various commands for writing and executing shell scripts, manipulating files and directories, and using the vi text editor. It also covers shell scripting concepts like variables, control structures, and functions.

Uploaded by

yrofficial13
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

Operating System and Shell Programming Lab –II

1. What is vi editor and its modes?


2. What is shell scripting?
3. What is shell scripting programming?
4. Write a shell scripting program to demonstrate the use of variables.
5. Write a program to implement input /output operations in shell scripting.
6. Write and execute the shell script files.
7. Write a program to implement loops using shell scripting.
8. Write a program to implement control statements using shell scripting.
9. Write a program to implement the concept of subprograms / functions using shell
scripting.
10. Write the syntax and example of the following shell scripting commands.

 $ clear : clear screen


 $ cal : display calendar
 $ who : display list of users who are currently logged into the computer
 $ date : displays current time stamp

 File related commands in unix

 $ touch filename : create a new file


 $ cat > filename : create a new file and enter content
 $ cat >> filename : append content in file
 $ cat filename : display content of the file
 $ cat file1 file2 > file3 : concatenate file 1 and file2 and store in file3
 $ cp file1 file2 : copy content from file1 into file2
 $ rm filename : remove file
 $ mv old-name new-name : rename file
 $ wc file_name : counts number of lines, words, and characters in specified
files
 $ grep string filename :search for a particular string in a file
 $ sort filename : arrange lines in a file in sorted order
 $ sort -m file1 file2 : displays merged content
 $ sort - filename : combine contents of a file with the input from keyboard and
then carry out the sorting.
 $ cut : picks up a given number of character or fields from the specified file.
 Directory related commands in unix
 $ pwd : present working directory
 $ mkdir directory_name : make directory
 $ rmdir directory_name : remove directory
 $ cd dir_name : change directory to dir_name

 Listing files and directories

 $ ls : display all files and directories in a particular file


 $ ls p* : display all file stating with character p
 $ ls [aeiou]* : display all files whose name start with a/e/i/o/u
 $ ls [!aeiou]* : display all files whose name doesn’t start with a/e/i/o/u
 $ ls –l : long listing – display all information about files
 (file type, permissions, no of links, owner, group, size in bytes, date and time,
file name)
 $ chmod : used to change permission(read / write / execute) of a file
 Example of chmod:
 $ chmod +w filename : give write permission to all users of the file
 $ chmod go-x filename : take away execute permission from group and other
users
 $ chmod 700 filename : give read write and execute permission only to owner.
Groups and others do not have any permission

 Commands related to vi editor

 $ vi filename : invoke the vi editor


 :w – save file/ write text
 :q – quit the editor return to shell.
 :m,n s/str1/str2/g – replace all occurrences of str1 with str2 from lines m to n
 :set nu – set display of line numbers on.
 :set nonu – set display of line numbers off(default).
 :set eb – beep the speaker when an error occurs.(default)
 :set noeb – do not beep the speaker when error occurs.
 :set ai – set auto indent on
 :set noai – set auto indent off (default)
 :set ic – ignore case while searching a pattern
 :set noic – do not ignore case while searching a pattern
 :set terse – make message terse.
 :set noterse – do not make error messages terse. (default)
 :set mesg – permit receipt of messages from other terminal.
 :set nomesg – don’t receive messages from other terminal. (default)
 :set showmode – display mode in which we are working
 :set noshowmode – don’t display current working mode. (default)
 :set aw – automatically write buffer contents to disk before switching to next
file during multiple file editing.
 :set noaw – do not write buffer contents to disk before switching to next file
during multiple file editing. (default)
 dd – delete the current line
 ndd – delete n lines from current line
 yy – yanks/copies line from current cursor position
 y$ – yanks/copies line from current cursor position to end of file.
 P – pastes the last deleted or yanked element

You might also like