Linux Interview Questions
Linux Interview Questions
com
1. Filesystem Basics
www.codelivly.com
27. How do you change file ownership?
● chown user:group filename
28. How do you view file permissions in a directory?
● ls -l
29. How do you recursively change permissions for a directory?
● chmod -R permissions directory_name
30. What does the chmod 777 command do?
● Grants read, write, and execute permissions to everyone
31. How do you view a file's access control list (ACL)?
●getfacl filename
32. How do you set a default ACL for a directory?
●setfacl -d -m u:user:permissions directory_name
33. How do you set permissions for a script to be executable?
●chmod +x script.sh
34. What is the significance of thesticky bit in Linux?
● It restricts file deletion in shared directories like/tmp.
35. How do you add the sticky bit to a directory?
● chmod +t directory_name
3. Process Management
www.codelivly.com
45. How do you view system logs for a process?
● journalctl -u service_name
46. How do you create a custom alias for a command?
● alias alias_name='command'
47. How do you remove an alias?
● unalias alias_name
48. How do you run a command as another user?
● sudo -u username command
49. How do you list all environment variables?
● printenv or env
50. How do you export a variable in Linux?
● export VAR=value
4. Networking
www.codelivly.com
5. User Management
6. Package Management
www.codelivly.com
78. How do you remove a package on Debian-based systems?
●apt remove package_name
79. How do you install a package on RHEL-based systems?
●yum install package_name or dnf install package_name
80. How do you remove a package on RHEL-based systems?
●yum remove package_name or dnf remove package_name
81. How do you search for a package in Debian repositories?
●apt search package_name
82. How do you list all installed packages?
●dpkg -l (Debian) or rpm -qa (RHEL)
83. How do you check which package a file belongs to?
●dpkg -S filename (Debian) or rpm -qf filename (RHEL)
84. How do you clean up cached packages on Debian-based systems?
●apt clean
85. How do you enable or disable a repository in RHEL-based systems?
●yum-config-manager --enable repo_name or --disable repo_name
www.codelivly.com
96. How do you check currently mounted filesystems?
● mount or df -h
97. How do you list active cron jobs?
● crontab -l
98. How do you check log files?
● tail -f /var/log/syslog or journalctl
99. How do you analyze disk usage by directories?
● du -h --max-depth=1
www.codelivly.com
113. How do you use variables in a shell script?
● variable=value and use with $variable
114. How do you accept input in a script?
● read variable_name
115. How do you pass arguments to a script?
● Use $1, $2, etc., for positional arguments
116. How do you write an if-else condition in a script?
●
bash if [ condition ]; then commands else commands fi
117. How do you write a for loop in a script?
●
bash for i in {1..5}; do echo $i done
118. How do you schedule a script using cron?
● crontab -e and add the schedule entry
119. How do you debug a script?
● bash -x script_name
www.codelivly.com
13. Disk Management
www.codelivly.com
146. How do you check process memory usage?
● ps aux --sort=-%mem
147. How do you check process CPU usage?
● ps aux --sort=-%cpu
148. How do you check process status?
● ps -o stat= -p PID
149. How do you find a process by name?
● pgrep process_name
150. How do you check the number of processes running?
● ps aux | wc -l
www.codelivly.com
162. How do you configure AWS CLI?
●aws configure
163. How do you create an S3 bucket using CLI?
●aws s3 mb s3://bucket_name
164. How do you list running EC2 instances?
●aws ec2 describe-instances
165. How do you create an EC2 instance?
●aws ec2 run-instances --image-id ami_id --count 1
--instance-type t2.micro
166. How do you deploy an application using Ansible?
● Write a playbook and run ansible-playbook playbook.yml
167. How do you configure Ansible inventory?
● Edit/etc/ansible/hosts
168. How do you use Terraform to create infrastructure?
● Write a.tf file and run terraform apply
169. How do you start a Kubernetes cluster?
● Usekubeadm init
170. How do you install Docker on a system?
● Useapt-get install docker.io or yum install docker
www.codelivly.com
180. How do you decompress a file?
●tar -xzf file_name.tar.gz
www.codelivly.com
196. How do you add a user to a group?
● usermod -aG group_name username
197. How do you list groups in Linux?
● cat /etc/group
198. How do you secure SSH access?
● Disable root login by setting PermitRootLogin no in
/etc/ssh/sshd_config
199. How do you configure SSH key-based authentication?
● Copy the public key to ~/.ssh/authorized_keys on the remote machine
200. How do you view system logs in Linux?
● journalctl or cat /var/log/syslog