Linux Command Line 2

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Tpotter
T
Tpotter
Community Contributor
Quizzes Created: 2 | Total Attempts: 4,391
| Attempts: 553 | Questions: 23
Please wait...
Question 1 / 23
0 %
0/100
Score 0/100
1. What command lists files in current directory?

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.

Submit
Please wait...
About This Quiz
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... see moreknow. see less

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

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.

Submit
3. What is the command to create an empty file named 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.

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

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.

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

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.

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

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.

Submit
7. What is the command to forcibly delete all files in the current directory ending in .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.

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

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.

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

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".

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

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.

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

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.

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

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.

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

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.

Submit
14. 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).

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.

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

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.

Submit
16. From the root directory, find files in /var/test/ directory with the name 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.

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

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.

Submit
18. How do you find files in your current directory that are world writable.

Note: use short syntax (ogw)

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.

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

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.

Submit
20. What is the command to display the first 5 lines of /var/test/data/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.

Submit
21. Which methods are correct for querying 10.2.4.42 for the ip address of 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.

Submit
22.   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.

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.

Submit
23. 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.

Explanation

Your answer should be the line from the file. Not the command itself.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

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
Cancel
  • All
    All (23)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What command lists files in current directory?
What command lists files in current directory including owner and...
What is the command to create an empty file named emptyfile.txt?
If you are in your home directory, how do you list files with user,...
How do you view the last 100 lines of a file?
How do you view the entire contents of a file and make each line...
What is the command to forcibly delete all files in the current...
What is the command to view data in real time as it is being added to...
What is the dig command to get a hostname by supplying the ipaddress?
What is the command to update all software packages on a server?
If you are in your home directory, how do you list list files in the...
What is the command to forcibly delete all files in the current...
Which commands will list all files and folders in your home directory.
Using tail and grep, how do you view only lines with the word ERROR as...
How do you find files in your current directory modified more than 48...
From the root directory, find files in /var/test/ directory with the...
How do you find files in your current directory modified less than 60...
How do you find files in your current directory that are world...
How do you list files in your current directory and all files 2 levels...
What is the command to display the first 5 lines of...
Which methods are correct for querying 10.2.4.42 for the ip address of...
  Assuming you are in the folder /var/test/data/,...
What is the command to find the line with "ERROR" in the file...
Alert!

Advertisement