Linux/Unix Operating Systems Commands and Shell Scripting
Test your knowledge of Linux/Unix operating systems commands, file operations, process management, and shell scripting basics.
Questions
In vi if we want to replace any string e.g. "NAME" with "name" from line number 1 to 10 only, what command we can use?
- :%s/NAME/name/
- :1-10s/NAME/name/
- :1,10s/NAME/name/
- :s/NAME/name/
How to check the exit status of the previous command?
- $?
- $$
- $#
- $@
what is the command to change ownership of a file?
- change
- setfscl
- chown
- chmod
echo this || echo that && echo other What will be the output?
- this
- that
- this other
- this that other
How could you check if two strings are equal?
- test $a -eq $b
- test a -eq b
- test $a -equal $b
- test $a = $b
Which of the following would return the process ID of the sleep command?
- sleep 1 & echo $!
- sleep 1 & echo $?
- sleep 1 & echo $#
- sleep 1 & echo $$
Which command will create a soft link to a file?
- ls -n
- ln
- ln -s
- link -s
How to search recursively in the directory structure to list the file named file1?
- ls -lrt file1
- ls -lR file1
- find . -s file1
- find . -name file1
How can you determine the number of positional parameter passed to the script ?
- $# will print the same
- $? will print the same
- $! will print the same
- $$ will print the same
"What will be the output of following command var=hello varx=goodbye echo ${var}x"
- goodbye
- hello
- hellox
- hellogoodbye
How can we know two text files are identical?
- if the output of “cmp -s file1 file2” is not zero
- if the output of “cmp -s file1 file2” is zero
- if the output of “cmp -s file1 file2” is one
- if the output of “cmp -diff file1 file2” is zero
The purpose of the nohup command is to prevent programs from closing when you log out. True or False?
- True
- False
Which one of the following PIDs is assigned to the init program?
- 0
- 1
- 2
- 100
How can the time stamps of a file be preserved while copying a file?
- cp -i
- cp -r
- cp -p
- cp -R
How to send a running process to background?
- ctrl+c then bg
- ctrl+z then bg
- ctlr+m then bg
- ctrl+z then fg
"what does the command do? find . -type f -mtime 2"
- list all ordinary files in current dir that have been modified within last 24 hours
- list all ordinary files in current dir that have been modified within last 4 days
- list all ordinary files in current dir that have been modified within last 48 hrs
- list all ordinary files in current dir that have been modified within last 2 hrs
what is the name of the data structure to maintain file identification?
- inode
- filter
- kernel
- shell
How to save the output of any command in a file as well as display the same on the VDU?
- echo “hello world” > temp.txt
- echo “hello world” | tee temp.txt
- echo "hello world">tmp.txt|tee tmp.txt
- echo "hello world">tmp.txt|print
Which of the following will list the directories from the current working path.
- ls -l | grep ^d
- ls | grep dir
- ls | grep ^d
- pwd
How can you print the first 10 line of a file
- head +10 file
- cat file
- tail -10 file
- head -10 file