160 Discovering (Web design careers) and Using Linux Commands The Linux
160 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 standard 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 probably 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.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.