Linux Command Line 2

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Tpotter
T
Tpotter
Community Contributor
Quizzes Created: 2 | Total Attempts: 4,337
Questions: 23 | Attempts: 534

SettingsSettingsSettings
Linux Command Line 2 - Quiz

Command line.
Several of the questions require you to log into the training server to get your answers. If you have any problems or need help, let me know.


Questions and Answers
  • 1. 

    What command lists files in current directory?

    Correct Answer(s)
    ls
    ls -l
    ls -la
    Explanation
    The "ls" command is used to list files in the current directory. It displays the names of all files and directories in the current directory. The "ls -l" command provides a detailed listing of the files, including their permissions, owner, size, and modification date. The "ls -la" command lists all files, including hidden files, in a long format.

    Rate this question:

  • 2. 

    What command lists files in current directory including owner and group information?

    Correct Answer(s)
    ls -l
    ls -la
    Explanation
    The command "ls -l" lists files in the current directory along with detailed information such as the owner and group of each file. The option "-l" stands for "long format" and provides a detailed listing of files. The command "ls -la" also lists files in the current directory, including hidden files, and provides detailed information about each file, including the owner and group.

    Rate this question:

  • 3. 

    If you are in your home directory, how do you list list files in the current directory and sub directories?

    Correct Answer(s)
    ls -R
    find .
    find ./
    find *
    Explanation
    The command "ls -R" lists all files in the current directory and its subdirectories recursively. Similarly, the command "find ." lists all files in the current directory and its subdirectories. The commands "find ./" and "find *" also achieve the same result.

    Rate this question:

  • 4. 

    If you are in your home directory, how do you list files with user, group and size of file including hidden files?

    Correct Answer(s)
    ls -la
    Explanation
    The command "ls -la" is used to list all files in the current directory, including hidden files. The "-l" flag displays the files in a long format, which includes information such as the user and group ownership, file permissions, and file size. The "-a" flag shows all files, including hidden files that start with a dot. Therefore, "ls -la" is the correct command to list files with user, group, and size, including hidden files, in the home directory.

    Rate this question:

  • 5. 

    How do you list files in your current directory and all files 2 levels deep?

    Correct Answer(s)
    find -maxdepth 2
    find . -maxdepth 2
    find * -maxdepth 2
    Explanation
    All three options are correct for listing files in the current directory and all files 2 levels deep. The "find -maxdepth 2" option will search for files in the current directory and its immediate subdirectories up to a depth of 2. The "find . -maxdepth 2" option is similar, but explicitly specifies the current directory as the starting point. The "find * -maxdepth 2" option will search for files in the current directory and its immediate subdirectories up to a depth of 2, but using the wildcard character "*" instead of explicitly specifying the current directory.

    Rate this question:

  • 6. 

    From the root directory, find files in /var/test/ directory with the name test3.txt

    Correct Answer(s)
    find /var/test/ -name test3.txt
    find /var/test/ -iname test3.txt
    find /var/test/ | grep test3.txt
    Explanation
    The correct answer is "find /var/test/ -name test3.txt, find /var/test/ -iname test3.txt, find /var/test/ | grep test3.txt". These three commands will search for files in the /var/test/ directory with the name "test3.txt". The first command, "find /var/test/ -name test3.txt", will perform a case-sensitive search for files with the exact name "test3.txt". The second command, "find /var/test/ -iname test3.txt", will perform a case-insensitive search for files with the name "test3.txt". The third command, "find /var/test/ | grep test3.txt", will search for files in the /var/test/ directory and its subdirectories, and then filter the results to only show files that contain the text "test3.txt" in their names.

    Rate this question:

  • 7. 

    How do you find files in your current directory modified more than 48 hours ago

    Correct Answer(s)
    find . -mtime 2
    find * -mtime 2
    find ./* -mtime 2
    find ./ -mtime 2
    Explanation
    The correct answer is any of the given options: "find . -mtime 2", "find * -mtime 2", "find ./* -mtime 2", or "find ./ -mtime 2". These commands use the "find" command in Unix/Linux to search for files in the current directory that have been modified more than 48 hours ago. The "-mtime 2" option specifies that it should look for files modified exactly 2 days ago. The dot (.) represents the current directory, while the asterisk (*) represents all files and directories in the current directory. The "./" and "./*" options are alternative ways to represent the current directory.

    Rate this question:

  • 8. 

    How do you find files in your current directory modified less than 60 minutes ago.

    Correct Answer(s)
    find . -mmin -60
    find * -mmin -60
    find ./ -mmin -60
    Explanation
    The correct answer is any of the three options: "find . -mmin -60", "find * -mmin -60", or "find ./ -mmin -60". These commands use the "find" utility to search for files in the current directory that have been modified within the last 60 minutes. The dot (.) represents the current directory, the asterisk (*) represents all files in the current directory, and the "./" specifies the current directory explicitly. The "-mmin -60" flag is used to search for files modified less than 60 minutes ago.

    Rate this question:

  • 9. 

    How do you find files in your current directory that are world writable.Note: use short syntax (ogw)

    Correct Answer(s)
    find . -perm -o+w
    find * -perm -o+w
    Explanation
    The correct answer is "find . -perm -o+w, find * -perm -o+w". These commands are used to find files in the current directory that are world writable. The "find . -perm -o+w" command searches for files starting from the current directory (represented by the dot) and checks for permissions that allow others to write to the file. The "find * -perm -o+w" command searches for files in the current directory only (not including subdirectories) and checks for the same world writable permissions.

    Rate this question:

  • 10. 

    Which commands will list all files and folders in your home directory.

    • A.

      Ls ~

    • B.

      Dir ~

    • C.

      Ls -la ~

    • D.

      Ls -la ~/*

    • E.

      Find ~

    Correct Answer
    C. Ls -la ~
    Explanation
    The command "ls -la ~" is the correct answer because "ls" is the command to list files and folders, "-la" is used to display all files including hidden ones and provide detailed information, and "~" represents the home directory. Therefore, "ls -la ~" will list all files and folders in the home directory, including hidden files.

    Rate this question:

  • 11. 

    How do you view the entire contents of a file and make each line display the line number?

    Correct Answer
    cat -n
    Explanation
    The command "cat -n" is used to view the entire contents of a file and display each line with its corresponding line number. The "cat" command is used to concatenate and display files, and the "-n" option adds line numbers to the output. So, when you run "cat -n" followed by the file name, it will display the contents of the file with line numbers for each line.

    Rate this question:

  • 12. 

    How do you view the last 100 lines of a file?

    Correct Answer
    tail -100
    Explanation
    The command "tail -100" is used to view the last 100 lines of a file. The "tail" command displays the last part of a file by default, and the "-100" option specifies the number of lines to be displayed. This command is useful when you want to quickly check the most recent entries in a log file or any other file where the most recent information is at the end.

    Rate this question:

  • 13. 

    What is the command to find the line with "ERROR" in the file /var/test/data/test. Copy the results of the command into your answer.

    Correct Answer
    May 4 09:52:54 localhost ERROR: bound to find this error.
    May 4 09:52:54 localhost ERROR: bound to find this error.
    Explanation
    Your answer should be the line from the file. Not the command itself.

    Rate this question:

  • 14. 

      Assuming you are in the folder /var/test/data/, what is the command to find the line with "ERROR" in the file /var/test/data/test and in all files in folders below /var/test/data/. Enter the command into your answer.

    Correct Answer
    grep -R ERROR *
    grep -R ERROR .
    grep -r ERROR *
    grep -r ERROR .
    Explanation
    The correct answer is "grep -R ERROR *". This command will search for the word "ERROR" in the file "test" located in the current directory (/var/test/data/) as well as in all files in subdirectories below it. The "-R" flag tells grep to search recursively, the "ERROR" is the pattern to search for, and the "*" represents all files and directories in the current directory.

    Rate this question:

  • 15. 

    What is the command to forcibly delete all files in the current directory?

    Correct Answer
    rm -f *
    rm --force *
    rm -f ./*
    Explanation
    The command "rm -f *" is the correct answer because it uses the "rm" command with the "-f" option, which forces the deletion of files without prompting for confirmation. The asterisk (*) is a wildcard character that represents all files in the current directory, so this command will delete all files in the current directory without any confirmation prompts. The other options, "rm --force *" and "rm -f ./*", are incorrect because they unnecessarily specify the current directory (./) and the double hyphen (--) is not required for the force option.

    Rate this question:

  • 16. 

    What is the command to forcibly delete all files in the current directory ending in .sh?

    Correct Answer
    rm -f *.sh
    rm --force *.sh
    rm -f ./*.sh
    Explanation
    The correct answer is "rm -f *.sh, rm --force *.sh, rm -f ./*.sh". These commands are used to forcibly delete all files in the current directory that end with .sh. The "-f" option is used to force the deletion without prompting for confirmation. The "*" wildcard is used to match any characters before the .sh extension, and the "./" specifies that the files should be deleted from the current directory. The "--force" option is an alternative to "-f" and achieves the same result.

    Rate this question:

  • 17. 

    What is the command to create an empty file named emptyfile.txt?

    Correct Answer
    touch emptyfile.txt
    Explanation
    The command "touch emptyfile.txt" is used to create an empty file named emptyfile.txt. The "touch" command is commonly used in Unix-based systems to update the access and modification timestamps of a file, but it can also be used to create a new file if it does not already exist. In this case, the command is used to create a new file named emptyfile.txt without any content in it.

    Rate this question:

  • 18. 

    What is the command to display the first 5 lines of /var/test/data/test ?

    Correct Answer
    head -50 /var/test/data/test
    head -50 test
    Explanation
    The correct answer is "head -50 /var/test/data/test". The "head" command is used to display the first few lines of a file. In this case, the "-50" option is used to specify that we want to display the first 50 lines. The file path "/var/test/data/test" indicates the location of the file we want to display the lines from. The second option "head -50 test" is incorrect as it does not specify the correct file path.

    Rate this question:

  • 19. 

    Which methods are correct for querying 10.2.4.42 for the ip address of lyris.com

    • A.

      Dig -x @10.2.4.42 lyris.com

    • B.

      Dig @10.2.4.42 lyris.com

    • C.

      Nslookup 10.2.4.42 lyris.com

    • D.

      Nslookup -10.2.4.42 lyris.com

    Correct Answer(s)
    B. Dig @10.2.4.42 lyris.com
    D. Nslookup -10.2.4.42 lyris.com
    Explanation
    The correct methods for querying the IP address of lyris.com from the DNS server at 10.2.4.42 are "dig @10.2.4.42 lyris.com" and "nslookup -10.2.4.42 lyris.com". The "dig" command is used to perform DNS queries, and by specifying the DNS server with the "@" symbol, we are querying the specific server at 10.2.4.42. Similarly, the "nslookup" command is used for DNS queries, and by using the "-" symbol before the IP address, we are specifying the DNS server at 10.2.4.42.

    Rate this question:

  • 20. 

    What is the dig command to get a hostname by supplying the ipaddress?

    Correct Answer(s)
    dig -x
    Explanation
    The dig command is used to perform DNS (Domain Name System) lookups. The -x option in the dig command is used to perform a reverse DNS lookup, which means it can be used to get the hostname by supplying the IP address. So, the correct answer is "dig -x".

    Rate this question:

  • 21. 

    What is the command to view data in real time as it is being added to a file (log file)

    Correct Answer(s)
    tail -f
    Explanation
    The command "tail -f" is used to view data in real time as it is being added to a file, specifically a log file. The "tail" command displays the last few lines of a file, and the "-f" option follows the file as it grows, continuously displaying newly added lines. This is particularly useful for monitoring log files, as it allows users to see the most recent updates without having to constantly refresh or reopen the file.

    Rate this question:

  • 22. 

    Using tail and grep, how do you view only lines with the word ERROR as they are being added to the file "test" (assuming test is a log file that is constantly being written to).

    Correct Answer(s)
    tail -f | grep ERROR
    tail -f|grep ERROR
    Explanation
    The correct answer is "tail -f | grep ERROR". This command will continuously display the contents of the "test" file as they are being written, and the "grep ERROR" part will filter out only the lines that contain the word "ERROR". This allows the user to view only the lines with the word "ERROR" in real-time from the constantly updating log file.

    Rate this question:

  • 23. 

    What is the command to update all software packages on a server?

    Correct Answer(s)
    yum update
    Explanation
    The command "yum update" is used to update all software packages on a server. Yum is a package management tool for RPM-based Linux distributions, such as Red Hat, CentOS, and Fedora. The "update" option tells yum to check for any available updates for installed packages and then install them. This command ensures that all software on the server is up to date, including security patches and bug fixes.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • May 04, 2009
    Quiz Created by
    Tpotter
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.