Command

Published on December 2016 | Categories: Documents | Downloads: 96 | Comments: 0 | Views: 831
of 19
Download PDF   Embed   Report

Comments

Content

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

paper --2006 ================ 1) Display regular files having more then two links. => 2) Display number of words and lines of files whose filenames begin with x. => wc -lw x* 3) Replace the word unix with UNIX in between 5th to 10th lines including both. => sed '5,10 s/unix/UNIX/p' file1 4) Remove all leading spaces from a file x1. => sed 's/^ *//' x1 5) Display lines from file x1 that contains at least 10 characters. => grep '^.\{10\}' x1 6) Display line number before each line. => nl file1 7) Move files that begin with x from current directory to the /user/bca01 directory. => mv x* /user/bca01 9) Remove directory tree dir1/dir2/dir3 using single command. => rm -r * 10) Assign value of 10th positional parameter to a variable x. =>i=0 for j in $* do i=`expr $i + 1`
FYBCA SEM-I Page 1 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

if [ $i -eq 10 ] then x=5 $j=$x fi done 11) Display lines 10 to 15 from file x1. => sed -n '10,15p' x1 12) Display last word of each line from a file x1. =>awk ' { print $NF } ' x1 13) Equivalent sed command of sed '1,5d' x1. => sed -n '1,5!p' fx1 14) Display lines before a line that contains pattern xyz. =>sed -n '1,/xyz/p' f1 15) Multiply value of variable x with that of y and store the result in variable x. => x='Expr $x \* $y'

==================== 2008 ====================
FYBCA SEM-I Page 2 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

16) To remove file that begins with hyphen. => rm [_]* 17) Display attributr of process. => ps 18) Kill current shell without using PID. => kill $! 19) List all files whose first character is anything other than an alphabat in the range 'd' to 'm'. => ls [^d-m]* 20) Display the processor of user bca01. => 21) Record your login session in file names logdetails. => script logdetails 22) Move all the files modified within the last 2-days to the dir1 directory under your parent directory. => 23) list uses from /etc/passwd in the alphabatically sorted order. => cut -d: -F1 /etc/passwd | sort 24) display files of current directory without using ls command. => echo * 25) Display file content in three columns with header 'Unix operating system' => 26) Display lines of file f1 that do not contain any digit in it. => grep "[^0-9] f1
FYBCA SEM-I Page 3 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

27) Replace all occurences of "linux OS" with "unix OS" in file f1. => sed -n 's/linux OS/unix OS/p' f1 28) create file2 from file1 such that it contains lines that begin with 'unix' in any case. => grep "^[uU][Nn][Ii][Xx]*" f1 > f2 29) Display all lines of file f1 having 3rd word 'user'. => $ awk ' { if($3=="user") print $0 }' f1 30) Count those line of file that do not begin with alphabets,. => grep "[^A-za-z]" f1 | wc -l 31) Display name of all files of workinf directory having patern 'the'. => grep -l "the"* 32) Display name of files of working directory having owner ,group and other permissions should be same. => $ ls -l |grep '^.\(...\)\1\1*' 33) Display lines of file f1 and that begin with any capital letter. =>grep "^[A-Z]*" f1

========================= 2010 ========================= 35) To display contents of top 3 largest files in a working directory.
FYBCA SEM-I Page 4 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

=>$ ls -l |tr -s ' '|cut -d' ' -f5,9| sort -r | head -3 | cut -d' ' -f2 | cat 36) To count number of words in lines 40 through 60 of file f1.txt. => sed -n "40,60p" f1.txt | wc -w 37) Match all filenames not begining with a dot(.). => $ ls '.'* 38) Transfer recursively the ownership of all files in current directory to 'bca5'. => chown -R bca5 /. 39) Copies all 6-characters files in working directory to dir1 exist in working directory. => cp ?????? ./dir1 40) To move all files of working directory modified within the last 24-hours to mydir directory under your parent directory. => 41) To display all proceses run by user1 on terminal pts/1. assume that user1 logged in from more than one terminal. => 42) To display all files of current directory whose 1st character is not digit. => ls [^0-9]* 43) To delete all special characters from the file x1. => $ tr -dc [0-9A-Za-z] < x1 44) To dfisplay inode number of all files of current directory. => ls -i 45) To display line number,no of characters and word in each line of file f1. => $ awk ' BEGIN { i=1 }
FYBCA SEM-I Page 5 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

{ c=length($0) w=NF printf("line no = %d\tchar = %d\tword =%d",i,c,w) printf("\n") i++ } ' f1 46) To display those lines of files f1 that contains exactly 50 character in it. => grep "^[.]\{50\}$" f1 47) To replace 'hello' with 'HELLO' in input file fin.sh and write those lines to output file fout.sh. => sed "s/hello/HELLO/g" fin.sh > fout.sh 48) To extract all username and their home directory from /etc/passwd file. => cut -d: -f1 /etc/passwd 49) Locate lines where the second and second last character of the f1.fh are the same. => $ grep '^.\(.\).*\1.$' f1 50) Display all files of working directory that contains 'hello' pattern in it. => $ ls -l|tr -s ' '| cut -d' ' -f9 | grep -l 'hello' 51) To display all lines that containsn pattern g* in a line. => grep "g\*" file1

