Linux and Command-Line Basics

Learn with multiple-choice questions about the Linux directory layout and paths, hard and symbolic links, wildcards, permissions with chmod and umask, sudo and setuid, redirection and pipes, grep and regular expressions, sort, uniq, cut, sed, awk and find, signals and job control, exit status with && and ||, quoting, arguments, conditions and loops in shell scripts, PATH and environment variables, package management, systemd, cron, df and du, SSH public-key authentication, tar, and basic Git operations.

Practice 10 questionsRandom questions from this topic · about 5 minutes Practice this topicAll questions in this topic, in random order Weak questionsRetry only the questions you last got wrong

Linux and Command-Line Basics: key points

Most servers and clouds run Linux, and EDA tools for logic synthesis, circuit simulation and the like are also normally used on Linux servers. There, daily work means typing commands into a shell rather than clicking buttons: inspecting files, filtering logs, and leaving long jobs running after disconnecting.

This topic covers the directory layout, absolute and relative paths, hidden files, hard and symbolic links, wildcards, rwx permissions and their octal notation, umask, execute permission on directories, and sudo and setuid. It then deals with redirection and pipes, grep and regular expressions, counting with sort and uniq, tail -f, cut, sed, awk, find, kill and signals, Ctrl+Z with bg and fg, nohup, exit status with && and ||, quoting and variable expansion, script arguments, conditions and loops, and PATH and export, and finally checks package management, systemctl, cron, df and du, SSH keys, tar, and Git add, commit and push with .gitignore. Command behavior follows bash and the GNU commands (coreutils, grep, sed, findutils, tar), and the outputs in the questions have been checked by actually running them on Linux. How processes and virtual memory work is covered in "OS & Hardware", port numbers and DNS in "Computer Networking Basics", access-control principles in "Information Security Basics", and Git merges and development practices in "Software Development and Project Management".

All Linux and Command-Line Basics questions (40)

  1. Which of the following correctly pairs standard Linux directories with what is placed in them?
  2. Which of the following correctly describes the /proc directory on Linux?
  3. The directory /home/alice/data exists, and the current directory is /home/alice/work. Which of the following is the directory shown when "cd ../data" is run and then "pwd"?
  4. In the home directory, "ls" shows only notes.txt, while "ls -a" shows ".", "..", ".bashrc" and "notes.txt". Which of the following correctly explains this result?
  5. When the commands above are run in order, which of the following is the result of the last two cat commands?
  6. A directory contains six files: a1.txt, a2.txt, a10.txt, b1.txt, c1.txt and a1.csv. Which of the following is the number of files shown when "ls [ab]?.txt" is run in this directory?
  7. After "chmod 754 run.sh" is run on the file run.sh, which of the following is the permission notation shown at the start of the line from "ls -l run.sh"?
  8. touch creates a new file from 666, and mkdir a new directory from 777, with the umask bits removed. Which of the following is the correct pair of permissions when a new file and a new directory are created in a shell whose umask is 027?
  9. The directory d has permissions rwx--x--x (711), and the file f.txt in it has rw-r--r-- (644). A user who is neither the owner nor the superuser runs "ls d" and "cat d/f.txt". Which of the following is the result?
  10. Which of the following correctly describes the sudo command on Linux?
  11. On many Linux systems, "ls -l /usr/bin/passwd" shows "-rwsr-xr-x 1 root root ...". Which of the following is the meaning of the "s" in the owner's execute position?
  12. When the commands above are run in order, which of the following is the content shown by the last cat?
  13. As shown above, in a directory where a.txt exists and nofile does not, the last command is run. Which of the following is the result?
  14. In the session above, which of the following is the value printed by the last command?
  15. In the session above, which of the following are the lines printed by the last grep?
  16. The choices omit the leading spaces of the line. In the session above, which of the following is the line printed by the last pipeline?
  17. You want to keep showing lines on the screen as they are appended later to the server log file /var/log/app.log. Which of the following commands is appropriate?
  18. Which of the following is the output of the command above, which extracts columns from a comma-separated line?
  19. Which of the following is the output of the sed command above, which replaces characters?
  20. In the session above, which of the following is printed by the last awk?
  21. Which of the following describes the files found when find /data -name "*.log" -mtime +7 -size +100M is run with GNU find?
  22. When stopping a process that has stopped responding, it is recommended to first use "kill <process ID>" and to use "kill -9 <process ID>" only if that does not end it. Which of the following is the reason?
  23. While a long-running ./sim.sh is running in a terminal, you want to use other commands in the same terminal. Which of the following is what happens when you press Ctrl+Z and then run bg?
  24. On a server reached over SSH, a long-running task was started with "./run.sh &", and when the connection was closed the task stopped too. Which of the following is the most appropriate way to start it so that it keeps running after the connection is closed?
  25. When the two lines above are run in a shell, which of the following are the characters shown?
  26. When the commands above are run in order, which of the following is the output of the two echo commands?
  27. As shown above, the script s.sh is run with arguments. Which of the following is the output?
  28. In a shell script, in which of the following cases is the condition of the if above true?
  29. Which of the following are the files in the directory after the session above?
  30. An executable script run.sh in the current directory gives "command not found" when run by typing "run.sh", but runs when typed as "./run.sh". Which of the following is the reason?
  31. When the commands above are run in order, which of the following is the pair of outputs of the two bash -c commands?
  32. Which of the following is the main function of a Linux package management system (apt on Debian-based systems, dnf on Red Hat-based systems and so on)?
  33. On a Linux system using systemd, which of the following is the difference between "systemctl start license.service" and "systemctl enable license.service" for the service license.service?
  34. The line "30 2 * * 1 /home/alice/backup.sh" was registered in cron. Which of the following is when backup.sh is run?
  35. A Linux server warns that disk space is running low. Which of the following is the correct pair of a command to check usage and free space for each file system and a command to total the space used by the files in a directory?
  36. You created a public-key authentication key pair with ssh-keygen on your own PC and want to connect to the server server1 with ssh without a password. Which of the following is the correct way to place the keys?
  37. Which of the following is what happens when "tar -czf proj.tar.gz proj/" is run?
  38. After editing main.c, a file managed with Git, only git commit -m "fix" was run, and "no changes added to commit" was shown and nothing was committed. Which of the following is the reason?
  39. You ran git commit in Git, but the commit does not yet appear in the GitHub repository shared by the team. Which of the following is the reason?
  40. "build/" was written in the .gitignore of a project managed with Git, but changes to build/out.log, which was committed earlier, keep appearing in git status. Which of the following is the reason?

Books on Linux and Command-Line Basics Ad

As an Amazon Associate I earn from qualifying purchases.

Other topics in Computer systems