Perintah lsini berhubungan dengan nama file , yang dicatat dalam struktur data direktori. Jadi tidak terlalu peduli dengan file itu sendiri, termasuk "tipe" dari suatu file.
Perintah yang lebih cocok untuk mengerjakan file yang sebenarnya , bukan hanya namanya saja, adalah find. Ini memiliki opsi yang langsung menjawab pertanyaan Anda tentang cara memfilter daftar pada jenis file.
Ini memberikan daftar direktori saat ini mirip dengan ls -l:
find . -maxdepth 1 -ls
Secara default, finddaftar direktori secara rekursif, yang dinonaktifkan dengan membatasi kedalaman pencarian ke 1.
Anda dapat meninggalkan ., tapi saya memasukkannya untuk menunjukkan direktori harus didaftar sebelum opsi.
Dengan -type, Anda dapat memfilter menurut jenis file, yang dinyatakan sebagai fatau duntuk file atau direktori biasa:
find . -maxdepth 1 -type d -ls
Ada nilai filter lain untuk -type, terutama luntuk tautan simbolik.
Perhatikan bahwa ada komplikasi dengan symlink :
Ada dua jenis file dalam kasus ini:, lmenunjukkan symlink, dan sesuatu seperti f, menunjukkan jenis file yang ditautkan. Ada opsi untuk menentukan cara menanganinya, sehingga Anda dapat memilih.
Dari man find:
-type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the -L option
or the -follow option is in effect, unless the sym‐
bolic link is broken. If you want to search for
symbolic links when -L is in effect, use -xtype.
s socket
D door (Solaris)
dan relevan dengan penanganan tautan simbolik:
-xtype c
The same as -type unless the file is a symbolic link. For
symbolic links: if the -H or -P option was specified, true
if the file is a link to a file of type c; if the -L option
has been given, true if c is `l'. In other words, for sym‐
bolic links, -xtype checks the type of the file that -type
does not check.
dan
-P Never follow symbolic links. This is the default behav‐
iour. When find examines or prints information a file, and
the file is a symbolic link, the information used shall be
taken from the properties of the symbolic link itself.
-L Follow symbolic links. When find examines or prints infor‐
mation about files, the information used shall be taken
from the properties of the file to which the link points,
not from the link itself (unless it is a broken symbolic
link or find is unable to examine the file to which the
link points). Use of this option implies -noleaf. If you
later use the -P option, -noleaf will still be in effect.
If -L is in effect and find discovers a symbolic link to a
subdirectory during its search, the subdirectory pointed to
by the symbolic link will be searched.
When the -L option is in effect, the -type predicate will
always match against the type of the file that a symbolic
link points to rather than the link itself (unless the sym‐
bolic link is broken). Using -L causes the -lname and
-ilname predicates always to return false.
-H Do not follow symbolic links, except while processing the
command line arguments. [...]