====================== 2006 ====================== 52) Count number of characters in first five lines of file x1. => head -5 x1 | wc -c
FYBCA SEM-I Page 6 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

53) Display files of current directory whose 1st character is not digit. => ls [^0-9]* 54) Display last 20 files of working directory. => ls | tail -30 55) Remove a file forcfuly which do not have write permission. => rm -f 56) Display only those files of current directory,which is own by the current user. => ls 57) To run utility x1 at 5:00pm. => at 5:00pm >x1 58) To replace the word Computer with Computing of file x1. => sed 's/Computer/Computing/p' x1 60) Display lines whose last word is unix of file x1. => grep "UNIX$" x1 61) Display no of lines having odd number of words in file x1. =>$ awk 'BEGIN { i=1 } { if (NF % 2 == 1) i++ print i } END { print i } ' f1 | tail -1 62) To return back user to his/her home directory without using home directory name as an argument to that command. => cd
FYBCA SEM-I Page 7 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

63) Display lines of file x1 that do not begins with caret(^). => grep "[^^]" x1 64) Display only hidden files of worj=king directory. => grep "^[.]" worj=king 65) Display lines starting from 10th line to end of file of file x1. => sed -n '10,$p' x1

========================= 2008 ========================= 66) Display all files of current directory whose 1st character is not special character. =>ls [a-zA-Z0-9]* 67) Remove directory tree-structure dir/dir2/dir3/ using single command. => rm -r dir/dir2/dir3 68) Count frequency of users who are logged-in from more than one terminal. => 69) frame a contrab entry to execute the command1 every minute in first 10 minutes after 5:00 p.m. every friday of the month march june sepember and december of every year. => 70) Opens most recently savad file in vi editor. => ls -l > file1 | head -l | vi 71) Delete all leading and trailing spaces in all line of afile f1.
FYBCA SEM-I Page 8 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

=> 72) Select those lines that contain only digits. => grep "^[0-9]*$" f1 73) Display all line that start with 'let', from a file x1. l,e or t may be in any case. => grep "^[lL][Ee][tT]?*" x1 74) count the frequency of each word in text file. =>awk ' { for(i=1;i<=NF;i++) word[$i]++ } END { for(w in word) printf("%s\t%d\n",w,word[w]) }' f1 75) Display string in uppercase. => cat f1 | tr 'a-z' 'A-Z' 76) Write a grep command to display all lines that begin and end with same character. =>$ grep '^\(.\).*\1$' f1 77) using commnd substitution,write a command sequence that always prins the calendar of the current month. =>$ date | tr -s ' '| cut -d' ' -f2 | cal -----------------------------------------------------------------oct -nov 2009 -------------------------------------------------------------------

FYBCA SEM-I

Page 9 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

78) Frame a command to locate all the .doc and .txt files in the system. => ls *.doc;*.txt 79) change the modification time of a file to dec 25,10:30 am. => touch 12251030 file1 80) list all files of working directory having at least 4-character in filename. => ls ????* 81) frame a command to run the script hello.sh. => at 14:00 hello.sh 82) Display all files recursively (including the hidden ones) in multiple columns with distinguishing makes on executable and directories. => ls -Fx 83) Replace multiple space with a space in file f1. => tr -s' ' f1 84) write a unix command to evalutw the expression: => expr 4*3.14+6 85) write a command to display all unique words of file file1. => tr '[ <tab> ]' '012' <file1 | uniq -u 86) write a command to locate lines that begin and end with a dot(.) and containing anything between them. => ls .a.* 87) write a command to display all lines that contains 2 or more ^ symbols at begining of lines. => grep "^[^*]*" f1

FYBCA SEM-I

Page 10 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

88) write a command to replace all occurences of 'he' 'she' and 'hello' with 'hi' in file f1. => sed -n 's/[she][he][hello]/hi/p' f1 89) write a command to sellect lines having exactly 10 alphabet. => grep ".\{10\}" file1 90) write an equivalent IRE for the following regular expression: 1) A* =>A+ 2) A?=>A. --------------------------------------------------2007 --------------------------------------------------91) To replace all occurences of words Zenix with Unix but only on those lines where the word "operating" found in file INFILE' =>$ grep 'operating' f1 | sed 's/Zenix/Unix/g' 92) To display those lines between 20 and 50 having pattern 'unix' in it. =>$ sed -n '20,50p' f1 | grep 'unix' 93) To replace multiple spaces with a space. => tr -s ' '<f1 94) To select files having read and write permission for all categories of users. =>$ ls -l |grep '^.rw.rw.rw.*' 95) To display those lines that contain two or more consecutive instences of any word. => 96) To count number of characters in last line of file x1. => tail -1 x1 | wc -c
FYBCA SEM-I Page 11 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

