0% found this document useful (0 votes)
26 views12 pages

Shell Ans 1

Uploaded by

Madhu Sudhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views12 pages

Shell Ans 1

Uploaded by

Madhu Sudhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1.What is the purpose of the command 'chmod 777 file.txt’?

a) Gives all users full read/write/execute permissions to the file


b) Removes all permissions from the fie
c) Gives the file owner read/write/execute permissions, and only read
permissions to all other users
d) Gives the file owner read/write/execute permissions, and read/execute
permissions to all other users.

2.Command prints the shared objects required by each program or shared


object specified on the command line.

a) Id
b) Ild
c) Idd
d) Lld

3. _______ stands for Universally Unique Identifier and it is used in Linux to


identify disk in the/etc/fstab file.

a) UID
b) UUID
c) UD
d) UIID
4. Which command will copy all.jpg files from the current directory to /backup/
directory?

a) Find. -iname”*..jpg" |xargs cp/backup


b) Find. -iname”*.jpg" |xargs -i cp{} /backup
c) Find. -iname”*.jpg" |xargs -i cp /backup
d) xargs -i cp{} /backup | find-iname”*.jpg"

5. Which of the following is the root directory of a Linux system?

a) ~/
b) /home
c) /
d) /usr

6. What command is used to remove a directory and its contents in Linux?

a) rmdir
b) rmd
c) removedir
d) rm -r

7. What does the command 'Is -I | head -n +5’ do?

a) Lists the first 5 files in the current directory and sorts them alphabetically
b) Lists all files in the current directory that were modified within the last 5
minutes
c) lists the first 5 files in the current directory displaying details including
file transmission and ownership
d) Lists the sizes of the first 5 files in the current directory, sorsed by size
8. Which command will generate an archive of all files in the current directory?

a) cpio -ov | /tmp/object.cpio


b) cpio -ov
c) ls | cpio -ov > archive.cpio
d) cpio -l archive.cpio

9. What command is used to list all files and directories in the current directory
in Linux?

a) ls
b) cd
c) dir
d) find

10. What is true about the below Is -il listing?

619888 -rw-rw-rw- 2 ownerid groupid 428 Apr 14 19:42 myfile.txt

145389 -rw-rw-r-- 1 ownerid groupid 7285 Sep 30 10:17 coffee.txt

268394 -гw-гw-rw- 1 ownerid groupid 8912 Nov 4 19:42 tea.txt

619880 -гw-rw-rw- 2 ownerid groupid 428 Apr 14 19:42 person.txt

a) There are 2 files with symbolic line to each other


b) There is one physical file with 2
c) There is a dragging symbolic link
d) None of the above
11. What is the output of the following command?

grep -oE ‘([0-9]+-)’ file.txt

a) All the lines containing hyphens in file.txt


b) All the hyphen-separated numbers are in file.txt
c) The line count of file.txt
d) Throws an error for invalid arguments

12. What is the output of the following command?

grep -r "Hello" /path/to/directory

a) Deletes all the files containing the string held


b) Displays the number of occurrences of the string Helo
c) Displays all the files containing the string Hello
d) Renames all the files containing the string Helo
13.

declare -i shared_var=0

declare -i num_threads=4

declare -i counter=0

Increment() (

while true

do

if [["$(counter)" -ge 100000 ]]; then

break

fi

shared_var+=1

counter+=1

done

main()(

for ((i=0; i<num_threads; i++))

do

increment &

done

wait

main
a) Shared variable: 0
b) Shared variable: 100000
c) Shared variable: 200000
d) The script will encounter an error and terminate prematurely

14. What is the output of the following command?

echo "12345" | awk '{print $1+5}’

a) 12350
b) 5
c) 12345
d) 10

15.Which statement is true for egrep command with option -n?

a) Print NUM lines of leading context before matching lines


b) Print NUM lines of output context
c) Print the filename for each match
d) Prefix each line of output with the Iine number within its input file

16. Which one of the following is NOT a Linux shell?

Please choose a correct answer.

a) bash
b) csh
c) jsh
d) zsh
17.Which command can be used to create a new file with read-write
permissions for the owner only, named 'newfile.txt' in the current directory?

a) touch newfile.txt; chmod 600 newfile.txt


b) touch newfile.txt; chmod 400 newfile.txt
c) touch newfile.txt; chmod 777 newfile.txt
d) touch newfile.txt; chmod 655 newfile.txt

18. What will be the output of the below code when values of p = 12, q = 14,

and r = 11?

read p

read q

read r

if test $p -gt $q-a $p -gt $r

then

echo "p is greatest"

else

if test $q -gt $r

then

echo "q is greatest"

else

echo "r is greatest"

fi

fi

Answer : q is greater
19.

#!/bin/sh

cat $1 | sort |

while read line

doif [ $prev!=$line ]

thenecho $line >> abc.txt

fi

prev=$linedone

a) Remove one line (or identical lines from the file)


b) Take an input file
c) Remove identical lines (or duplicate lines from the file)
d) Take an input file and remove identical lines for duplicate
lines from the file)
20. What will be the output of the below code when p = 12 and q = 14?

read p

read q

x='expr $p + $q

echo $x

Answer

a) -2
b) 26
c) 2
d) 12 14

21. Which command will enable shell to correct minor mistakes, for example to
execute cd test instead of (incorrect) cd terst?

Please choose a correct answer.

a) set AUTOCORRECT='yes'
b) shopt -s cdspell
c) export CORRECT_DIR='yes'
d) unset STRICT_MODE
22. What is the output of the following command?

echo "Hello World" | awk '{print substr($1, 3, 4)}'

Please choose a correct answer

a) Hel
b) ello
c) llo
d) Lo W

23.What is the output of the following command?

Find / -type f -name '*.txt' -size +5M-user root 2>/dev/null'

a) List of all files with .txt extensions, size greater than 5 MB and owned by
root user in the root directory and sub-directories

b) List of all files with .txt extensions, size less than 5 MB and owned by root
user in the root directory and sub-directories

c) List of all files with .txt extensions, size greater than 5 MB and owned by non-
root user in the root directory and sub-directories

d) List of all files with .txt extention size less than 5MB and owned by non-root
users in the root directory and sub-directories
24.Which one of the following commands changes the directory to the

current users home directory?

a) cd~

b) cd/

c) cd.

d) cd $

25. mkfifo mypip.

a) creates a directory named mypip. named

b) creates a name pip mypip

c) creates a regular file names mypip

d) displays an error message because mkfifo is not a valid command

26.Which command can be used to create a new directory in the current


location

a) touch dir name

b) mk dirname

c) mk file dirname

d) newdir dirname
27. What does the command 'Is -I | head -n +5° do?

a) Lists the first 5 files in the current directory and sorts them alphabetically
b) Lists all files in the current directory that were modified within the last 5
minutes
c) Ousts the first 5 files in the current directory displaying details
including file Permission and ownership
d) Lists the sizes of the first 5 files in the current directory, sorted by size

28. Which of the following commands is used for finding the maximum
numbers of open files in the system

a) max-open-files
b) limit -n
c) ulimit -n
d) maxfiles

29. Which of the following commands used to find and replace all occuranced
of a string ‘old string’ with ‘new string’ in the file.txt

sed -i ‘s/oldstring/newstring/g’ file.txt

30. command to change the permission of a file or directory in linux?

chmod

31. Which command is used to display the no.of words in the file
named 'example.txt'?

wc -w example.txt

You might also like