previous contents up next

Unix for Advanced Users

6. Manipulating Files

6.2.4. What files do I have? How big are they? ls, wc

6.2.4.1. ls

ls is an abbreviation for list, and it does just that: It lists the files in a directory. As such, it is one of the most-used Unix commands. ls takes several commonly used options (along with the usual host of obscure and operating system-specific options):

ls -F shows special characters after files' names to indicate their types, so that / follows directories, @ follows symbolic links, and * follows executable files.

ls -l shows extended information about files, including their owners and permissions, and the targets of symbolic links.

ls -a shows all files, including those that start with a dot (.). Normally, files whose names begin with a dot are hidden.

ls -R lists the contents of a directory, its subdirectories, its subdirectories' subdirectories, and so on recursively.

These options can be combined, so, for instance, ls -RlF is a good way to see all the files below the current directory. By default, the directory whose contents should be listed is the current working directory; giving a directory as an argument to ls will make it list that directory's files, as in ls -RlF /var/log/.

6.2.4.2. wc

wc stands for word count. Actually, by default, wc lists the number of lines, words, and characters (or bytes) in a file, in that order. You can give options to wc to make it report only one of those metrics: -l for lines, -w for words, and -c for characters. One useful wc idiom is ls | wc -l, which counts the number of files in a directory.

If it is passed several filenames at once, wc will print information for each of the files, followed by information about the total length of all the files. For instance, wc * might print the following:

      71     366    2283 setuid.html
      54     277    1764 sticky.html
      21      66     516 touch.html
     146     709    4563 total

previous contents up next