Linux + Chapter 3: Managing Files, Directories, and Text

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

A short text-based control file is no longer working properly with the program that reads it. You suspect the file was accidentally corrupted by a control code update you performed recently, even though the file's control codes are all correct. Which command should you use next on the file in your problem investigation? A. cat -v B. cat -z C. cat -n D. cat -s E. cat -E

A. The cat -v command will show any nonprinting characters that may have gotten embedded in the control file causing it to be corrupt, and therefore option A is the correct answer.

You downloaded a large important file, fortytwo.db, from your company's local website to your Linux server but got interrupted by an emergency. Now you cannot remember where you stored the file. What is the best first step to fixing this problem? A. Issue the sudo updatedb command. B. Issue the locate -b fortytwo.db command. C. Issue the locate -b 'fortytwo.db' command. D. Download the file from the company's local website again. E. Issue the locate fortytwo.db command.

A. The locate utility searches the mlocate.db database, which is typically only updated one time per day via a cron job. Therefore, for this newly created file, the first thing you should do is update the mlocate.db via the updatedb command, using super user privileges. Thus, option A is the correct answer.

You have just created an empty directory called MyDir. Which command most likely did you use? A. mkdir -v MyDir B. touch MyDir C. cp -R TheDir MyDir D. mv -r TheDir MyDir E. rmdir MyDir

A. The mkdir -v command creates a directory and lets you know whether or not it was successful, so option A is the correct answer.

There is a large directory structure that needs to be renamed. What mv command options should you consider employing? (Choose all that apply.) A. -f B. -i C. -n D. -r E. -v

B, C, E. When renaming a directory, you only need to employ the mv command. However, it is wise to use the -i option, so if the new directory name already exists, the utility will stop and ask permission prior to proceeding. Even better is to use the -n option; that way, if the new name you select is already being used, the mv command does not allow you to overwrite it. Also, the -v option is worthwhile, so the mv command operates in verbose mode, telling you want is going on. Therefore, options B, C, and E are all correct choices.

You are trying to peruse a rather large text file. A coworker suggests you use a pager. Which of the following best describes what your coworker is recommending? A. Use a utility that allows you to view the first few lines of the file. B. Use a utility that allows you to view one text page at time. C. Use a utility that allows you to search through the file. D. Use a utility that allows you to filter out text in the file. E. Use a utility that allows you to view the last few lines of the file.

B. A pager utility allows you to view one text page at a time and move through the text at your own pace. Therefore, option B is the correct answer.

You are trying to decide whether to use a hard link or a symbolic link for a data file. The file is 5GB, has mission-critical data, and is accessed via the command line by three other people. What should you do? A. Create a hard link so the file can reside on a different filesystem for data protection. B. Create three hard links and provide the links to the three other people for data protection. C. Create three symbolic links and protect the links from the three other people for data protection. D. Create a symbolic link so the file can reside on a different filesystem. E. Create a symbolic link so the links can share an inode number.

B. Option B is the correct answer because the hard links will prevent the three other command-line interface users from accidently deleting the data. If they delete their link's name, they will not delete the data.

You are using the ls command to look at a directory file's metadata but keep seeing metadata for the files within it instead. What command option will rectify this situation? A. -a B. -d C. -F D. -l E. -R

B. The -d switch on the ls command will allow you to view a directory file's metadata instead of seeing metadata for the files managed by that directory. Therefore, option B is the correct choice.

Which diff option is the best option to allow you to quickly determine if two text files are different from one another? A. -e B. -q C. -s D. -W E. -y

B. The -q (or --brief) option used with the diff command will allow you to quickly determine if two text files are different from one another. Thus, option B is the correct answer.

You are working on a Linux server at the command line, and you try to issue a diff command and receive a response stating that the command was not found. What is the next best step to take in order to start the troubleshooting process? A. Hit your up arrow key and press Enter. B. Log out, log back in, and retry the command. C. Enter the which diff command. D. Enter the whereis diff command. E. Reboot the server and retry the command.

C. Option C is the correct answer because the which command will allow you to quickly see the location of the program you provide as an argument. If you see no response, you can go on to the next troubleshooting step of determining if the program is not installed.

You are looking at a directory that you have not viewed in a long time and need to determine which files are actually directories. Which command is the best one to use? A. mkdir -v B. ls C. ls -F D. ls -i E. ll

C. Option C will append an indicator code of / to every directory name, so therefore it is the best choice.

You need to figure out what configuration file(s) hold a host name directive. Which of the following commands is the best one to use? A. which B. whereis C. grep D. locate E. find

C. The grep utility will allow you to search file contents quickly and effectively. Therefore, option C is the correct answer.

You have a lengthy file named, FileA.txt. What will the head -15 FileA.txt command do? A. Display all but the last 15 lines of the file. B. Display all but the first 15 lines of the file. C. Display the first 15 lines of the file. D. Display the last 15 lines of the file. E. Generate an error message

C. The head command can use either the -n 15 switch or the -15 switch to display a file's first 15 lines. Therefore, option C is the correct answer.

You have two short text files that have maximum record lengths of 15 characters. You want to review these files side by side. Which of the following commands would be the best to use? A. pr -m B. pr -tl 20 C. cat D. pr -mtl 20 E. pr -ml 20

D. Option D is the correct answer because the best command to use is the pr -mtl 20 command. This will display the files side by side, remove any file headers or trailers, and set the page length to 20 lines so the files do not scroll off your screen. Of course, you may need to adjust the line length depending upon your screen's resolution.

You want to search for a particular file, main.conf, using the find utility. This file most likely is located somewhere in the /etc/ directory tree. Which of the following commands is the best one to use in this situation? A. find -r /etc -name main.conf B. find / -name main.conf C. find /etc -maxdepth -name main.conf D. find /etc -name main.conf E. find main.conf /etc

