Unix Interview Questions and Answers for internship
-
What is Unix?
- Answer: Unix is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, developed in the late 1960s and early 1970s. It's known for its portability, efficiency, and a powerful command-line interface.
-
What is the difference between Linux and Unix?
- Answer: Linux is an open-source implementation of the Unix-like operating system. Unix is a family of proprietary operating systems. While Linux adheres to the POSIX standard (making it Unix-like), it's distinct from the original Unix systems like Solaris or HP-UX. Key differences often lie in licensing, kernel implementations, and specific system calls.
-
Explain the concept of a shell.
- Answer: A shell is a command-line interpreter. It acts as an interface between the user and the Unix kernel. Users type commands, and the shell interprets these commands and executes them. Popular shells include bash, zsh, and csh.
-
What are some common Unix commands?
- Answer: Common Unix commands include `ls` (list files), `cd` (change directory), `pwd` (print working directory), `mkdir` (make directory), `rm` (remove files), `cp` (copy files), `mv` (move/rename files), `cat` (concatenate files), `grep` (search text), `find` (find files), `sort` (sort lines), `wc` (word count), `chmod` (change file permissions), `chown` (change file ownership).
-
How do you list all files and directories in a directory?
- Answer: Use the `ls` command. For a more detailed listing, use `ls -l`.
-
How do you create a new directory?
- Answer: Use the `mkdir` command followed by the directory name. For example, `mkdir my_new_directory`.
-
How do you change your working directory?
- Answer: Use the `cd` command followed by the directory path. For example, `cd /home/user/documents`.
-
How do you copy a file?
- Answer: Use the `cp` command. For example, `cp source_file.txt destination_file.txt`.
-
How do you move or rename a file?
- Answer: Use the `mv` command. For example, `mv old_name.txt new_name.txt`.
-
How do you delete a file?
- Answer: Use the `rm` command. For example, `rm my_file.txt`. Be cautious, as this command permanently deletes files.
-
What is the purpose of the `grep` command?
- Answer: `grep` searches for patterns within files. For example, `grep "error" log.txt` searches for the word "error" in the file `log.txt`.
-
Explain the concept of file permissions in Unix.
- Answer: File permissions control who can access a file (read, write, execute) – the owner, the group, and others. These permissions are represented by a three-digit octal number (e.g., 755).
-
How do you change file permissions?
- Answer: Use the `chmod` command. For example, `chmod 755 my_file.sh` sets read, write, and execute permissions for the owner, and read and execute permissions for the group and others.
-
What is the purpose of the `find` command?
- Answer: `find` searches for files and directories based on various criteria, such as name, type, modification time, etc. For example, `find . -name "*.txt"` finds all files ending in ".txt" in the current directory and its subdirectories.
-
What is a pipe in Unix?
- Answer: A pipe (`|`) takes the output of one command and uses it as the input of another command. This allows chaining commands together for powerful processing.
-
What is input/output redirection?
- Answer: Input/output redirection changes where a command gets its input from and sends its output to. `>` redirects output to a file, `>>` appends to a file, and `<` redirects input from a file.
-
What is the difference between hard links and symbolic links?
- Answer: A hard link is another name for the same file data (inode). A symbolic link (symlink) is a pointer to a file or directory.
-
What is a process in Unix?
- Answer: A process is a running program. Each process has a unique process ID (PID).
-
How do you list running processes?
- Answer: Use the `ps` command (often `ps aux` for a detailed listing).
-
How do you kill a process?
- Answer: Use the `kill` command followed by the process ID (PID). For example, `kill 1234`.
-
What is the `top` command?
- Answer: `top` displays dynamic real-time information about running processes.
-
What is the `cron` job scheduler?
- Answer: `cron` allows you to schedule tasks to run automatically at specified times or intervals.
-
What are environment variables?
- Answer: Environment variables are dynamic named values that can affect the behavior of programs. They are inherited by child processes.
-
How do you view environment variables?
- Answer: Use the `env` command or `printenv`.
-
What is a regular expression?
- Answer: A regular expression is a sequence of characters that defines a search pattern. They're used to match and manipulate text.
-
How do you use regular expressions with `grep`?
- Answer: Use the `-E` option for extended regular expressions. For example, `grep -E "a[0-9]b" file.txt`.
-
What is the `sed` command?
- Answer: `sed` is a stream editor for filtering and transforming text.
-
What is the `awk` command?
- Answer: `awk` is a pattern-scanning and text-processing language.
-
What is a shell script?
- Answer: A shell script is a program written in a shell scripting language (like bash) that automates tasks.
-
How do you make a shell script executable?
- Answer: Use `chmod +x script_name.sh`.
-
What are some common shell scripting features?
- Answer: Variables, loops (for, while), conditional statements (if, else), functions, input/output redirection.
-
Explain the concept of signal handling in Unix.
- Answer: Signals are software interrupts that allow processes to respond to events like keyboard interrupts (Ctrl+C) or termination requests.
-
What is the `tar` command?
- Answer: `tar` is used for creating and manipulating archive files (e.g., .tar, .tar.gz, .tar.bz2).
-
What is the `zip` command (if applicable to your system)?
- Answer: `zip` is used for creating and manipulating zip archive files.
-
What is the `unzip` command (if applicable to your system)?
- Answer: `unzip` is used to extract files from zip archives.
-
What is the importance of the `/etc` directory?
- Answer: `/etc` contains system-wide configuration files.
-
What is the importance of the `/var` directory?
- Answer: `/var` stores variable data files, like log files and databases.
-
What is the importance of the `/tmp` directory?
- Answer: `/tmp` is used for temporary files.
-
What is a symbolic link (symlink)? Give an example.
- Answer: A symbolic link is a pointer to another file or directory. `ln -s /path/to/original /path/to/link`
-
What is a hard link? Give an example.
- Answer: A hard link is another name for the same file inode. `ln /path/to/original /path/to/link`
-
What is the difference between `>` and `>>` in redirection?
- Answer: `>` overwrites the file, `>>` appends to the file.
-
How can you check disk space usage?
- Answer: Use the `df` command (disk free).
-
How can you check the current user?
- Answer: Use the `whoami` command or `id` command.
-
How do you search for a specific string within multiple files?
- Answer: Use `grep -r "string" directory`
-
How do you sort the lines of a file alphabetically?
- Answer: Use `sort file.txt`
-
How do you count the number of lines in a file?
- Answer: Use `wc -l file.txt`
-
How do you display the first 10 lines of a file?
- Answer: Use `head -n 10 file.txt`
-
How do you display the last 10 lines of a file?
- Answer: Use `tail -n 10 file.txt`
-
What is the purpose of the `uname` command?
- Answer: `uname` prints system information (kernel name, node name, etc.).
-
What is the purpose of the `finger` command (if applicable to your system)?
- Answer: `finger` displays information about users on the system.
-
What is a background process? How do you run a command in the background?
- Answer: A background process runs independently of the terminal. Add `&` to the end of a command.
-
How do you bring a background process to the foreground?
- Answer: Use the `fg` command or `jobs` command followed by `fg %job_number`.
-
What are some common shell scripting pitfalls to avoid?
- Answer: Unhandled errors, improper quoting, inefficient loops, lack of comments, insufficient error checking.
-
Describe your experience with version control systems (e.g., Git).
- Answer: [This requires a personalized answer based on your experience. Mention specific commands used, branching strategies, and any projects where you utilized version control.]
-
Explain the concept of process groups in Unix.
- Answer: Process groups are collections of related processes that share a common process group ID (PGID). This allows for sending signals to a group of processes at once.
-
What is a shell's prompt? How can you customize it?
- Answer: The shell's prompt is the text displayed before the command line. It can be customized using environment variables like `PS1`.
-
How do you handle errors in a shell script?
- Answer: Use `if` statements to check the exit status of commands, use error codes, and provide informative error messages to the user.
-
What are some common Linux distributions?
- Answer: Ubuntu, Debian, Fedora, CentOS, Red Hat Enterprise Linux (RHEL), Arch Linux, etc.
-
What are some common Unix system utilities?
- Answer: `ps`, `top`, `kill`, `netstat`, `ifconfig`, `route`, `ping`, `traceroute` (or `mtr`), `ss`
-
What is a daemon process?
- Answer: A daemon process runs in the background without a controlling terminal.
-
How do you determine the PID of a running process?
- Answer: Use `ps aux | grep process_name` or `pgrep process_name`
-
Explain the concept of "umask" in Unix.
- Answer: `umask` sets the default file permission mask when creating new files and directories.
-
What is the difference between a regular file and a directory?
- Answer: A regular file contains data; a directory organizes files and other directories.
-
How would you find all files larger than 1GB in a directory?
- Answer: `find . -type f -size +1G`
-
How would you find all files modified in the last 24 hours?
- Answer: `find . -type f -mtime -1`
-
What is the significance of the `.` and `..` directories?
- Answer: `.` represents the current directory, `..` represents the parent directory.
-
What is the importance of proper logging in a Unix system?
- Answer: Logging helps with debugging, auditing, security monitoring, and troubleshooting.
-
Describe a time you had to troubleshoot a Unix system issue. What was the problem, and how did you solve it?
- Answer: [This requires a personalized answer based on your experience.]
-
What are your strengths and weaknesses as a Unix systems intern?
- Answer: [This requires a personalized answer based on your strengths and weaknesses.]
-
Why are you interested in this Unix internship?
- Answer: [This requires a personalized answer based on your interests and goals.]
-
What are your salary expectations for this internship?
- Answer: [This requires a personalized answer based on your research and expectations.]
Thank you for reading our blog post on 'Unix Interview Questions and Answers for internship'.We hope you found it informative and useful.Stay tuned for more insightful content!