Unix Interview Questions and Answers for 10 years experience
-
What is the difference between hard links and symbolic links?
- Answer: A hard link is a directory entry that points to the same inode as another file. Multiple hard links can exist to the same file. Deleting one hard link doesn't affect the others until the last link is removed. Symbolic links (or soft links) are essentially pointers to a file or directory. They contain the path to the target file. Deleting a symbolic link doesn't affect the target file, and the symbolic link can point to a file that doesn't exist.
-
Explain the difference between `grep`, `egrep`, and `fgrep`.
- Answer: `grep` uses basic regular expressions. `egrep` (or `grep -E`) uses extended regular expressions, which offer more concise syntax for complex patterns. `fgrep` (or `grep -F`) performs fast fixed-string searches; it doesn't interpret regular expressions.
-
How do you find all files modified in the last 24 hours?
- Answer: `find . -type f -mtime -1` This command uses `find` to locate all files (`-type f`) modified within the last 24 hours (`-mtime -1`). The `.` specifies the current directory as the starting point.
-
What is the purpose of the `chmod` command? Give examples.
- Answer: `chmod` changes the permissions of a file or directory. For example: `chmod 755 myfile` sets read, write, and execute permissions for the owner, read and execute for the group, and read and execute for others. `chmod u+x myfile` adds execute permission for the owner only.
-
Explain the significance of the shell environment variables like PATH, HOME, and SHELL.
- Answer: `PATH` specifies the directories where the shell searches for executable files. `HOME` points to the user's home directory. `SHELL` indicates the user's default shell.
-
How do you redirect standard output and standard error in a single command?
- Answer: `command 2>&1 > output.txt` This redirects both standard output (>) and standard error (2>&1) to the file `output.txt`.
-
What are pipes and how are they used in Unix?
- Answer: Pipes (`|`) connect the standard output of one command to the standard input of another, allowing you to chain commands together. For example, `ls -l | grep txt` lists all files and then filters the output to show only those containing "txt".
-
Describe the use of `awk` for data processing.
- Answer: `awk` is a powerful text processing tool that can be used for pattern scanning and text manipulation. It's often used for extracting specific columns from data files, performing calculations on fields, and reformatting data.
-
Explain the concept of process management in Unix using commands like `ps`, `top`, `kill`, and `jobs`.
- Answer: `ps` displays running processes. `top` shows real-time process activity. `kill` terminates a process (by sending a signal). `jobs` lists background jobs.
-
How do you find the largest file in a directory?
- Answer: `find . -type f -printf "%s %p\n" | sort -nr | head -n 1` This finds all files, prints their size and path, sorts numerically in reverse order, and displays the first (largest) file.
-
What is a shell script?
- Answer: A shell script is a sequence of commands that are executed by a shell interpreter. It automates tasks and processes.
-
Explain the difference between `cp` and `rsync`.
- Answer: `cp` copies files and directories. `rsync` is more powerful; it copies only the changed parts of files, making it efficient for backups and synchronizing directories over a network. It also handles resuming interrupted transfers.
-
How can you monitor system performance using Unix commands?
- Answer: Use `top`, `htop`, `vmstat`, `iostat`, `mpstat` (for multiprocessor systems), and `sar` (System Activity Reporter) to monitor CPU usage, memory usage, I/O performance, and other system metrics.
-
What are the different types of users and groups in Unix?
- Answer: Root (administrator), regular users, and groups (collections of users with shared access permissions).
-
What is a cron job? How do you create one?
- Answer: A cron job is a scheduled task. You create one by editing the crontab file (`crontab -e`) and adding lines specifying the time and command to run.
-
How do you search for a specific string within multiple files?
- Answer: `grep -r "string" .` searches recursively from the current directory.
-
Explain the use of `sed` for text manipulation.
- Answer: `sed` (stream editor) is used for in-place editing of text files, making substitutions and other transformations.
-
How do you compress and decompress files using Unix commands?
- Answer: `gzip`, `bzip2`, `xz` for compression and their corresponding `gunzip`, `bunzip2`, `xz -d` for decompression.
-
What are permissions (rwx) in Unix?
- Answer: r (read), w (write), x (execute) permissions for the owner, group, and others.
Thank you for reading our blog post on 'Unix Interview Questions and Answers for 10 years experience'.We hope you found it informative and useful.Stay tuned for more insightful content!