Search Jobs

Ticker

6/recent/ticker-posts

Unix Interview Questions


Certainly! Here are 50 Unix interview questions and answers with examples:


1. What is Unix?


Unix is a multi-user, multitasking operating system that was developed in the late 1960s.


2. What is a shell?


A shell is a command-line interface to interact with the Unix operating system.


3. How do you list files in a directory?


Use the ls command.


$ ls


4. How do you change your current directory?


Use the cd command.

$ cd /path/to/directory


5. How do you create a new directory?


Use the mkdir command.

$ mkdir new_directory


6. How do you remove a file?


Use the rm command.


$ rm filename


7. How do you remove a directory and its contents?


Use the rm command with the -r option.

$ rm -r directory_name


8. Explain the difference between a hard link and a symbolic link.


A hard link points directly to the data blocks of a file, while a symbolic link is a separate file that contains a path to another file.


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


Use the find command.

lua


$ find /path/to/search -name filename


10. How do you display the first few lines of a file?

- Use the head command.

$ head filename


11. How do you display the last few lines of a file?

- Use the tail command.

$ tail filename


12. What is a shell script?

- A shell script is a series of Unix commands stored in a file for execution.


13. How do you make a shell script executable?

- Use the chmod command.

$ chmod +x script.sh


14. What is a wildcard character in Unix?

- Wildcard characters, like * and ?, are used for pattern matching in Unix commands.


15. How do you find all files with a specific extension in a directory?

- Use the find command with the -name option and wildcard.

$ find /path/to/search -name "*.txt"


16. How do you redirect output to a file?

- Use the > operator.

$ command > output.txt


17. How do you append output to a file?

- Use the >> operator.

$ command >> output.txt


18. What is a pipeline in Unix?

- A pipeline (|) allows you to chain multiple commands together, passing the output of one as the input to another.


19. How do you list all environment variables in Unix?

- Use the env or printenv command.

$ env


20. How do you set an environment variable?

- Use the export command.

$ export VARIABLE_NAME=value


21. How do you check the disk usage of a file or directory?

- Use the du command.

$ du -h file_or_directory


22. How do you check the free disk space on a Unix system?

- Use the df command.

$ df -h


23. How do you kill a running process?

- Use the kill command.

$ kill process_id


24. How do you schedule a task to run at a specific time?

- Use the cron scheduler.

$ crontab -e


25. What is SSH?

- SSH (Secure Shell) is a protocol used to securely access remote Unix systems.


26. How do you copy files and directories in Unix?

- Use the cp command.

$ cp source destination


27. How do you move files and directories in Unix?

- Use the mv command.

$ mv source destination


28. How do you display the manual page for a command?

- Use the man command.

$ man command_name


29. How do you display the current date and time?

- Use the date command.

$ date


30. What is a shell variable?

- A shell variable is a user-defined variable that can store data for use in shell scripts.


31. How do you check the history of commands you've executed?

- Use the history command.

$ history


32. What is a symbolic link and how do you create one?

- A symbolic link (symlink) is a reference to another file or directory. You can create one with the ln command.

$ ln -s source_file_or_directory symlink_name


33. How do you zip files in Unix?

- Use the zip or tar command.

$ zip archive.zip file1 file2


34. How do you unzip files in Unix?

- Use the unzip or tar command.

$ unzip archive.zip


35. How do you check the user who is currently logged in?

- Use the who or w command.

$ who


36. How do you display the contents of a file in reverse order?

- Use the tac command.

$ tac filename


37. What is a process in Unix?

- A process is a running instance of a program.


38. How do you find the process ID of a running program?

- Use the pgrep or ps command.

$ pgrep process_name


39. How do you check your current working directory?

- Use the pwd command.

$ pwd


40. How do you create an empty file in Unix?

- Use the touch command.

$ touch filename


41. How do you count the number of lines in a file?

- Use the wc command.

$ wc -l filename


42. How do you rename a file in Unix?

- Use the mv command with a new name.

$ mv old_filename new_filename


43. How do you list all running processes?

- Use the ps command.

Post a Comment

0 Comments