25- Linux Shell Interview Questions for Intermediate Level with Answers
25- Linux Shell Interview Questions for Intermediate Level with Answers
1. What are the different types of shells available in Linux? How do you switch between
them?
Answer:
Answer:
Arguments are passed via the command line and accessed using $1, $2, etc.
Example:
Answer:
source: Runs the script in the current shell session. Changes affect the parent shell.
./: Executes the script in a new subshell, isolating changes.
4. How do you redirect both stdout and stderr to the same file?
Answer:
Use 2>&1 or &>:
Answer:
A Heredoc redirects a block of text into a command:
EOF
Answer:
Use conditional statements:
fi
Answer:
Temporary Alias:
Answer:
Use the du command:
du -sh /path/to/directory
Answer:
Answer:
for i in {1..5}; do
done
Answer:
set -e causes the script to exit immediately if a command fails.
Answer:
Use the -e option:
if [ -e file.txt ]; then
fi
Answer:
14. How do you find all files larger than 10MB in a directory?
Answer:
Use the find command:
Answer:
Answer:
Add this to crontab:
*/15 * * * * /path/to/script.sh
17. How do you create a function in a shell script?
Answer:
my_function() {
my_function
Answer:
Use the awk command:
Answer:
Use the wc -l command:
wc -l file.txt
Answer:
Use the >> operator:
Answer:
Answer:
Use set -x to enable debugging:
set -x
Answer:
Use the trap command:
Answer:
25. How do you extract only specific files from a .tar archive?
Answer: