WEEK-1: Work out on UNIX/LINUX Vi editor and File Handling Utilities.Commands and their Description vi filename: Creates a new file if it already not exist, otherwise opens existing file. vi -R filename : Opens an existing file in read only mode. view filename : Opens an existing file in read only mode. File Handling Commands of Linux a)mkdir: This command is used to create a new empty directory or directories. Syntax: $ mkdir dir_name(s) Example: $ mkdir Sam b)rmdir: This command is used to remove an existing directory or directories from the directory hierarchy. Syntax: $ rmdir dir_name(s) Example: $ rmdir Sam c)cat: This command is used to display the contents of the existing file(s), to create a new file or to add the data to the end of the existing file. Syntax: $ cat file_name(s) Example: $ cat sam.txtOutput: This command without any options will display the content of the file named “sam.txt". Options: There are three versions of this Command. They are: a. $ cat filename(s): This will display the content of the given file(s). Example: $ cat sam.txt b. $ cat >filename: This will create a new file with the given filename. This will wait for the input after giving the input from the the standard keyboard, you have to press ctrl+d to terminate the input. Example: $ cat >sam.txt c. $ cat >>filename: This will add the lines at the end of the existing file. Example: $ cat >>sam.txt 1. -n option: This will give the line numbers to the content of the file. Example: $ cat -n sam.txt 2. -b option: This will give the line numbers to the content of the file but ignore the blank lines. Example: $ cat -b sam.txt d)mv: This command is used to rename the files with the new file name.Here this command first creates an empty file with the name given, then copies the contents of the old file to the new empty file and finally it deletes the old file. Syntax: $ mv old_filename new_filename Example: $ mv sam.txt isad.c Output: This command will change the name of the "sam.txt" to "isad.c". e)rm: This command is used to remove the existing file(s) from directory hierarchy. Syntax: $ rm file_name(s) Example: $ rm sam.txt Output: This command will delete the file "sam.txt" from the hierarchy. Options: 1. -f (Forcibly Removal): This option is used to remove the file even though it is write protected. Example: rm -f sam.txt 2. -r (Recursive Removal): This option will remove all the files and empty directories even though if the directory is having the files, it will removes the files first then remove the emptied directory. Example: rm -r sam.txt 3. -i (Interactive Removal): The rm command with -i flag will ask the user before removing the file or directory. Example: rm -i sam.txt ############################################### WEEK-2: Practice the UNIX/LINUX Process and text processing utilities.Text Processing in Unix/Linux Unix provides a number of powerful commands to process texts in different ways. These text processing commands are often implemented as filters. Some standard commands are described below. These commands may also take an input file as a parameter, but by default when the file is not specified, they operate as filter commands. Unix Filter Commands  grep: Find lines in stdin that match a pattern and print them to stdout.  sort: Sort the lines in stdin, and print the result to stdout.  uniq: Read from stdin and print unique (that are different from the adjacent line) to stdout.  cat: Read lines from stdin (and more files), and concatenate them to stdout.  more: Read lines from stdin, and provide a paginated view to stdout.  cut: Cut specified byte, character or field from each line of stdin and print to stdout.  paste: Read lines from stdin (and more files), and paste them together line-by-line to stdout.  head: Read the first few lines from stdin (and more files) and print them to stdout.  tail: Read the last few lines from stdin (and more files) and print them to stdout.  wc: Read from stdin, and print the number of newlines, words, and bytes to stdout.  tr: Translate or delete characters read from stdin and print to stdout. a. Cat: The cat command reads one or more files and prints them to standard output. The operator >can be used to combine multiple files into one. The operator >> can be used to append to an existing file. Syntax: cat [options] [files]Option: -e $ is printed at the end of each line. This option must be used with -v. Examples: 1. $cat file1 // displays the contents of file1 2. $cat file1 file2 > file3 //concatenates file1 and file2, and writes the results in file3 3. $cat file1 >> file2 //appends a copy of file1 to the end of file2 b. Tail: The tail command displays the last ten lines of the file. Syntax: tail [options] [file] Options: -f Follow the file as it grows. -r Displays the lines in the reverse order. Example: $tail -n 20 filename (This example shows all lines of filename from the second line onwards) c. Head: The head command displays the first ten lines of a file. Syntax: $head [options] $head -n 20 filename This displays the first 5 lines of all files d. Sort : Sorting is the ordering of data in ascending or descending sequence. The sort command orders a file. By default sort reorders lines in ASCII collating sequence_ white space first, then numerals, uppercase letters and finally lowercase letters. Sort by lines: The easiest sort arranges data by lines. Starting at the beginning of the line, it compares the first character in one line with the first character in another line. Syntax: $ sort filename Sort by fields: in general a field is the smallest unit of data. When a field sort is required we need to define which fields are to be used for the sort. Syntax: $ sort –t ” “ –k2 filename Here we use –k option to sort on the specified field. The delimiter option (-t) specifies an alternate delimiter. Reverse order: To order the data from largest to smallest,we specify reverse order(-r). Syntax: $ sort –t : -k2.3 -r filename Here it sorting the data based on 3rd character of the second field in descending order. options: -n - Sorts numerically -r - Reverses sort order e. nl: nl is a Unix utility for numbering lines, either from a file or from standard input, reproducing output on standard output. Options: • s – separator- number and data is separated with separator • w - width Example: $nl filename $nl –s: file1 $nl –w20 –s: file1 f. uniq: This command displays uniq lines of the given files.That is, if successive lines of a file are same then they will be removed. This can be used to remove successive empty lines in a given file. Syntax: $uniq[OPTIONS] INPUT [OUTPUT] Options: -c Prefix lines by their occurrences -d Only print repeated lines -D Print all duplicate lines -u Only print unique linesExample: $ uniq testfile (or uniq –u testfile) $ sort f1 | uniq g. Grep: (Global Regular Expression) Searching for a pattern UNIX has a special family of commands for handling search requirements, and the principal member of this family is the grep command. grep scans its input for a pattern and displays lines conainning the pattern, the linenumbers or filenames where the pattern occurs. Syntax: grep options pttern filename(s) Grep searches for pattern in one or more files ,or the standard input if no filename is specified. The first argument is the pattern and the remainning arguments are filenames. Example: $ grep “sales” employee It displays the lines containing the string sales from the file employee. Grep is also used with multiple filenames.It displays the filenames along with the ouput. Example: $ grep director emp1 emp2 $ grep “sales director” emp1 emp2 Here quoting is not necessary.when we use pattern with multiple words then we have to use quoting. options: option significance -I - Ignores case for matching -v - Doesn’t display lines matching expression -n - Displays line numbers along with lines -c - Display count of number of occurrences -l - Displays list of filenames only h. fgrep and egrep command: The fgrep and egrep command are advanced pattern matching command. The fgrep command doesn’t use any meta character for its searched pattern. The primary advantage of fgrep is it can Examples $cmp file1.txt file2.txt Compares file1 to file2 and outputs results. Below is example of how these results may look. $file.txt file2.txt differ: char 1011, line 112 o. diff command: This command is used to display file differences. It also tells you which lines in one file have to be changed to make two files identical. Syntax: $ diff file1 file2 p. tr command: (translate or transliterate): When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. Syntax: tr options expression1 expression2 < standard input Example: 1.$tr 'abcd' 'jkmn' maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'. Sets of characters may be abbreviated by using character ranges. The previous example could be written: 2.$tr 'a-d' 'jkmn' 3. $ tr ‘a-z’ ‘A-Z’ < file1 Options: -d -- delete the specified characters $ tr –d ‘ad’ < file1 -c – delete all the characters except specified character. $ tr –cd ‘ad’ < file1Process Utilities: Foreground Process : Every process when started runs in foreground by default, receives input from the keyboard and sends output to the screen.When issuing pwd command $ ls pwd Backround Process : It runs in the background without keyboard input and waits till keyboard input is required. Adding & along with the command starts it as a background process $ pwd & Tracking ongoing processes ps (Process status) can be used to see/list all the running processes. $ ps Stopping a process When running in foreground, hitting Ctrl + c (interrupt character) will exit the command. For processes running in background kill command can be used if it’s pid is known. $ ps –f $ kill 19 Other process commands: bg: A job control command that resumes suspended jobs while keeping them running in the background Syntax: bg [ job ] fg: It continues a stopped job by running it in the foreground. Syntax: fg [ %job_id ] For example fg 19 top: This command is used to show all the running processes within the working environment of Linux. Syntax: top nice: It starts a new process (job) and assigns it a priority (nice) value at the same time. Syntax:nice [-nice value] ###################### 3a. First Come First Serve Scheduling Algorithms PROGRAM: #include #include void main() { int i,j,bt[10],n,wt[10],tt[10],w1=0,t1=0; float aw,at; clrscr(); printf("enter no. of processes:\n"); scanf("%d",&n); printf("enter the burst time of processes:\n"); for(i=0;i #include void main() { int i,j,bt[10],t,n,wt[10],tt[10],w1=0,t1=0; float aw,at; clrscr(); printf("enter no. of processes:\n"); scanf("%d",&n); printf("enter the burst time of processes:\n"); for(i=0;ibt[j]) { t=bt[i]; bt[i]=bt[j]; bt[j]=t; } } for(i=0;i #include void main() { int st[10],bt[10],wt[10],tat[10],n,tq; int i,count=0,swt=0,stat=0,temp,sq=0; float awt=0.0,atat=0.0; clrscr(); printf("Enter number of processes:"); scanf("%d",&n); printf("Enter burst time for sequences:"); for(i=0;itq) st[i]=st[i]-tq; else if(st[i]>=0) { temp=st[i]; st[i]=0; } sq=sq+temp; tat[i]=sq; } if(n==count) break; } for(i=0;i #include void main() { int i,j,pno[10],prior[10],bt[10],n,wt[10],tt[10],w1=0,t1=0,s; float aw,at; clrscr(); printf("enter the number of processes:"); scanf("%d",&n); for(i=0;i