0% found this document useful (0 votes)
8 views

30- Linux Shell Interview Questions for Beginners with Answers

Uploaded by

abhikumbhar1908
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)
8 views

30- Linux Shell Interview Questions for Beginners with Answers

Uploaded by

abhikumbhar1908
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/ 7

30+ Linux Shell Interview Questions for Beginners with Answers

1. What is the Linux Shell?

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.

2. What is the difference between a shell and a terminal?

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).

3. How do you display the current working directory in Linux?

Answer:
Use the pwd command:

pwd

4. How do you list files and directories in Linux?

Answer:
Use the ls command:

ls

Options:

​ ls -l: Detailed view.


​ ls -a: Include hidden files.

5. How do you create a directory in Linux?

Answer:
Use the mkdir command:

mkdir new_directory
6. How do you remove a file and a directory?

Answer:

​ Remove a file: Use rm filename.


​ Remove a directory: Use rmdir directory_name (if empty) or rm -r
directory_name (for non-empty directories).

7. What is the purpose of the cd command?

Answer:
The cd command is used to change directories:

cd /path/to/directory

8. How do you view the contents of a file?

Answer:
Use commands like cat, more, or less:

cat file.txt
less file.txt

9. How do you search for a file in Linux?

Answer:
Use the find command:

find /path -name filename

10. What is the difference between > and >> operators?

Answer:

​ >: Overwrites the file content.


​ >>: Appends content to the file.

Example:

echo "Hello" > file.txt # Overwrites


echo "World" >> file.txt # Appends

11. How do you check disk usage in Linux?

Answer:
Use the df and du commands:

df -h # Disk space usage


du -h file # Directory or file size

12. How do you display the first or last few lines of a file?

Answer:

​ First few lines: Use head:

head -n 5 file.txt

​ Last few lines: Use tail:

tail -n 5 file.txt

13. How do you search for a string in a file?

Answer:
Use the grep command:

grep "search_string" file.txt

14. What is the purpose of the chmod command?

Answer:
The chmod command changes file permissions:

chmod 755 file.txt

15. How do you check the running processes in Linux?

Answer:
Use the ps or top command:
ps -aux
top

16. How do you kill a process in Linux?

Answer:
Use the kill command with the process ID (PID):

kill -9 PID

17. What does the alias command do?

Answer:
The alias command creates shortcuts for commands:

alias ll="ls -la"

18. How do you display system information in Linux?

Answer:
Use commands like uname and hostname:

uname -a # Kernel information


hostnamectl # System hostname and details

19. How do you check network connectivity?

Answer:
Use the ping command:

ping google.com

20. How do you archive files in Linux?

Answer:
Use the tar command:

tar -cvf archive.tar file1 file2

21. How do you extract files from a tar archive?


Answer:
Use the tar command:

tar -xvf archive.tar

22. What is the sudo command?

Answer:
sudo allows a user to execute commands as another user, usually root:

sudo apt update

23. How do you check the current user in Linux?

Answer:
Use the whoami command:

whoami

24. How do you schedule tasks in Linux?

Answer:
Use the cron utility:

crontab -e

Example:

0 5 * * * /path/to/script.sh # Runs script at 5 AM daily

25. How do you count lines, words, and characters in a file?

Answer:
Use the wc command:

wc file.txt

Options:

​ wc -l: Line count.


​ wc -w: Word count.
​ wc -c: Character count.

26. How do you view the history of commands?

Answer:
Use the history command:

history

27. What is the purpose of environment variables?

Answer:
Environment variables store configuration data. Display them using printenv or echo:

echo $PATH

28. How do you compress files in Linux?

Answer:
Use the gzip command:

gzip file.txt

29. How do you create symbolic links?

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.

You might also like