30- Linux Shell Interview Questions for Beginners with Answers
30- Linux Shell Interview Questions for Beginners with Answers
Answer:
The shell is a command-line interface that interprets user commands and passes them to the
operating system for execution. Common shell types include Bash, Zsh, and Fish.
Answer:
Shell: A program that processes commands and returns outputs (e.g., Bash, Zsh).
Terminal: A user interface to interact with the shell (e.g., GNOME Terminal, xterm).
Answer:
Use the pwd command:
pwd
Answer:
Use the ls command:
ls
Options:
Answer:
Use the mkdir command:
mkdir new_directory
6. How do you remove a file and a directory?
Answer:
Answer:
The cd command is used to change directories:
cd /path/to/directory
Answer:
Use commands like cat, more, or less:
cat file.txt
less file.txt
Answer:
Use the find command:
Answer:
Example:
Answer:
Use the df and du commands:
12. How do you display the first or last few lines of a file?
Answer:
head -n 5 file.txt
tail -n 5 file.txt
Answer:
Use the grep command:
Answer:
The chmod command changes file permissions:
Answer:
Use the ps or top command:
ps -aux
top
Answer:
Use the kill command with the process ID (PID):
kill -9 PID
Answer:
The alias command creates shortcuts for commands:
Answer:
Use commands like uname and hostname:
Answer:
Use the ping command:
ping google.com
Answer:
Use the tar command:
Answer:
sudo allows a user to execute commands as another user, usually root:
Answer:
Use the whoami command:
whoami
Answer:
Use the cron utility:
crontab -e
Example:
Answer:
Use the wc command:
wc file.txt
Options:
Answer:
Use the history command:
history
Answer:
Environment variables store configuration data. Display them using printenv or echo:
echo $PATH
Answer:
Use the gzip command:
gzip file.txt
Answer:
Use the ln -s command:
ln -s target_file link_name
30. What is the difference between soft link and hard link?
Answer:
Soft link: Points to the file path and breaks if the target is moved/deleted.
Hard link: Points to the file content and remains valid even if the target is moved.