Prepare Smarter for the 101-500 Exam
Build your exam confidence with flexible preparation resources designed around the latest 101-500 exam objectives. Practice at your own pace using PDF questions, online exam simulations, or desktop practice software.
Which of the following commands replaces each occurrence of ' bob ' in the file letter with ' Bob ' and writes the
result to the file newletter?
Correct Answer: D
The command that replaces each occurrence of ‘bob’ in the file letter with ‘Bob’ and writes the result to the file newletter is sed ‘s/bob/Bob/g’ letter > newletter. This command uses the following options and syntax:
s: Specifies the substitution operation.
/: Separates the pattern and the replacement strings.
bob: The pattern to be searched and replaced.
Bob: The replacement string.
g: The global flag that indicates all occurrences of the pattern in each line should be replaced, not just the first one.
letter: The name of the input file.
: Redirects the output to a file.
newletter: The name of the output file.
The output of this command will be a new file called newletter that contains the same text as letter, except that every ‘bob’ is replaced by ‘Bob’. For example, if the file letter contains the following text:
Dear bob, I hope this letter finds you well. I am writing to inform you that your subscription to our magazine has expired. If you wish to renew it, please send us a check for $50 by the end of this month. Otherwise, we will have to cancel your subscription and remove you from our mailing list. Thank you for your cooperation and support. Sincerely, Alice
The file newletter will contain the following text:
Dear Bob, I hope this letter finds you well. I am writing to inform you that your subscription to our magazine has expired. If you wish to renew it, please send us a check for $50 by the end of this month. Otherwise, we will have to cancel your subscription and remove you from our mailing list. Thank you for your cooperation and support. Sincerely, Alice
The other commands are incorrect for the following reasons:
A. sed ‘/bob/Bob’ letter > newletter: This command is missing the s option and the second / delimiter, and will produce an error message.
B. sed s/bob/Bob/ letter < newletter: This command is using the wrong redirection operator ( < instead of > ), and will try to read the input from newletter instead of letter, and write the output to the standard output instead of newletter.
C. sed’s/bob/Bob’ letter > newletter: This command is missing a space between sed and the first ' , and will produce an error message.
E. sed ‘s/bob, Bob/’ letter > newletter: This command is using a comma (,) instead of a slash (/) as a delimiter, and will produce an error message.
After moving data to a new filesystem, how can the former path of the data be kept intact in order to avoid
reconfiguration of existing applications? (Choose TWO correct answers.)
Correct Answer: C, E
The former path of the data can be kept intact by creating a symbolic link from the old to the new path of the data or by mounting the new filesystem on the original path of the data. A symbolic link is a special file that points to another file or directory. It can be used to create a shortcut to the new location of the data without changing the applications that access it. Mounting the new filesystem on the original path of the data means that the data will appear as if it is still in the same location, but it is actually stored on a differ ent device or partition. This can be done by editing the /etc/fstab file or using the mount command. References :
[LPI Linux Essentials - 1.3 Basic File Management]
[LPI Linux Essentials - 1.4 Finding Files]
[LPI Linux Essentials - 2.1 Using Devices, Linux Filesystems, Filesystem Hierarchy Standard]
[LPI Linux Essentials - 2.2 Mounting, Unmounting Filesystems]
[LPI Linux Essentials - 2.3 Disk Partitions]
Which of the following commands overwrites the bootloader located on /dev/sda without overwriting the partition
table or any data following it?
Correct Answer: C
The dd command is used to copy data from one device or file to another, with optional parameters to specify the block size (bs), the number of blocks to copy (count), and other options. The bootloader is typically located in the first 440 bytes of the disk, which is the Master Boot Record (MBR) area. The MBR also contains the partition table, which starts at byte 446 and occupies 64 bytes. Therefore, to overwrite the bootloader without affecting the partition table or any data following it, the command should copy 440 bytes from /dev/zero (a special device that provides null bytes) to /dev/sda (the disk device) and stop after one block. This is achieved by the command: dd if=/dev/zero of=/dev/sda bs=440 count=1 References:
LPI Exam 101 Detailed Objectives , section 1.101.3
dd man page
Master Boot Record
Which of the following commands prints all files and directories within the /tmp directory or its subdirectories
which are also owned by the user root? (Choose TWO correct answers.)
Correct Answer: A, C
The find command is used to search for files and directories that match certain criteria. The -uid option specifies the numeric user ID of the owner of the file or directory, while the -user option specifies the name of the owner. The -print option prints the full file name of the matching file or directory to the standard output. Therefore, both find /tmp -uid root -print and find /tmp -user root -print will print all files and directories within the /tmp directory or its subdirectories which are also owned by the user root. The other options are either invalid or do not perform the desired task. The -path option matches the whole path name, not just the starting directory. The -print option is implied if no other action is specified, but it is good practice to include it for clarity. References:
LPIC-1 Exam 101 Objectives , Topic 103: GNU and Unix Commands, 103.4 Use streams, pipes and redirects
LPIC-1 Linux Administrator 101-500 Exam FAQ , LPIC-1 Exam 101 Objectives, GNU and Unix Commands (Total Weight: 25)
Which of the following partition types is used for Linux swap spaces when partitioning hard disk drives?
Correct Answer: A
Linux swap spaces are designated as type 82 on MBR (Master Boot Record) partition tables, which are used to store information about the partitions on a hard disk drive. This type code identifies the partition as a Linux swap area, which can be used by the Linux kernel to supplement the system RAM by holding idle memory pages. The mkswap command can be used to initialize a partition of type 82 as a swap partition. Other type codes are used for different purposes, such as 83 for Linux native partitions, 8e for Linux LVM partitions, fd for Linux RAID partitions, and 7 for NTFS partitions. References:
How to create swap partition in Linux
Choosing partition types for swap and root and choosing device for bootloader installation
Creating and Using a Swap Partition
Swap