LFCS: LINUX FOUNDATION CERTIFIED SYSTEM ADMINISTRATOR EXAM
PREP - VERIFIED ANSWERS AND QUESTIONS - MOST RECENT EDITION
2026/2027
Q1. What command displays the current working directory? ANSWER pwd
Q2. How do you list all files including hidden ones in a directory? ANSWER ls
-la or ls -a
Q3. What command changes directory to the parent directory? ANSWER cd ..
Q4. How do you create a new empty file? ANSWER touch filename
Q5. What command copies a file while preserving attributes? ANSWER cp -p
source destination
Q6. How do you move or rename a file? ANSWER mv oldname newname
Q7. What command removes a file forcefully without prompts? ANSWER rm
-f filename
Q8. How do you remove a directory and all its contents recursively? ANSWER
rm -rf directoryname
Q9. What command creates a new directory? ANSWER mkdir dirname
Q10. How do you create a nested directory structure in one command?
ANSWER mkdir -p /path/to/new/dir
Q11. What command displays the type of a file? ANSWER file filename
Q12. How do you find files by name in the current directory? ANSWER find . -
name "filename"
Q13. What command searches for files by type (e.g., regular files)? ANSWER
find /path -type f
Q14. How do you find files modified in the last 24 hours? ANSWER find /path
-mtime -1
,Q15. What command locates files by name using a prebuilt database?
ANSWER locate filename
Q16. How do you update the database used by locate? ANSWER updatedb
Q17. What command searches for text within files? ANSWER grep "pattern"
file
Q18. How do you perform a case-insensitive grep search? ANSWER grep -i
"pattern" file
Q19. What command recursively searches for text in all files under a
directory? ANSWER grep -r "pattern" /directory
Q20. How do you display only the count of matching lines in grep? ANSWER
grep -c "pattern" file
File Viewing & Manipulation
Q21. What command displays the first 10 lines of a file? ANSWER head
filename
Q22. How do you display the first 20 lines of a file? ANSWER head -n 20
filename
Q23. What command shows the last 10 lines of a file? ANSWER tail filename
Q24. How do you continuously monitor a log file for new entries? ANSWER
tail -f /var/log/file.log
Q25. What command displays file contents page by page? ANSWER less
filename
Q26. How do you display the entire contents of a file? ANSWER cat filename
Q27. What command numbers all output lines including blank ones?
ANSWER cat -n filename
Q28. How do you concatenate multiple files into one? ANSWER cat file1 file2
> combined
Q29. What command displays lines in reverse order (last line first)? ANSWER
tac filename
Q30. How do you sort lines in a file alphabetically? ANSWER sort filename
, Q31. What command sorts numerically instead of alphabetically? ANSWER
sort -n filename
Q32. How do you remove duplicate lines from sorted output? ANSWER sort
filename | uniq
Q33. What command counts lines, words, and bytes in a file? ANSWER wc
filename
Q34. How do you count only the number of lines in a file? ANSWER wc -l
filename
Q35. What command compares two files line by line? ANSWER diff file1 file2
Q36. How do you create a patch file from diff output? ANSWER diff -u file1
file2 > patchfile
Q37. What command applies a patch file? ANSWER patch < patchfile
Q38. How do you extract a specific column from text output? ANSWER awk
'{print $1}' filename or cut -d' ' -f1 filename
Q39. What command replaces text in a stream? ANSWER sed 's/old/new/g'
filename
Q40. How do you edit a file in-place with sed? ANSWER sed -i 's/old/new/g'
filename
Text Processing & Streams
Q41. What is the purpose of the pipe operator |? ANSWER It sends the
output of one command as input to another command.
Q42. How do you redirect both stdout and stderr to a file? ANSWER
command > file 2>&1
Q43. What does command > /dev/null 2>&1 do? ANSWER It discards all
output (both stdout and stderr).
Q44. How do you append output to an existing file instead of overwriting?
ANSWER command >> filename
Q45. What command reads from standard input and writes to standard
output and files? ANSWER tee filename
PREP - VERIFIED ANSWERS AND QUESTIONS - MOST RECENT EDITION
2026/2027
Q1. What command displays the current working directory? ANSWER pwd
Q2. How do you list all files including hidden ones in a directory? ANSWER ls
-la or ls -a
Q3. What command changes directory to the parent directory? ANSWER cd ..
Q4. How do you create a new empty file? ANSWER touch filename
Q5. What command copies a file while preserving attributes? ANSWER cp -p
source destination
Q6. How do you move or rename a file? ANSWER mv oldname newname
Q7. What command removes a file forcefully without prompts? ANSWER rm
-f filename
Q8. How do you remove a directory and all its contents recursively? ANSWER
rm -rf directoryname
Q9. What command creates a new directory? ANSWER mkdir dirname
Q10. How do you create a nested directory structure in one command?
ANSWER mkdir -p /path/to/new/dir
Q11. What command displays the type of a file? ANSWER file filename
Q12. How do you find files by name in the current directory? ANSWER find . -
name "filename"
Q13. What command searches for files by type (e.g., regular files)? ANSWER
find /path -type f
Q14. How do you find files modified in the last 24 hours? ANSWER find /path
-mtime -1
,Q15. What command locates files by name using a prebuilt database?
ANSWER locate filename
Q16. How do you update the database used by locate? ANSWER updatedb
Q17. What command searches for text within files? ANSWER grep "pattern"
file
Q18. How do you perform a case-insensitive grep search? ANSWER grep -i
"pattern" file
Q19. What command recursively searches for text in all files under a
directory? ANSWER grep -r "pattern" /directory
Q20. How do you display only the count of matching lines in grep? ANSWER
grep -c "pattern" file
File Viewing & Manipulation
Q21. What command displays the first 10 lines of a file? ANSWER head
filename
Q22. How do you display the first 20 lines of a file? ANSWER head -n 20
filename
Q23. What command shows the last 10 lines of a file? ANSWER tail filename
Q24. How do you continuously monitor a log file for new entries? ANSWER
tail -f /var/log/file.log
Q25. What command displays file contents page by page? ANSWER less
filename
Q26. How do you display the entire contents of a file? ANSWER cat filename
Q27. What command numbers all output lines including blank ones?
ANSWER cat -n filename
Q28. How do you concatenate multiple files into one? ANSWER cat file1 file2
> combined
Q29. What command displays lines in reverse order (last line first)? ANSWER
tac filename
Q30. How do you sort lines in a file alphabetically? ANSWER sort filename
, Q31. What command sorts numerically instead of alphabetically? ANSWER
sort -n filename
Q32. How do you remove duplicate lines from sorted output? ANSWER sort
filename | uniq
Q33. What command counts lines, words, and bytes in a file? ANSWER wc
filename
Q34. How do you count only the number of lines in a file? ANSWER wc -l
filename
Q35. What command compares two files line by line? ANSWER diff file1 file2
Q36. How do you create a patch file from diff output? ANSWER diff -u file1
file2 > patchfile
Q37. What command applies a patch file? ANSWER patch < patchfile
Q38. How do you extract a specific column from text output? ANSWER awk
'{print $1}' filename or cut -d' ' -f1 filename
Q39. What command replaces text in a stream? ANSWER sed 's/old/new/g'
filename
Q40. How do you edit a file in-place with sed? ANSWER sed -i 's/old/new/g'
filename
Text Processing & Streams
Q41. What is the purpose of the pipe operator |? ANSWER It sends the
output of one command as input to another command.
Q42. How do you redirect both stdout and stderr to a file? ANSWER
command > file 2>&1
Q43. What does command > /dev/null 2>&1 do? ANSWER It discards all
output (both stdout and stderr).
Q44. How do you append output to an existing file instead of overwriting?
ANSWER command >> filename
Q45. What command reads from standard input and writes to standard
output and files? ANSWER tee filename