Study Guide - Chap3: Managing Files, Directories, and Text Flashcards

(20 cards)

1
Q

1- 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?

  • mkdir -v
  • ls
  • ls -F
  • ls -i
  • ll
A

ls -F

Option C will append an indicator code of / to every directory name, so therefore it is the best choice. The mkdir -v command creates a directory and lets you know whether or not it was successful, but it does not indicate directories, so option A is a wrong answer. The ls command only displays file and directory names, so option B is also a wrong answer. The ls -i command will display filenames along with their inode number, but it does not indicate directories, so option D is incorrect. While option E will work on some distributions to produce a long listing that can indicate directories, this command is not aliased to ls -l on every distribution, so therefore it is not the best command to use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

2- 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
  • -d
  • -F
  • -l
  • -R
A

-d

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. Option A is a wrong answer because the -a switch forces the ls command to display hidden files, which are files starting with a dot (.). The -F switch will append an indicator code to each file but not allow you to view a directory’s metadata, so option C is a wrong choice. The -l option is already being employed because you are viewing metadata, so it does not need to be added. Therefore, option D is an incorrect answer. The -R switch allows you to view file information recursively through a directory tree, and thus option E is also a wrong choice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

5- 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 and still indicate that you are removing the correct directory, but without forcing you to confirm every file deletion?

  • cp -R /home/Zoe/ /dev/null/
  • mv -R /home/zoe/ /dev/null/
  • rm -Rf /home/Zoe/
  • rm -ri /home/Zoe/
A

rm -rI /home/Zoe

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. Option A is incorrect because the cp command simply copies files; it does not remove them. Option B is incorrect because not only is part of the directory name using the wrong case, but there is no verification the correct directory is being moved to the black hole device, /dev/null/. The rm -Rf command would work, but it is not the best command to use because it does not ask before it starts, so you do not know if you are deleting the correct tree. In fact, the -f option suppresses error messages, so option C is wrong. Option D would also work, but it is not the best answer because it employs the -i option. If Zoe has years of files in her home directory, you may be sitting there for a long time deleting files due to the fact that you must confirm each file before it is deleted. Therefore, option D is an incorrect answer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

6- There is a large directory structure that needs to be renamed. What mv command options should you consider employing? (Choose all that apply.)

  • -f
  • -i
  • -n
  • -r
  • -v
A
  • -i
  • -n
  • -v

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 what is going on. Therefore, options B, C, and E are all correct choices. The -f option is not a wise choice because it forces the directory’s renaming, even if a directory already exists that has that name. Therefore, option A is a wrong answer. Also, there is no -r switch, because renaming a directory using the mv command does not require any recursive action. Thus, option D is an incorrect choice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

7- ou are trying to decide whether to use a hard link or a symbolic link for a data file. The file is 5 GB, has mission‐critical data, and is accessed via the command line by three other people. What should you do?

  • Create a hard link so that the file can reside on a different filesystem for data protection.
  • Create three hard links and provide the links to the three other people for data protection.
  • Create three symbolic links and protect the links from the three other people for data protection.
  • Create a symbolic link so that the file can reside on a different filesystem.
  • Create a symbolic link so that the links can share an inode number.
A

Create three hard links and provide the links to the three other people for data protection.

Option B is the correct answer because the hard links will prevent the three other command‐line interface users from accidentally deleting the data. If they delete their link’s name, they will not delete the data. Option A is an incorrect choice because hard‐linked files must reside on the same filesystem together. Option C is also an incorrect choice because if you do not provide the symbolic links to the other three data users, they will have to access the data file directly and could delete it. While creating symbolic links will protect the data by letting it reside on a different filesystem, if it is mission‐critical data, the filesystem employed should be rigorous enough to protect the data, and therefore your only threat would be human. Thus, option D is an incorrect answer. Symbolic linked files do not share an inode number. Therefore, option E is an incorrect choice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Hard link

A

A direct reference to the file’s data on disk (inode). Multiple hard links point to the same physical file content, and deleting one hard link doesn’t affect the others until all hard links are removed.

Key difference from symbolic link: Hard links share the same inode and file data, while symbolic links are separate files that just contain a path reference to another location in the filesystem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Symbolic link

A

