- How do you take a single line of input from the user in a shell script?
Answer:
Use the read command:
echo "Enter your name:"
read name
echo "Hello, $name"
- Write a script to convert all DOS-style backslashes to UNIX-style slashes in a list of files.
Answer:
Use Python to safely handle local files:
import os
files = ['C:\\temp\\file1.txt', 'C:\\temp\\file2.txt']
for file in files:
new_file = file.replace("\\\\", "/")
print(f"Converted: {new_file}")
This script prints the converted paths and demonstrates how to handle path normalization.
- Write a regular expression (or sed script) to replace all occurrences of the letter ‘f’, followed by any number of characters, followed by the letter ‘a’, followed by one or more numeric characters, followed by the letter ‘n’, and replace what’s found with “UNIX”.
Answer:
Using sed:
sed 's/f.*a[0-9]\+n/UNIX/g' input.txt
- Write a script to list all the differences between two directories.
Answer:
diff -rq /path/dir1 /path/dir2
This command recursively compares directories and reports differing files.
- Write a program in any language to reverse a file.
Answer (Bash):
tac filename.txt > reversed.txt
- What are the fields of the password file (
/etc/passwd)?
Answer:
Each line has 7 fields separated by colons:
username:password:UID:GID:GECOS:home_directory:shell
- What does a plus (+) at the beginning of a line in the password file signify?
Answer:
It historically indicated an entry for NIS (Network Information Service). This practice is deprecated; modern systems use PAM and LDAP for authentication.
- Using the man pages, find the correct ioctl to send console output to an arbitrary pty.
Answer:
This is system-dependent, but on Linux the TIOCCONS ioctl can redirect console output to a pseudo-terminal.
- What is an MX record?
Answer:
An MX (Mail Exchange) record in DNS specifies the mail server responsible for accepting email messages on behalf of a domain.
- What happens to a child process that dies and has no parent process to wait for it, and what’s bad about this?
Answer:
The process becomes a “zombie.” Zombies consume process table entries until reaped by the init (PID 1) process. Excess zombies can exhaust system resources.
- What command do you run to check file system consistency?
Answer:
fsck /dev/sdXn
Use it in single-user mode or on unmounted filesystems.
- What can be wrong with setuid scripts?
Answer:
Setuid scripts are insecure because they can be exploited during race conditions. Most modern UNIX systems ignore the setuid bit on scripts for this reason.
- What value does
spawn return?
Answer:
In UNIX-like systems, functions like fork() or posix_spawn() return the PID of the spawned process to the parent and 0 to the child.
- Write a script to send mail from three other machines on the network to root at the machine you’re on, including disk utilization.
Answer:
Example using SSH and mailx:
for host in server1 server2 server3; do
ssh $host "df -h" | mail -s "Disk usage from $host" root@$(hostname)
done
- Why can’t root just cd to someone’s home directory and run a program called a.out by typing
./a.out, and why is this good?
Answer:
For security, user home directories often restrict execution with permissions (700 or 750). Preventing root from executing arbitrary binaries reduces accidental privilege escalation or malware execution risk.
- What is the difference between UDP and TCP?
Answer:
TCP is connection-oriented and reliable (guarantees delivery and order). UDP is connectionless, faster, and used for time-sensitive transmissions like streaming.
- What is DNS?
Answer:
DNS (Domain Name System) translates human-readable domain names (e.g., example.com) into IP addresses that computers use to identify each other.
- What does
nslookup do?
Answer:
nslookup queries DNS servers to obtain domain name or IP address mappings.
Note: It is deprecated in favor of dig or host for modern diagnostics.
- How do you create a swap file?
Answer:
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
- How would you check the routing table on a workstation or server?
Answer:
ip route show
Note: The legacy route command is deprecated in favor of the ip command.
- How do you find which NIS master you are bound to?
Answer:
ypwhich -m
- How do you fix a problem where a printer cuts off anything over 1MB?
Answer:
Increase the spool size or buffer limit in the printer configuration file (e.g., /etc/cups/cupsd.conf) and restart the print service:
sudo systemctl restart cups
- What is the largest filesystem size supported by modern Linux distributions?
Answer:
With ext4, up to 1 exabyte (EB) in theory, though practical limits are smaller depending on kernel and hardware. For enterprise use, XFS and Btrfs support multi-petabyte volumes.
- What are the different RAID levels?
Answer:
- RAID 0 – Striping (no redundancy, highest performance)
- RAID 1 – Mirroring (redundancy)
- RAID 5 – Striping with parity (fault tolerance)
- RAID 6 – Double parity
- RAID 10 – Combination of mirroring and striping