You can use the ls command to list the files in any directory to which you have access. For a simple directory listing, at the Unix prompt, enter:
ls
The options available with ls are far too numerous to list here, but you can see them all in the online manual (man) pages by entering man ls at the Unix prompt. Some of the more common options, however, include:
- You can limit the files that are described by using fragments of filenames and * ? wildcards. The * represents any number of unknown characters, while ? represents only one unknown character. You can use * and ? anywhere in the filename fragment.
- If you would like to list files in another directory, use the ls command along with the path to the directory. For example, if you are in your home directory and want to list the contents of the /etc directory, enter: ls /etc. This will list the contents of the /etc directory in columns.
- Several options control the way in which the information you get is displayed. Options are used in this format: ls -option filename. Neither the options nor the filename are required (you may use ls by itself to see all the files in a directory). You may have multiple options and multiple filenames on a line.
- Some of the more helpful options for ls are:
-a which shows all files, including those beginning with . (a period). The dot is special in the Unix file system.
-d which shows directory names, but not contents.
-F which marks special files with symbols to indicate what they are: / for directories, @ for symbolic links, * for executable programs.
-l which shows the rights to the file, the owner, the size in bytes, and the time of the last modification made to the file. (The l stands for "long".)
-R which recursively lists subdirectories. - The options can be combined. To list all the files in a directory in the long format, with marks for the types of files, you would enter: ls -Flg
- As with many other Unix commands, you can redirect the output from ls to a file, or pipe it to another command.
- If you want to save a list of the files in your directory to a file named foo, you would use the following command combination: ls > foo
- If you want to mail a list of the files in your directory to a user named tony, you would use the following combination: ls Mail tony
To see the files beginning with a dot in your home directory, enter at the Unix prompt:
ls -ad ~/.*For example, many rc files have a filename that begins with a . (dot), which means that you normally won't see them when you use the just the "ls" command.
Also see:
In Unix, how do I get a recursive directory listing?
In Unix, how do I remove a directory?
In Unix, how do I create a new directory?
In Unix, what is the find command, and how do I use it to search through directories for files?
What do some common Unix file extensions mean?
In Unix, what command can I use other than "ls" or "ls -l" to list the files in a directory?
No comments:
Post a Comment