aka symlink: A special file that contains a path pointing to another file or directory. It’s like a shortcut - if you delete the original file, the symlink becomes broken, and if you move the original file, the symlink may no longer work.

Key difference from symbolic link: Hard links share the same inode and file data, while symbolic links are separate files that just contain a path reference to another location in the filesystem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

8- 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?

  • cat -v
  • cat -z
  • cat -n
  • cat -s
  • cat -E
A

cat -v

The cat -v command will show any nonprinting characters that may have gotten embedded in the control file causing it to be corrupted, and therefore option A is the correct answer. The -z option only lets you see end‐of‐line characters if they are NULL, and thus, option B is a wrong choice. The -n option only numbers the text lines in output, so option C is also a wrong answer. The cat -s command will display multiple blank lines in the file as one blank line. This will not help in the investigation, so option D is an incorrect answer. The -E option displays a $ whenever a newline linefeed is encountered, and while possibly helpful, it is not the best option to use in this case. Therefore, option E is a wrong answer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Control Codes

A
  • non-printing ASCII characters (values 0-31 and 127) that provide instructions to devices or programs rather than displaying visible text. Examples include newline (\n), carriage return (\r), tab (\t), and backspace.
  • In files: Control codes can accidentally get inserted during editing, file transfers, or encoding conversions, causing programs to misinterpret the file even though the visible text appears correct.
  • Common problems: Mixed line endings (Windows CRLF vs Linux LF), stray null bytes, or escape sequences can make configuration files unreadable to programs that expect clean text formatting.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

9- 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?

  • pr -m
  • pr -tl 20
  • cat
  • pr -mtl 20
  • pr -ml 20
A

pr -mtl 20

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 on your screen’s resolution. Option A is incorrect because, while it will display the files side by side, the display may scroll off your screen. Option B is also incorrect, because the command will not display your files side by side. Option C is a wrong answer choice because the cat command will not display the files side by side. Option E’s command may work for you, but it is not the best choice because file headers or trailers will not be removed. Therefore, option E is an incorrect answer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

pr

A
  • formats text files for printing by adding headers, page numbers, line numbers, and organizing content into columns or pages with proper spacing and margins.
  • Key features: Can split text into multiple columns (pr -2 file.txt), add line numbers (pr -n), create custom headers (pr -h “My Title”), and control page length and width for consistent formatting.
  • Common use: Often piped with lpr for printing (pr file.txt | lpr) or used to make plain text files more readable and organized before viewing or printing them.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

11- 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?

  • Employ the tail command to peruse the text file.
  • Employ the cat command to view the text file.
  • Delete the text file and regenerate it using information from the failed login attempts file.
  • Issue the grep -d skip Hal command on the text file.
  • Issue the grep -i Hal command on the text file.
A

Issue the grep -i Hal command on the text file.

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. Thus, option E is the correct answer. Option A is a wrong choice because the tail command will not allow you to search the file. Option B is also an incorrect answer, because the cat command will just display the entire text file to the screen and is not an efficient method for finding a few text lines. While you may end up having to regenerate the text file, prior to doing so you should check for Hal, ignoring case. If you find the records, then you have saved yourself some time. Thus, option C is also a wrong choice. Finally, the -d skip option on the grep command allows the search to skip any directory files. This option is useless in this situation, and therefore option D is an incorrect answer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

13- Which of the following does not describe the less utility?

  • It does not read the entire file prior to displaying the file’s first page.
  • You can use the up and down arrow keys to move through the file.
  • You press the spacebar to move forward a page.
  • You can use the Esc+V key combination to move backward a page.
  • You can press the X key to exit from the utility.
A

You can press the X key to exit from the utility.

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. Option A is a wrong answer because less does not read the entire file prior to displaying the file’s first page. You can also employ the up and down arrow keys to traverse the file as well as the spacebar to move forward a page and the Esc+V key combination to move backward a page, so options B, C, and D are incorrect answers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

14- Which diff option is the best option to allow you to quickly determine if two text files are different from one another?

  • -e
  • -q
  • -s
  • -W
  • -y
A

-q