D. When using the locate command, the path argument is listed first, which is a starting point directory. The find utility will search through that directory and all its subdirectories (recursively) for the file or files you seek. Also, the -name switch allows you to search for a file by name, so option D is the correct answer.

You are trying to find a file on your Linux server whose name is conf. Employing the locate conf command for your search shows many directories that contain the letters conf. What is the best description for why this is happening? A. The locate utility searches for only for directory names. B. You did not employ the -d skip switch. C. It is most likely because the locate database is corrupted. D. You did not employ the appropriate regular expression. E. It is due to file globbing on the pattern name.

E. By default, the locate command uses file globbing, which adds wildcards to the pattern you enter. Thus, conf is turned into *conf*. Therefore, option E best explains the results and is the correct answer.

You have issued the command grep Hal on a text file you generated using information from a failed login attempts file. It returns nothing, but you just performed a test case, by purposely failing to log into the Hal account, prior to generating the text file. Which of the following is the best choice as your next step? A. Employ the tail command to peruse the text file. B. Employ the cat command to view the text file. C. Delete the text file and regenerated it using information from the failed login attempts file. D. Issue the grep -d skip Hal command on the text file. E. Issue the grep -i Hal command on the text file.

E. It is possible that the account name Hal is listed in the generated text file as hal. Therefore, your best next step is to employ the -i option on the grep command. This will quickly search the text file for the word Hal, while ignoring case. Option E is the correct answer.

Yesterday a coworker, Michael, was fired for nefarious behavior. His account and home directory were immediately deleted. You need to audit the server to see if he left any files out in the virtual directory system. Which of the following commands is the best one to use in this situation? A. find / -name Michael B. find / -user Michael C. find / -mmin 1440 D. find ∼ -user Michael E. find / -nouser

E. The find / -nouser command will search through the entire virtual directory structure looking for any files that do not have a username associated with them. Since Michael's account and home directory were deleted, any files he owned out in the virtual directory structure will not have a username associated with them, only a user ID (UID). Thus, option E is the best answer.

A long-time server administrator has left the company, and now you are in charge of her system. Her old user account directory tree, /home/Zoe/, has been backed up. Which command is the best one to use to quickly remove her files? A. cp -R /home/Zoe/ /dev/null/ B. mv -R /home/zoe/ /dev/null/ C. rm -Rf /home/Zoe/ D. rm -ri /home/Zoe/ E. rm -rI /home/Zoe

E. The rm -rI command will recursively delete the files in the /home/Zoe directory tree, and it will ask before it starts, so you know you are deleting the correct tree. Therefore, option E is the best answer.

You have a file that is over 10GB in size, and it needs to be backed up to a locally attached drive. What is the best utility to use in this situation? A. readlink -f B. mv C. cp D. scp E. rsync

E. The rsync utility allows you to perform fast local copies, so for a big file it is the best utility to use in this case. Therefore, option E is the correct answer.

Which of the following does not describe the less utility? A. It does not read the entire file prior to displaying the file's first page. B. You can use the up and down arrow keys to move through the file. C. You press the spacebar to move forward a page. D. You can use the Esc+V key combination to move backward a page. E. You can press the X key to exit from the utility.

E. You need to use the q key to exit from the less pager utility; therefore, only option E does not describe less and is the correct answer.

Describe both structures and commands involved in linking files.

Linking files is rather easy to do with the ln command. However, it is important for you to describe the underlying link structure. Hard linked files share the same inode number, while soft linked files do not. Soft or symbolic links can be broken if the file they link to is removed. It is also useful to understand the readlink utility to help you explore files that have multiple links.

Describe how to find information on your Linux system.

To determine two text files' differences, the diff utility is helpful. With this utility, you can also employ redirection and modify the files to make them identical. When you need to quickly find files on your system and want to use simple tools, the which, whereis, and locate commands will serve you well. Keep in mind that the locate utility uses a database that is typically updated only one time per day, so you may need to manually update it via the updatedb command. When simple file location tools are not enough, there are more complex searching utilities, such as find and grep. The grep command can employ regular expressions to assist in your search.

Summarize the various utilities that can be employed to read text files.

To read entire text files, you can use the cat, bat, and pr utilities. Each utility has its own special features. If you only need to read the first or last lines of a text file, employ either the head or tail command. For a single text line out of a file, the grep utility is useful. For reviewing a file a page at a time, you can use either the less or the more pager utility.

Explain basic commands for handling files and directories.

Typical basic file and directory management activities include viewing and creating files, copying and moving files, and deleting files. For viewing and creating files and directories, use the ls, touch, and mkdir commands. When needing to duplicate, rename, or move files, employ one of the mv, cp, or rsync commands. For local large file copies, the rsync utility is typically the fastest. You can quickly delete an empty directory using the rmdir utility, but for directories full of files, you will need to use the rm -r command. Also, if you need to ensure that you are removing the correct files, be sure to use the -i option on the rm utility.


Ensembles d'études connexes

Science ESG- Loss of Biodiversity

View Set

B2 LS Grammar: Simple Past Tense - Irregular Verbs (Group 2)

View Set

amy 47 cardiac questions REVIEW again-most were on last exam

View Set

International Business Law EXAM FOUR

View Set

Bronfenbrenner's Ecological Systems Theory

View Set

Олимпиада на платформе uchi.ru

View Set

Maternity and pedi ch 2,3,4,5,6,7, review

View Set

Vocabulary ATOMS, Molecules Ions and Isotopes

View Set

C836 - Fundamentals of Information Security Study Notes

View Set