Linux Week2 Exam Questions
Linux Command Line Practice Questions - Week 2
— Process Management —
-
How do you list all currently running processes on the system?
-
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?
-
What do the columns USER, PID, %CPU, and %MEM mean in the output of
ps aux? -
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?
-
How do you stop a process with PID 5678?
-
What is the difference between
kill 5678andkill -9 5678? When would you use each? -
How do you kill a process by name (e.g., an app called
myapp) without knowing its PID? -
How do you run a command in the background? Start
sleep 300in the background, find its PID usingps, and then kill it.
— sudo & System Administration —
-
What does
sudodo? Why is it needed for commands likeapt update? -
How do you run the previously failed command with sudo? (Hint: there is a shortcut.)
-
How do you become the root user temporarily from the terminal?
— System Information —
-
How do you check disk space usage on all mounted filesystems in human-readable format?
-
How do you check the total size of the
/var/logdirectory? -
How do you find the 10 largest directories inside your home directory?
-
How do you check how much RAM is free and used on the system?
-
How do you check how long the system has been running?
— Package Management —
-
What command must you always run before installing a package, and why?
-
How do you install the packages
git,curl, andwgetin a single command? -
How do you remove a package called
nginxand also clean up any unused dependencies? -
How do you search for all available packages related to Python 3?
-
How do you update all installed packages on the system in one command?
— Archives & Compression —
-
How do you create a compressed archive called
backup.tar.gzfrom a folder namedprojects/? -
What does each flag mean in
tar -czf? -
How do you extract a file called
backup.tar.gz? -
How do you view the contents of
backup.tar.gzwithout extracting it? -
How do you create a compressed backup of your home directory with today’s date in the filename?
-
How do you extract an archive to a specific destination folder, e.g.,
/tmp/restore/? -
How do you create a zip archive of a folder called
website/? How do you extract it?
— SSH & Remote Access —
-
How do you connect to a remote server at
192.168.1.100as userrahul? -
How do you run the command
df -hon a remote server without starting an interactive session? -
How do you generate an SSH key pair? What two files does it create, and what is the difference between them?
-
How do you copy your public key to a remote server so you can log in without a password?
-
How do you connect to a remote server using a specific private key file at
~/.ssh/my_key? -
How do you SSH into a server running on
localhostat port2222? -
How do you create an SSH config file entry so that
ssh myserverconnects toexample.comas userdeployon port 22?
— SCP (Secure Copy) —
-
How do you copy a local file
report.pdfto the home directory of userrahulonserver.com? -
How do you copy an entire folder
website/to/var/www/html/on a remote server? -
How do you download the file
/var/log/app.logfrom a remote server to your current local directory? -
How do you SCP a file to a server running on port
2222? (Note: what flag does SCP use for port — is it-por-P?) -
How do you SCP using a specific private key file?
— Real-World Scenarios —
-
Write the sequence of commands to: connect to a server, install nginx, start it, enable it to start on boot, and check its status.
-
Write a bash script called
system_check.shthat prints disk space, memory usage, top 10 processes by memory, and system uptime. -
Write a bash script called
backup.shthat creates a folder named with today’s date inside~/backups/, then compresses~/Documentsinto it, and prints a completion message. -
You are given three servers:
server1.com,server2.com,server3.com. Write a bash script that SSHs into each one and runsdf -hto check disk space. -
How do you monitor live logs on a remote server and filter to show only lines containing the word “error”?