97) To display those lines of file emp.dat in which third field contains 'director' or 'chairman'. => 98) Display from /etx/passwd a list of users and their shells for those using the korn shell or bash. => 99) To locate lines that contain hardware,software or firmware. => $ egrep '(hard|soft|firm)ware' f1 100) To count all lines that end with digit. =>$ grep -c '.*[0-9]$' f1 101) Write a command to display file names of working directory having first and last character must be an alphabet. =>$ ls -l | tr -s ' ' | cut -d' ' -f9 | grep '^[0-9].*[0-9]$' 102) write a command to list the users logged in more then once. => 103) write a command to display all files having length greater than equal to 25 characters. => find . -size +25c -print 104) write a command to display System process. => ps -W 105) how will you remove duplicate lines from a file? Assume that file is unsorted. => unique file1

FYBCA SEM-I

Page 12 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

========================================= march-april -2007 -----------------------------------------

106) What is command to display all filenames containing only digits in a filename. => ls [0-9]* 107) write a command to count number of special characters in a file. => grep -c '[^a-zA-Z0-9]*' f2

109) how will you schedule a process, which should wish you happy birthday throught out your life. => 110) how do you find out the users who are idling? => ls -ul 111) Give at least two way to delete a current line in vi editor. => 112) Write an unix command which is similar to msDos command del *.*/p => rm -i *.* 113) Write a command to move all files begins with digit ,from the parent directory to the current directory. => $ mv ../[0-9]* /.

FYBCA SEM-I

Page 13 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

114) Write a vi editor command to move two lines from the beginning of a file to the end. => 115) Write a command to link non-existing file nonfile.sh with newfile.sh. =>$ ln -s nonfile.sh newfile.sh 116) Write sed command which add two spaces to the begining of each line and two dashes to the end of each line. => $ awk '{ print " " $0 "--" }' f1 117) write an awk command that display all lines having 2nd and 3rd characters same. =>$ grep '^.\(.\)\1.*$' f1 118) Write a command to append blank line after each line in a file except last line. =>$ sed '$!a > ' f1 119) write a grep command which print all lines except the comment line of shell script. => grep "^[^#]*" f1 120) write a grep command that display all files which have read and write permission for the group. =>$ ls -l |grep '^....rw....*' 121) write a sed command to replace 'unix os' on lines 5th to 10th.

-----------------------------------march-2005 -----------------------------------FYBCA SEM-I Page 14 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

122) To remove a file named as x?(x followed by ? character). => rm x? 123) To send on line message to all login user. => wall x1 124) To run script x1 in background so that its execution continue even user logour from the system. => nohup x1.sh& 125) To display last line of a file x1. => sed -n '$p' x1 126) To sort a file with country as the primary key and state as secondary key when a file consist of name of city,state and country in the order. => sort -t" " -k3,3 -k2,2 file1 127) To deny execute permission to a group of a file x1. => chmod g-x x1 128) To kill the most recent background process,whom neither PID nor job number is known. => kill 128) To display number of processes related to login user. => ps -a 129) To create a link between file x1 and x1.link. => ln x1 x1.link 130) To create null(i.e 0 byte) file named as x1 in working directory. => cp /dev/null file1 | ls -l
FYBCA SEM-I Page 15 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

131) To combine content of file x1 and x2 into x12. => cat x1 x2 >x12 132) To run a command with a priority of 25. => nice -n 25 133) To display content of a file named x1.Don't use cat command. => grep "^$*" x1 134) To remove duplicate lines from file x1. => unique x1 135) To display characters from 5th position to 10th position,including both,from file x1 $ cut -c5-10 f1 using "awk" =============== 136) only line having odd number of fileds from file x1. =>awk ' { if ( NF % 2 == 1 ) > print $0 } > ' f1 137) The length of the last field of every line of file x1. => awk '{ l=length($NF) >print l } >' x1 138) Lines having at least three fields from file x1. =>$ awk '{ if (NF >=3) >print $0 >} ' f1 139) Fields of each line in reverse order of file x1. $ awk ' { for (i=NF;i>=1;i--)
FYBCA SEM-I Page 16 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

>printf("%s\t",$i) >printf("\n") >}' f1 using "grep" =============== => 140) Display lines having exactly 50 characters of file x1. => sed -n 's/{/50/}/p' x1 141) Count number of blank lines in file x1. => grep -vc '.' x1 142) Display lines having at least one* character in file x1. => grep -c '\*' x1 143) Display lines from file x1 that containing string "UNIX" or "unix""Unix". => grep '[uU][Nn][Ii][Xx]' f1 using "sed" =============== 144)Three lines starting from 5th line of file x1. => sed -n '5,7p' x1 145) All lines before string unix from file x1. => sed -n '1,/unix/p' X1 146) All blank lines of file x1. => 147) Lines begining either with alphabet or digit from file x1. => sed -n '/^[a-zA-z0-9]/p' x1
FYBCA SEM-I Page 17 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

FYBCA SEM-I

Page 18 of 19

Vidyabharti Trust College of BBA & BCA. Umrakh
Course: BCA SEM - V Sub: File Structure

FYBCA SEM-I

Page 19 of 19

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close