Sunteți pe pagina 1din 7

Rahul kumar sangwan Roll no :a14 Reg no:11003338 Section :k1r03

Linux assignment Submitted to: Miss Chavi rahlan

Q1. Write a Shell script that defines no of bytes used by a file in a directory? Q2. Write a shell script to show various system configurations like (i) Currently logged user and his log name Ans: who: shows who is logged on Description: Prints information about the user who is ligged in Synopsis: $who
(ii)

Your current shell. Ans:Ps: It reports the snapshots of current processes Description: Ps display information about the active processes .and aso displays the current shell you are working in Synopsis: $ps

Your home directory. Cd /home Description: Changes directory to home directory Synopsis: Cd /home
(iii) (iv)

Your Operating System type.

Uname: prints system information Description: Print certain system information Synopsis: Uname -a -a :prints all information
(v)

Your current path setting. Echo $path Your current working directory. Pwd: prints the name of current directory Description: Prints full file name of current working directory Synopsis: $pwd Show currently logged number of users. who: shows who is logged on Description: Prints information about the user who is ligged in Synopsis: $who Show all available shells. Cat /etc/shells

(vi)

(vii)

(viii)

Q3. Write a shell script to that confirms the password for a user once he logs in. [ Ans:

echo password stty echo read password stty echo echo # force a carriage return to be output

echo you entered $password

correct=$(cat/etc/verify) if[ $password = $correct ] then failed=$(( $failed + 1 ))

Q4. Write Linux commands for each of the following: a. Find all lines in a file with exactly 9 characters in them. Ans: grep ^.\{9\}$ rahul b. Find all lines in a file with at least 9 characters in them. Ans: egrep {9,} filename c. Find all lines in a file that end with two digits. [10] Q5. Write a shell program to reverse a string which is entered by a user. [10] Ans: # reverse a string [[ -z "$@" ]] && STR=" l u h a r " || STR="$@" len=${#STR} REV="" for (( i=$len ; i>0 ; i-- )) do REV=$REV""${STR:$i-1:$i} STR=${STR%${STR:$i-1:$i}} done echo "Reversed string" echo $REV

Q6. Execute the command man man. What do you see?

(a) What does the a option to man do?

Ans: [--names-only] [-a] Description: Display all the details by name (b) What does the k option to man do?

Ans: k [apropos options] It displays all the commands concerning to the given command For eg: $man k grep Display all the commands concerning to grep (c) What option should you use to just print a short description of a command? (d) What options shows the location of the man page rather than its [10] contents? Ans: Manpath: determine search path for manual pages Description: Manpath determine suitable manual page hierarchy search path and display the results Synopsis: $manpath Q7. What do the following numeric file modes represent: Illustrate with a valid example. (a) 666 Ans: rw-rw-rw(b) 770 Ans: -rwxrwx--(c) 640 Ans: -rw-r----(d) 444 Ans: -rrr-e) 220 ans: --ww----

Q8. A user wants set the permissions of a directory tree rooted at Dir so that the user can read and write files but nobody else has any access. Which command is most appropriate and Why? Ans: chmod -r 600 dir Q9. Write a shell script to display the grades of a student. Ans: sum=0 min=10000 max=0 n=5 i=0 file="students.txt" cat $file | while read line; do set line grade=$3 sum='expr $sum + $grade' if [ $grade -gt $max ]; then max=$grade fi if [ $grade -lt $min ]; then min=$grade fi i='expr $i + 1' if [ $i -ge $n ]; then break fi done average='expr $sum / $i' echo "Max: $max Min: $min Avg: $average" Q10. There are following environmental variables. With the help of shell script let us know the output of the various environment variable How can we display all the environmental variables. $HOME

$PATH $PS1 $PS2 $$ $# $0 $IFS Ans: echo $HOME echo $PATH echo $PS1 echo $PS2 echo $$ echo $# echo$0 echo $IFS

S-ar putea să vă placă și