filename
where the result produces
filename
.gz
. The
116
◾
Linux with Operating System Concepts
compressed file cannot be viewed until it is decompressed. The decompression algorithm is
either
gunzip
or
gzip –d
and it will remove the .gz extension.
The bzip2 program uses the Burrows–Wheeler sorting algorithm combined with
Huffman codes for compression. There is a bzip program although it is based on the LZ77
and LZ78 algorithms. The bzip2 program operates much the same as gzip/gunzip with
the instruction being
bzip2
filename
which creates
filename
.bz2
. To decompress,
use either
bunzip2
or
bzip2 –d
. As with gunzip, these programs will remove the .bz2
extension.
There is also a zip program which is used to both bundle and compress files. Its format is
different because it produces a single bundled file in place of multiple input files.
zip
destination
.zip
sourcefile(s)
To unzip, use
unzip
filename
.zip
. The zip program uses the DEFLATE compres-
sion algorithm which combines both LZ77 and Huffman codes.
3.9 CHAPTER REVIEW
Concepts and terms introduced in this chapter:
• Absolute path—path from root to directory/file.
• Compression—reducing files’ sizes by either discarding data or replacing data with
replacement strings.
• Decompression—or uncompression, restoring the file to its original format. Only
lossless compressed files can be decompressed.
• Device driver—a program that permits the CPU to communicate with a hardware
device. The driver is installed as part of the operating system.
• Directory—a unit of organization which can contain files, subdirectories, and links.
• File—the basic unit of storage in the logical file system.
• File system—the collection of devices storing the files.
• Home directory—the directory reserved for the given user.
• Link—a pointer to an object in the file system.
• Logical file system—the user’s view of the file system consisting of files, directories,
paths, and partitions.
• Mounting—the act of making a file system accessible.
• Parent directory—the directory of which the current directory is contained.
• Partition—a logical way to separate groups of directories so that each partition can
be treated independently.
Navigating the Linux File System
◾
117
• PATH variable—an environment variable which stores the directories that the Bash
interpreter searches for an executable program when a command is entered.
• Permissions—access control to determine who can read, write, or execute a file or
directory.
• Physical file system—the physical mechanisms that implement the file system
including disk drives (and other storage devices); a file is stored in the physical file
system as a collection of blocks distributed across one or more devices, connected
by pointers.
• Recursive copy/delete—an operation to copy or delete not just the contents of a direc-
tory, but all subdirectories and their contents.
• Relative path—path specified from the current working directory.
• Top-level Linux directories—a standard collection of directories that help Linux
users and administrators know where to look.
• Wildcards—characters that can be used in Bash to specify multiple files such as *
matching all files and ? matching any one character of a file name.
• Working directory—the directory that the user is currently interacting in, reached
using cd commands.
Linux commands covered in this chapter:
• bzip2/bunzip2—compress/decompress files using Burrows–Wheeler and Huffman
codes.
• cat—concatenate files; often used to display files’ contents to the terminal window.
• cd—change the working directory.
• chmod—change the permissions of a file.
• comm—compare two sorted files, displaying all differences.
• cmp—compare two files, byte by byte, displaying the point where the two files differ.
• cp—copy one or more files or entire directories to another location.
• cut—remove portions of every line of a file.
• diff—compare two files and display their differences.
• file—output the type of entity passed as a parameter such as a text file, a directory, a
block device.
• find—locate files in the file system based on some criteria such as name, permissions,
owner, last access time.
118
◾
Linux with Operating System Concepts
• gzip/gunzip—compress/uncompress files using LZ77 and Huffman codes.
• head—display the first part of a file.
• join—join lines of files together which have a common value for one of its fields.
• less—display a file screen-by-screen; allows forward and backward movement.
• locate/slocate—locate files in the file system based on name; uses a preestablished
database of file names.
• ln—create a hard link; creates a symbolic link if you supply it with the option -s.
• ls—list the contents of the given or current directory.
• mkdir—create a new directory.
• more—display a file screen-by-screen; allows only forward movement.
• mv—move one or more files to a new location or rename a file.
• paste—unite files together by fields.
• pwd—print the current working directory.
• rm—delete one or more files; can delete directories if the -r recursive option is used.
• rmdir—delete an empty directory.
• sort—sort the contents of a file.
• split—split a file’s contents into multiple files.
• strings—output sequences of 4 or more printable characters found in non-text-based
files.
• tail—display the last part of a file.
• touch—create an empty text file.
• uniq—examine a file for duplicated consecutive lines.
• updatedb—create or update the file database as used with locate/slocate.
• wc—perform a character, word, and line count on the given file(s).
REVIEW QUESTIONS
1. Which of the following Linux file system commands can you issue
a. On a directory?
b. On a file?
ls cd mv rm cp sort touch less cat wc chmod
Navigating the Linux File System
◾
119
2. Referring to Figure 3.4, assume you are currently in the directory /
home/foxr/
temp2/a
.
a. Write an absolute path to take you to zappaf.
b. Write a relative path to take you to zappaf.
c. Write an absolute path to take you to etc.
d. Write a relative path to take you to etc.
3. You are user zappaf. You were in the directory /usr and then performed cd /home/
foxr/temp. What values would you find in these environment variables? PWD
OLDPWD HOME.
4. What is the difference between home/foxr and /home/foxr?
5. What does ~ represent? What does ~zappaf represent?
6. What is the difference between . and ..?
For questions 7 through 16, assume that the current directory contains the following items
(all of which are files):
abc.txt abc1.txt abb.txt bbb.txt bbb.dat bbb bbbb c123.txt ccc.txt
7. List the files that the following command will display: ls *
8. List the files that the following command will display: ls *.txt
9. List the files that the following command will display: ls a*.*
10. List the files that the following command will display: ls ab?.txt
11. List the files that the following command will display: ls bbb*
12. List the files that the following command will display: ls bbb.*
13. List the files that the following command will display: ls c??.txt
14. List the files that the following command will display: ls [ab][ab][ab].*
15. List the files that the following command will display: ls [a-c]??.???
16. List the files that the following command will display: ls [!c]*
17. Refer back to Figure 3.4. Assume that you are currently in the subdirectory
temp2
of
foxr
. Assume the subdirectory
a
contains five files and subdirectory
b
is empty.
a. What is the result of doing rmdir a?
b. What is the result of doing rmdir b?
c. What is the result of doing rm -ir a*?
d. How would rm -fr a* differ from rm -ir a* from part c?
120
◾
Linux with Operating System Concepts
For questions 18 through 21, assume the directory zappaf has the following partial
long listing:
-rw-rw-r-- zappaf zappaf . . . foo1.txt
-rw-rw-r-- zappaf zappaf . . . foo2.txt
-rw-rw---- zappaf zappaf . . . foo3.txt
18. Write a command, as foxr, to copy these files to foxr’s temp directory.
19. Will your command from 18 successfully copy all three files? Why or why not?
20. For your copy command from #18, what would differ if you added the option -p?
21. How does the command mv ~zappaf/foo1.txt. differ from the command mv ~zappaf/
foo1.txt foo4.txt?
22. The -f option in rm forces a file to be deleted without asking for permission. What
then does the -f option do for cp?
23. What is the difference between
tail –n 10
and
tail –n
+
10
when issued on a
file of 100 lines?
24. What is the difference between
tail –c 10
and
tail –n 10
when issued on a
file of 100 lines and 1000 characters?
25. Assume you have two files that are nearly identical. To view the differences between
them, which file comparison program should you use?
26. Assume you have two files that are sorted. To view the differences between them,
which file comparison program should you use?
27. Which of the file comparison programs can compare one file to several other files?
28. How does uniq differ from diff and cmp?
Assume you have two files: names.txt and phone.txt which each contain enumerated
(numbered) lists of names (names.txt) and phone numbers (phone.txt). We assume that
the
Do'stlaringiz bilan baham: |