Basic shell scripting interview questions
1. How do you find out the current directory you are in?
pwd
2. How do you find out what's your shell?
echo $SHELL
3. How do you list currently running process?
ps
4. How do you stop a process?
kill pid
5. How do you stop all the processes, except the shell window?
kill 0
6. What's the command to find out users on the system?
who
7. How do you count words, lines and characters in a file?
wc filename
8. What's the command to find out today's date?
date
9. How do you find out your own username?
whoami
10. How do you remove a file?
rm filename
11. How do you search for a string inside a given file?
grep string filename
12. How do you search for a string inside a directory?
grep string *
13. How do you search for a string in a directory with the subdirectories recursed?
grep -r string *
14. What's the conditional statement in shell scripting?
if {condition} then fi
15. How do you do number comparison in shell scripts?
-eq, -ne, -lt, -le, -gt, -ge
16. How do you fire a process in the background?
./process-name &
17. How do you refer to the arguments passed to a shell script?
$1, $2 and so on. $0 is your script name.
18. How do you find out the number of arguments passed to the shell script?
$#
19. How do you capture the return code?
$?
20. How do you know about running processes of a particular user?
ps -u username
1. How do you find out the current directory you are in?
pwd
echo $SHELL
ps
kill pid
kill 0
6. What's the command to find out users on the system?
who
wc filename
date
whoami
rm filename
11. How do you search for a string inside a given file?
grep string filename
grep string *
grep -r string *
if {condition} then fi
-eq, -ne, -lt, -le, -gt, -ge
16. How do you fire a process in the background?
./process-name &
$1, $2 and so on. $0 is your script name.
$#
$?
ps -u username