The -q (or –brief) option used with the diff command will allow you to quickly determine if two text files are different from each other. Thus, option B is the correct answer. The -e switch allows you to create an ed script to use later on, so option A is an incorrect choice. The -s option does allow you to see if the files are the same and shows a simple message stating this fact. However, it is focused on file differences, so it is not the best switch to use. Therefore, option C is also a wrong answer. The diff command’s -W option allows you to set a display width, and thus, option D is an incorrect choice. The -y switch displays the two files in two columns, so option E is also a wrong selection.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

15- 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?

  • Hit your up arrow key and press Enter.
  • Log out, log back in, and retry the command.
  • Enter the which diff command.
  • Enter the whereis diff command.
  • Reboot the server and retry the command.
A

Enter the which diff command.

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. Option A is not correct because these actions will simply recall the original diff command and try it again. Logging out and then back in again may reset some variables you accidentally created, but it is not a good first step in this troubleshooting process. Therefore, option B is a wrong answer. Entering the whereis diff command will provide additional information concerning the diff command, such as program location and source code file locations as well as man page locations. This additional information is not needed, so option D is an incorrect choice. Rebooting a server just because a command does not work is not a good first troubleshooting step. Therefore, option E is also a wrong answer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

16- 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?

  • The locate utility searches for only for directory names.
  • You did not employ the -d skip switch.
  • It is most likely because the locate database is corrupted.
  • You did not employ the appropriate regular expression.
  • It is due to file globbing on the pattern name.
A

It is due to file globbing on the pattern name.

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. The locate command will search for both file and directory names for specified patterns unless options are provided to modify this behavior. Therefore, option A is an incorrect answer. The locate command does not use the -d skip switch (the grep command does use it, though), and thus, option B is a wrong answer. Because the command operated normally, there is not a problem with the locate database, so option C is an incorrect choice. Also, a regular expression switch was not used in the locate command, so option D is also a wrong choice.

17
Q

17- 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?

  • Issue the sudo updatedb command.
  • Issue the locate -b fortytwo.db command.
  • Issue the locate -b ‘fortytwo.db’ command.
  • Download the file from the company’s local website again.
  • Issue the locate fortytwo.db command.
A

Issue the sudo updatedb command.

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 mlocate.db via the updatedb command, using super user privileges. Thus, option A is the correct answer. After you have updated the database, any of the commands in option B, C, or E should work fairly well, with option B’s command being the best choice. However, for the first step, options B, C, and E are wrong answers. Downloading the file again is tedious and time‐consuming and can possibly consume disk space unnecessarily. Therefore, option D is an incorrect choice.

18
Q

File globbing

A
  • the shell’s pattern matching feature that automatically expands wildcard characters into matching filenames. Common patterns include * (matches any characters), ? (matches single character), and [abc] (matches any character in brackets).
  • Examples: .txt matches all files ending in .txt, file?.log matches file1.log, file2.log etc., and [A-Z] matches files starting with uppercase letters.
  • Shell expansion: The shell performs globbing before passing arguments to commands, so when you type ls *.conf, the shell first expands this to all matching filenames, then passes that list to the ls command.
19
Q

18- 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?

  • find -r /etc -name main.conf
  • find / -name main.conf
  • find /etc -maxdepth -name main.conf
  • find /etc -name main.conf
  • find main.conf /etc
A

find /etc -name main.conf

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. Option A is incorrect because there is no -r switch, and no need for one. Option B is not the best command to use in this case because the starting directory is /, which is the root of the virtual directory structure. It is much better to start at the /etc directory, since the file is most likely located somewhere in that directory tree. Using the -maxdepth switch may hamper the search because it sets the subdirectory level to stop the search. Therefore, option C is a wrong answer. Option E is an incorrect choice, because the path and filename are flip‐flopped and the -name switch is missing.

20
Q

19- 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?

  • find / -name Michael
  • find / -user Michael
  • find / -mmin 1440
  • find ~ -user Michael
  • find / -nouser
A

find / -nouser

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. Option A is incorrect because the -name switch is for file names, not usernames. Option B is also an incorrect answer, because the -user switch is used to search for files owned by a particular account. Since Michael’s account was deleted, his username would no longer be associated with any files. Option C is a wrong answer because you do not know when his files may have experienced data changes, as indicated by the -mmin switch, and thus this is a bad method for trying to identify them. Option D is an incorrect choice because the find command is starting the search process in the user’s home directory instead of the root (/) of the virtual directory structure.