ls - list
lists non-hidden(non-dot) files in current directory.
options modify what is shown.
arguments identify alternative directory files to list.
Both options and arguments are optional.
Options :
ls -a
lists all files in current directory, including 'hidden' (dot) files.
filenames starting with a . (dot) are not normally displayed by ls
dot files often used to store configuration options for various
commands.
ls -l
long listing - shows file-type permissions, number of names, owner,
time last modified, and name.
ls -d target
directory - surpresses traversal into subdirectories. Useful when
target is a directory, lists info about directory itself.
ls -q
quiet - shows unprintable characters as ?
ls -b
binary - shows unprintable characters as octal or symbolic
ls -F
classification flag
- / at end if filename if directory
- * at end if executable
- @ at end if symbolic link
- Note - not part of file name
- --color=auto - GNU? option similar to -F but using colors.
ls -R
recursive, (note Cap.) list all visible files
and contents of all sub-directories. Needs -a for all.
Several more available : man ls
Arguments :
For ls, arguments are file names.
If name a non-directory file, lists just file.
If name directory, lists contents.
wild cards allow flexibility, close matches, but may give more than desired.
- * - any
ls *
- by itself - all visible in current and all next level directory contents
- ls -d * - produces the same output as ls with no arguments.
ls r*
- lists all files beginning with r
ls *s
- lists all files ending with s
ls *s*
- lists all files with s in its name including the filename s if it exists.
- ? - single character of any value
ls ???
- lists all 3 character filenames.
ls f???
- list all 4 character filenames where 1st character is f
ls [char-list]
- ls [135] - each bracket represents possible alternative characters for
one character position.
- ls [a-f] - allows range specification. Range must be ascending ASCII.
- ls [a-fn-z] - multiple ranges allowed.
- [A-F][02468]
- This matches 2 characters in a row,
1st character A or B or C or D or E or F
Note : comma is NOT used in not used in list.
2nd character and even digit.
ls myfile[1-5]
- lists mfile1, myfile2, ... myfile5 - if they exist.
ls [ab]file[1-5]
- lists afile1 ... afile5, bfile1 ... bfile5 - if they exist.
- [[:upper:]] - symbolic list reference.
the inner [:...:] is the list specifier.
Some available symbolic definitions.
[:alnum:] - a-zA-Z0-9
[:alpha:] - a-zA-Z
[:digit:] - 0-9
[:lower:] - a-z
[:space:] - [tab],[space],[verttab],[formfeed],[carriage-return]
[:upper:] - A-Z
[:xdigit:] - 0-9a-fA-F
ls {string1,string2}
specifies list of alternative multi-character strings to match.
strings may be of different lengths
whole string matched.
comma IS required as separator beteen strings in list.
ls f{1,13}
- lists f1 and f13 if they exist.
Wildcards will work with most commands that use a filename as a target,
so be very careful. It is possible to wipe out ALL of your files with
the wrong combination of options and wildcards.
Don't quote filename wildcards, they loose their definition.
ls "*"
literally matches a file called * if it exists.
*Note - filename wildcards are not the same as regular expression wildcards.