Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
ls shows what is in a folder (the current one when you give no name). With -l you get the long list:
-rw-r--r--. 1 root root 158 Jan 6 10:12 /etc/hostsFrom left to right: file type and permissions (the . at the end means an SELinux context exists), number of hard links, owner, group, size in bytes, last change time, name.
The first letter is the type: - file, d folder, l symbolic link, b block device, c character device, p pipe, s socket.
On RHEL, ls is an alias for ls --color=auto, and ll for ls -l --color=auto.
Zo schrijf je het
ls [OPTION]... [FILE]...Opties 60
Meest gebruikt
What to show
Long list and details
Sort
Format
Niets past bij dit filter.
Voorbeelden 13
$ als gewone gebruiker# als root (of met sudo)
1Long list with readable sizes
ls -lh /var/logThe basic view to check owners, permissions and sizes.
2Show hidden files
ls -la ~Files like
.bashrcand.sshare hidden.-ashows them.3What changed last?
ls -lrt /etc | tailSorted by time, the newest files at the bottom. Great after an update or an incident.
4Show the folder itself, not its content
ls -ld /tmp /etc drwxrwxrwt. 18 root root 4096 Oct 25 09:12 /tmp drwxr-xr-x. 140 root root 8192 Oct 25 08:55 /etcCheck the permissions of a folder. The
ton /tmp is the sticky bit.5Show the SELinux context
ls -Z /var/www/htmlThe label must be
httpd_sys_content_tfor Apache. Wrong labels cause "403 Forbidden".6Find the biggest files in a folder
ls -lS /var/log | headBiggest first. For a whole tree use
duorfind -size.7Show inode numbers to see hard links
ls -li /data/projects/web/hosts.old /data/projects/db/hosts.hardThe same inode number means the same data.
8List only folders
ls -d /etc/*/The slash at the end of the pattern matches folders only.
9Show user and group as numbers
ls -ln /homeUseful after a restore or on NFS, when names do not match on two systems.
10Exact times in ISO format for a report
ls -l --time-style=long-iso /etc/passwd /etc/shadowWhen was the account database last changed? A good question in a security check.
11Show which files are links and programs
ls -F /usr/local/bin@= link,*= program,/= folder.12One name per line for a script
ls -1 /etc/yum.repos.d/Better: use a
for f in /etc/yum.repos.d/*loop orfindin scripts; never parsels -l.13Folders first, then files, sorted naturally
ls -l --group-directories-first -v /srv/releasesVersion numbers like v2, v10 are sorted in the right order.
Niets past bij dit filter.
Let op
- Do not parse the output of
lsin scripts (names with spaces or new lines break it). Use globs orfind -print0. - The size in
ls -lis the file length, not the space used on disk.ls -sordushows the real use. ls -lof a link shows the link; add-Lto see the target file.
Tips om te onthouden
-llong,-aall,-hhuman,-ttime,-rreverse,-dthe folder itself,-ZSELinux.ls -lrt= newest at the bottom;ls -lS= biggest first.