Questions tagged [ls]

The ls command lists the contents of a directory.

ls is a command to list files and their metadata (time, size, owner, etc.). Some implementations can show files in color.

ls does not expand wildcards: this is done by the .

It is very nearly always a mistake to use ls in a script. If you're just expanding wildcards, the shell does it already. If you're looking for files based on criteria such as their size or time, use (or 's glob qualifiers if you have zsh).

External references

Further reading

1294 questions
1473
votes
16 answers

How do I get the size of a directory on the command line?

I tried to obtain the size of a directory (containing directories and sub directories) by using the ls command with option l. It seems to work for files (ls -l file name), but if I try to get the size of a directory (for instance, ls -l /home), I…
Abdul Al Hazred
  • 23,792
  • 22
  • 62
  • 85
780
votes
2 answers

How do I make `ls` show file sizes in megabytes?

What commands do I need for Linux's ls to show the file size in MB?
Paul Sheldrake
  • 7,913
  • 3
  • 13
  • 10
352
votes
10 answers

How to list all files ordered by size

I would like to list all files in the order of big to small in size and the files could be present anywhere in a certain folder.
Joe
  • 3,645
  • 2
  • 12
  • 4
322
votes
4 answers

What do the fields in ls -al output mean?

The ls -al command shows the following output; -rwxrw-r-- 10 root root 2048 Jan 13 07:11 afile.exe What are all the fields in the preceding display?
Mr. White
  • 3,407
  • 3
  • 12
  • 9
264
votes
9 answers

Why *not* parse `ls` (and what to do instead)?

I consistently see answers quoting this link stating definitively "Don't parse ls!" This bothers me for a couple of reasons: It seems the information in that link has been accepted wholesale with little question, though I can pick out at least a…
mikeserv
  • 56,150
  • 9
  • 105
  • 218
244
votes
9 answers

What causes this green background in ls output?

There are two directories shown by 'ls'. Normally directories anywhere are blue on black background. But the first one is blue on green and impossible to read. Why is this? How to make it blue on black, or at least something light on something…
DarenW
  • 3,243
  • 5
  • 17
  • 20
233
votes
3 answers

Why is 'ls' suddenly wrapping items with spaces in single quotes?

I just noticed that on one of my machines (running Debian Sid) whenever I type ls any file name with spaces has single quotes surrounding it. I immediately checked my aliases, only to find them intact. wyatt@debian630:~/testdir$ ls 'test 1.txt' …
Wyatt Ward
  • 3,792
  • 2
  • 13
  • 21
190
votes
11 answers

List files sorted numerically

I have a bunch of files from log1 to log164. I'm trying to LIST the directory (sorted) in a UNIX terminal but the sort functions are only providing the format like this: home:logs Home$ ls -1 |…
Rabiani
169
votes
7 answers

How do I do a ls and then sort the results by date created?

In what order are the dated ordered by? Certainly not alphanumeric order. ls -lt sorts by modification time. But I need creation time.
InquilineKea
  • 5,822
  • 12
  • 40
  • 42
167
votes
7 answers

What does the @ mean in ls -l?

I am using Mac OSX. When I type ls -l I see something like drwxr-xr-x@ 12 xonic staff 408 22 Jun 19:00 . drwxr-xr-x 9 xonic staff 306 22 Jun 19:42 .. -rwxrwxrwx@ 1 xonic staff 6148 25 Mai 23:04 .DS_Store -rw-r--r--@ 1 xonic staff …
Larry Wang
  • 2,485
  • 4
  • 19
  • 11
166
votes
8 answers

How do I limit the number of files printed by ls?

Is there a way to limit the quantity of listed files on a ls command? I've seen: ls | head -4 but to get head or tail to be executed I need to wait for ls to finish execution, and with directories with an enourmous quantity of files that can take…
AndreDurao
  • 1,860
  • 2
  • 12
  • 8
162
votes
5 answers

How to get only files created after a date with ls?

With the ls command, is it possible to show only the files created after a specific date, hour...? I'm asking it because I have a directory with thousand of files. I want so see all files that were created since yesterday. I use ls -ltr but I have…
Luc M
  • 3,775
  • 5
  • 29
  • 29
158
votes
9 answers

List only regular files (but not directories) in current directory

I can use ls -ld */ to list all the directory entries in the current directory. Is there a similarly easy way to just list all the regular files in the current directory? I know I can use find find . -maxdepth 1 -type f or stat stat -c "%F %n" * |…
daniel kullmann
  • 9,047
  • 11
  • 36
  • 45
150
votes
1 answer

What does the "@" (at) symbol mean on OSX ls?

When I check permission of less files from the command line on my Snow Leopard OSX system using Bash I see -rw-r--r--@ for certain files and for others I just see -rw-r--r-- What does the @ mean here?
rhand
  • 1,665
  • 2
  • 11
  • 10
132
votes
10 answers

How to output only file names (with spaces) in ls -Al?

I should echo only names of files or directories with this construction: ls -Al | while read string do ... done ls -Al output : drwxr-xr-x 12 s162103 studs 12 march 28 12:49 personal domain drwxr-xr-x 2 s162103 studs 3 march…
Alex Zern
  • 1,519
  • 3
  • 12
  • 8
1
2 3
86 87