Question
A Linux systems administrator needs to extract the contents of a file named /home/dev/web.bkp to the /var/www/html/ directory. Which of the following commands should the administrator use?
- A. cd /var/www/html/ && gzip -c /home/dev/web.bkp | tar xf -
- B. pushd /var/www/html/ && cpio -idv < /home/dev/web.bkp && popd Correct
- C. tar -c -f /home/dev/web.bkp /var/www/html/
- D. unzip -c /home/dev/web.bkp /var/www/html/
Explanation
pushd changes into /var/www/html/, cpio -idv reads the archive from standard input and extracts it (-i) into the current directory, creating directories as needed (-d), and popd returns to the previous directory. Option A compresses the file with gzip -c instead of decompressing it, so tar receives gzip data rather than an archive. Option C creates a new archive (-c) and would overwrite the backup, and unzip -c only prints the files to standard output instead of extracting them to the directory.