Danh mục

Linux all in one desk reference for dummies phần 3

Số trang: 47      Loại file: pdf      Dung lượng: 1.36 MB      Lượt xem: 13      Lượt tải: 0    
Thư viện của tui

Phí tải xuống: 16,000 VND Tải xuống file đầy đủ (47 trang) 0
Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu linux all in one desk reference for dummies phần 3, công nghệ thông tin, hệ điều hành phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Linux all in one desk reference for dummies phần 3160 Discovering and Using Linux Commands The Linux wc command comes to the rescue. The wc command displays the total number of characters, words, and lines in a text file. For example, type wc /etc/inittab and you see an output similar to the following: 75 304 2341 /etc/inittab In this case, wc reports that 75 lines, 304 words, and 2341 characters are in the /etc/inittab file. If you simply want to see the number of lines in a file, use the -l option and type wc -l /etc/inittab. The resulting output should be similar to the following: 75 /etc/inittab As you can see, with the -l option, wc simply displays the line count. If you don’t specify a filename, the wc command expects input from the stan- dard input. You can use the pipe feature of the shell to feed the output of another command to wc, which can be handy sometimes. Suppose you want a rough count of the processes running on your system. You can get a list of all processes with the ps ax command, but instead of counting lines manually, just pipe the output of ps to wc and you get a rough count automatically: ps ax | wc -l 76 Here the ps command produced 76 lines of output. Because the first line simply shows the headings for the tabular columns, you can estimate that about 75 processes are running on your system. (Of course, this count prob- ably includes the processes used to run the ps and wc commands as well, but who’s really counting?) Sorting text files You can sort the lines in a text file by using the sort command. To see how the sort command works, first type more /etc/passwd to see the current contents of the /etc/passwd file. Now type sort /etc/passwd to see the lines sorted alphabetically. If you want to sort a file and save the sorted version in another file, you have to use the Bash shell’s output redirection feature like this: sort /etc/passwd > ~/sorted.text This command sorts the lines in the /etc/passwd file and saves the output in a file named sorted.text in your home directory. TEAM LinG - Live, Informative, Non-cost and Genuine ! 161 Discovering and Using Linux CommandsSubstituting or deleting characters from a fileAnother interesting command is tr — it substitutes one group of charactersfor another (or deletes a selected character) throughout a file. Supposethat you occasionally have to use MS-DOS text files on your Linux system.Although you may expect to use a text file on any system without any prob-lems, you find one catch: DOS uses a carriage return followed by a line feedto mark the end of each line, whereas Linux uses only a line feed.On your Linux system, you can get rid of the extra carriage returns in the DOStext file by using the tr command with the -d option. Essentially, to convertthe DOS text file filename.dos to a Linux text file named filename.linux,type the following: Book II Chapter 2tr -d ‘15’ < filename.dos > filename.linuxIn this command, ‘15’ denotes the code for the carriage-return character Commanding the Shellin octal notation.Splitting a file into several smaller filesThe split command is handy for those times when you want to copy a fileto a floppy disk, but the file is too large to fit on a single floppy. You can thenuse the split command to break up the file into multiple smaller files, eachof which can fit on a floppy.By default, split puts 1,000 lines into each file. The files are named bygroups of letters such as aa, ab, ac, and so on. You can specify a prefix forthe filenames. For example, to split a large file called hugefile.tar intosmaller files that fit into several high-density 3.5-inch floppy disks, use splitas follows:split -b 1440k hugefile.tar part.This command splits the hugefile.tar file into 1440K chunks so eachone can fit onto a floppy disk. The command creates files named part.aa,part.ab, part.ac, and so on.To combine the split files back into a single file, use the cat command asfollows:cat part.?? > hugefile.tarIn this case, the two question marks (??) match any two character extensionin the filename. In other words, the filename part.?? would match all file-names s ...

Tài liệu được xem nhiều: