Post

Linux Week2 Exam Questions

Linux Command Line Practice Questions - Week 2

— Process Management —

  1. How do you list all currently running processes on the system?

  2. How do you find all running processes that contain the word “<look at response from 1 and then Examiner to Decide process name>” in their name?

  3. What do the columns USER, PID, %CPU, and %MEM mean in the output of ps aux?

  4. How do you monitor running processes in real time? What key do you press to sort by memory usage? What key to sort by CPU?

  5. How do you stop a process with PID 5678?

  6. What is the difference between kill 5678 and kill -9 5678? When would you use each?

  7. How do you kill a process by name (e.g., an app called myapp) without knowing its PID?

  8. How do you run a command in the background? Start sleep 300 in the background, find its PID using ps, and then kill it.

— sudo & System Administration —

  1. What does sudo do? Why is it needed for commands like apt update?

  2. How do you run the previously failed command with sudo? (Hint: there is a shortcut.)

  3. How do you become the root user temporarily from the terminal?

— System Information —

  1. How do you check disk space usage on all mounted filesystems in human-readable format?

  2. How do you check the total size of the /var/log directory?

  3. How do you find the 10 largest directories inside your home directory?

  4. How do you check how much RAM is free and used on the system?

  5. How do you check how long the system has been running?

— Package Management —

  1. What command must you always run before installing a package, and why?

  2. How do you install the packages git, curl, and wget in a single command?

  3. How do you remove a package called nginx and also clean up any unused dependencies?

  4. How do you search for all available packages related to Python 3?

  5. How do you update all installed packages on the system in one command?

— Archives & Compression —

  1. How do you create a compressed archive called backup.tar.gz from a folder named projects/?

  2. What does each flag mean in tar -czf?

  3. How do you extract a file called backup.tar.gz?

  4. How do you view the contents of backup.tar.gz without extracting it?

  5. How do you create a compressed backup of your home directory with today’s date in the filename?

  6. How do you extract an archive to a specific destination folder, e.g., /tmp/restore/?

  7. How do you create a zip archive of a folder called website/? How do you extract it?

— SSH & Remote Access —

  1. How do you connect to a remote server at 192.168.1.100 as user rahul?

  2. How do you run the command df -h on a remote server without starting an interactive session?

  3. How do you generate an SSH key pair? What two files does it create, and what is the difference between them?

  4. How do you copy your public key to a remote server so you can log in without a password?

  5. How do you connect to a remote server using a specific private key file at ~/.ssh/my_key?

  6. How do you SSH into a server running on localhost at port 2222?

  7. How do you create an SSH config file entry so that ssh myserver connects to example.com as user deploy on port 22?

— SCP (Secure Copy) —

  1. How do you copy a local file report.pdf to the home directory of user rahul on server.com?

  2. How do you copy an entire folder website/ to /var/www/html/ on a remote server?

  3. How do you download the file /var/log/app.log from a remote server to your current local directory?

  4. How do you SCP a file to a server running on port 2222? (Note: what flag does SCP use for port — is it -p or -P?)

  5. How do you SCP using a specific private key file?

— Real-World Scenarios —

  1. Write the sequence of commands to: connect to a server, install nginx, start it, enable it to start on boot, and check its status.

  2. Write a bash script called system_check.sh that prints disk space, memory usage, top 10 processes by memory, and system uptime.

  3. Write a bash script called backup.sh that creates a folder named with today’s date inside ~/backups/, then compresses ~/Documents into it, and prints a completion message.

  4. You are given three servers: server1.com, server2.com, server3.com. Write a bash script that SSHs into each one and runs df -h to check disk space.

  5. How do you monitor live logs on a remote server and filter to show only lines containing the word “error”?

This post is licensed under CC BY 4.0 by the author.