Linux Terminal Commands Practice Questions (Ubuntu and Bash)

Practice questions on common Linux and Ubuntu terminal commands (pwd, cd, ls, and more), with explanations for every answer.

94 questions · Linux Terminal Commands · by Study Foxy

Study these questions free

Questions

  1. What does pwd do?

    • Prints the current directory's path
    • Changes the password for the current user
    • Lists the files in the current directory
    • Prints the contents of a file
  2. You are in /home/student. What does this output? $ cd projects/site; pwd

    • /home/student/projects/site
    • projects/site
    • /projects/site
    • /home/student
  3. You are in /home/student. What does this output? $ cd projects/site; cd ../..; pwd

    • /home/student
    • /home/student/projects
    • /home
    • /
  4. You are in /home/student. What does this output? $ cd /tmp; cd ~; pwd

    • /home/student
    • /tmp
    • /
    • ~
  5. Which of these is an absolute path?

    • /home/student/docs
    • docs/readme.md
    • ../docs
    • ./docs
  6. What does ~ stand for in a path?

    • Your home directory
    • The root of the file system
    • The previous directory you were in
    • The current directory
  7. What does cd / do?

    • Goes to the root, /
    • Moves to your home directory
    • Moves up one directory
    • Moves to the last directory you used
  8. In a path, what does .. mean?

    • The parent directory
    • The current directory
    • The home directory
    • A hidden file
  9. Your home contains docs/, projects/, notes.txt, report.txt, and a hidden file named .hidden. You are in /home/student. What does this output? $ ls | wc -l

    • 4
    • 5
    • 2
    • 3
  10. Your home contains a hidden file named .hidden. You are in /home/student. What does this output? $ ls -a | grep hidden

    • .hidden
    • Nothing
    • hidden
    • ls: invalid option
  11. What does ls -l add to a normal listing?

    • Permissions, owner, size, and date
    • Only the hidden files in the directory
    • A list sorted from largest to smallest file
    • The full path of each file
  12. projects/site contains index.html and style.css. You are in /home/student. What does this output? $ ls projects/site | wc -l

    • 2
    • 1
    • 3
    • 0
  13. You type cd Doc and press Tab. What happens?

    • The shell completes the name, such as Documents
    • The shell deletes the folder
    • The shell lists every command on the system
    • Nothing; Tab does nothing in a terminal
  14. In Linux, Notes.txt and notes.txt are two different files.

    True or false

  15. Linux commands are case-sensitive, so LS is not the same command as ls.

    True or false

  16. Which command prints the full path of the directory you are in?

  17. You are in /home/student. What does this output? $ mkdir -p a/b/c; ls a/b

    • c
    • a/b/c
    • b
    • mkdir: cannot create directory
  18. You are in /home/student, which has no folder named x. What happens? $ mkdir x/y

    • An error: No such file or directory
    • It creates both x and y
    • It creates only x
    • Nothing; it silently does nothing
  19. You are in /home/student. What does this output? $ touch new.txt; ls | grep new

    • new.txt
    • Nothing
    • touch: missing operand
    • new
  20. notes.txt holds six lines: apple, banana, apple, cherry, banana, apple. You are in /home/student. What does this output? $ cp notes.txt copy.txt; wc -l copy.txt

    • 6 copy.txt
    • 0 copy.txt
    • 6 notes.txt
    • 12 copy.txt
  21. notes.txt holds six lines: apple, banana, apple, cherry, banana, apple. You are in /home/student. What does this output? $ mv notes.txt list.txt; ls | grep -c notes

    • 0
    • 1
    • 2
    • list.txt
  22. projects/ contains a folder named site with two files. What happens? $ rmdir projects

    • An error: Directory not empty
    • projects and everything in it are deleted
    • Only the empty folders inside projects are deleted
    • projects is moved to the trash
  23. You are in /home/student. What does this output? $ echo hi > a.txt; cp a.txt b.txt; echo bye > a.txt; cat b.txt

    • hi
    • bye
    • hi bye
    • Nothing
  24. Besides moving files, what else can mv do?

    • Rename a file
    • Copy a file to a new folder
    • Delete a file permanently
    • Change a file's permissions
  25. Which command deletes a folder named old and everything inside it?

    • rm -r old
    • rmdir old
    • rm old
    • del old
  26. Which command copies the folder site and everything in it to backup?

    • cp -r site backup
    • cp site backup
    • mv -r site backup
    • copy site backup
  27. Why is sudo rm -rf / considered extremely dangerous?

    • It force-deletes everything from the root down
    • It only clears the screen
    • It removes the terminal program
    • It deletes the current user's password
  28. Files deleted with rm go to a trash can where they can be restored.

    True or false

  29. Which command creates a new, empty file (one word)?

  30. Which command creates a new directory?

  31. Which commands can delete something?

    • rm
    • rmdir
    • touch
    • ls
    • cat
    • chmod -x
  32. notes.txt holds six lines: apple, banana, apple, cherry, banana, apple. You are in /home/student. What does this output? $ head -n 2 notes.txt

    • apple banana
    • apple apple
    • banana apple
    • apple
  33. report.txt holds four lines: Error: disk full / warning: low memory / Error: timeout / info: started. You are in /home/student. What does this output? $ tail -n 1 report.txt

    • info: started
    • Error: disk full
    • Error: timeout
    • warning: low memory
  34. notes.txt holds six lines: apple, banana, apple, cherry, banana, apple. You are in /home/student. What does this output? $ wc -l notes.txt

    • 6 notes.txt
    • 6
    • 3 notes.txt
    • 36 notes.txt
  35. notes.txt holds six lines: apple, banana, apple, cherry, banana, apple. You are in /home/student. What does this output? $ cat notes.txt | wc -l

    • 6
    • 6 notes.txt
    • 3
    • 1
  36. You are in /home/student. What does this output? $ echo one > a.txt; echo two > b.txt; cat a.txt b.txt

    • one two
    • two one
    • one
    • onetwo
  37. You open a long file with less. How do you quit?

    • Press q
    • Press Ctrl+S
    • Type exit and press Enter
    • Close and reopen the terminal
  38. Which command watches a log file and shows new lines as they are added?

    • tail -f app.log
    • head -f app.log
    • cat -w app.log
    • less -n app.log
  39. How many lines does head show if you don't give a number?

  40. nano is a text editor that runs inside the terminal.

    True or false

  41. What does wc stand for?

    • Word count
    • Write copy
    • Web connect
    • Wildcard
  42. notes.txt holds six lines: apple, banana, apple, cherry, banana, apple. You are in /home/student. What does this output? $ grep apple notes.txt | wc -l

    • 3
    • 1
    • 6
    • 2
  43. report.txt holds four lines: Error: disk full / warning: low memory / Error: timeout / info: started. You are in /home/student. What does this output? $ grep -c Error report.txt

    • 2
    • 1
    • 4
    • 3
  44. report.txt holds four lines: Error: disk full / warning: low memory / Error: timeout / info: started. You are in /home/student. What does this output? $ grep error report.txt | wc -l

    • 0
    • 2
    • 1
    • 4
  45. notes.txt holds six lines: apple, banana, apple, cherry, banana, apple. You are in /home/student. What does this output? $ grep -v apple notes.txt | wc -l

    • 3
    • 0
    • 6
    • 1
  46. notes.txt holds six lines: apple, banana, apple, cherry, banana, apple. You are in /home/student. What does this output? $ grep -n cherry notes.txt

    • 4:cherry
    • cherry
    • 1:cherry
    • cherry:4
  47. projects/site contains index.html and style.css. You are in /home/student. What does this output? $ find . -name "*.css"

    • ./projects/site/style.css
    • style.css
    • projects/site
    • ./style.css
  48. What is the difference between grep and find?

    • grep searches inside files; find searches for files
    • They do exactly the same thing
    • grep only works on folders
    • find searches inside files; grep finds file names
  49. Which option makes grep ignore uppercase and lowercase differences?

    • -i
    • -c
    • -v
    • -n
  50. Which commands are used to find files by name?

    • find
    • locate
    • grep
    • cat
    • grep -r

Showing 50 of 94. Open the quiz to study them all.