The ls command lists the contents of a directory.

learn more… | top users | synonyms

70
votes
8answers
9k views

Why *not* parse `ls`?

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 ...
34
votes
6answers
4k views

The result of ls * , ls ** and ls ***

I know using the command ls will list all the directories. But what does the ls * command do ? I used it and it just lists the directories. Is the star in front of ls means how deep it can list the ...
31
votes
4answers
2k views

The ls command is not working for a directory with a huge number of files

I had a directory which had around 5 million files. When I tried to run the ls command from inside this directory, my system consumed a huge amount of memory and it hung after sometime. Is there an ...
30
votes
7answers
3k views

why does ls -d also list files, and where is it documented?

when specifying ls --directory a* it should list only directories starting with a* BUT it lists files AND directories starting with a Questions: where might I find some documentation on this, ...
27
votes
2answers
22k views

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.
27
votes
3answers
3k views

What does size of a directory mean in output of 'ls -l' command?

What does size of a directory mean in output of ls -l command?
26
votes
5answers
7k views

Is there any option with 'ls' command that I see only the directories?

Sometimes, I need to check only the directories not files. Is there any option with the command ls? Or is there any utility for doing that? EDIT: I'm using Mac OS X, and ls -d gives me . even though ...
24
votes
1answer
2k views

Why does “ls *” take so much longer than “ls”?

I have a couple of files in a directory: $ ls | wc -l 9376 Can anybody explain why there is such a huge time difference in using ls * and ls? $ time ls > /dev/null real 0m0.118s user ...
24
votes
6answers
5k views

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 ...
23
votes
12answers
3k views

What's the most resource efficient way to count how many files are in a directory?

CentOS 5.9 I came across an issue the other day where a directory had a lot of files. To count it, I ran ls -l /foo/foo2/ | wc -l Turns out that there were over 1 million files in a single ...
19
votes
2answers
644 views

Is there a reason why ls does not have a --zero or -0 option

This question was prompted by questions about ls' -1 option and the recurring tendency of people to ask question and answers that includes processing the output of ls. This reuse of the output ls ...
19
votes
2answers
7k views

Output from ls has newlines but displays on a single line. Why?

I think I may be overlooking a relatively fundamental point regarding shell. Output from the ls command by default separates output with newlines, but the shell displays the output on a single line. ...
19
votes
3answers
3k views

ls command: what does the first line mean?

When I do ls -l I get this: calico@A000505:~/Documentos$ ls -l total 2020 -rwxr-xr-x 1 calico calico 8559 2010-11-16 11:12 a.out -rwxrw-rw- 1 smt smt 2050138 2010-10-14 10:40 Java2.pdf ...
17
votes
11answers
2k views

Linux - command to list files (except ls)

Imagine you were working on a system and someone accidentally deleted the ls command (/bin/ls). How could you get a list of the files in the current directory? Try it. I tried many ...
15
votes
3answers
12k views

Find the owner of a directory or file, but only return that and nothing else

I am looking for a command that will return the owner of a directory and only that--such as a regex parsing the ls -lat command or something similar? I want to use the result in another script.
15
votes
1answer
2k views

Why are reboot, shutdown and poweroff symlinks to systemctl?

In Arch Linux, if I do ls -l in /sbin, I can see that reboot, shutdown and poweroff are all symlinks to /usr/bin/systemctl. But issuing reboot, shutdown and systemctl commands obviously does not all ...
15
votes
6answers
13k views

How to match case insensitive patterns with ls?

I would like to list all files matching a certain pattern while ignoring the case. For example, I run the following commands: ls *abc* I need to see all the file that have "abc" as a part of the ...
15
votes
2answers
51k views

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

With ls command, does it possible to show only file created after a date, hour... I'm asking it because I have a directory with thousand of files. I want files created since yesterday. I use ls ...
14
votes
7answers
8k views

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 | sort ...
14
votes
5answers
6k views

What is the difference between ls and l?

I accidentally typed l instead of ls today and found that the command still printed a list of the files in my current directory. Trying l --help brings up the help file for ls suggesting that l is ...
14
votes
4answers
11k views

last time file opened

Is it possible to get the time when file was opened last time and sort all files in a directory by those times?
14
votes
5answers
16k views

How to list all files in the size order

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.
13
votes
4answers
19k views

Why is Debian's root shell colorless?

Are there any security concerns? What is the best way to enable it?
13
votes
3answers
458 views

When does `ls -s` print “0”

Of course, the standard way of testing if a file is empty is with test -s FILE, but one of our clients have received a script containing tests like this: RETVAL=`ls -s ./log/cr_trig.log | awk '{print ...
12
votes
4answers
676 views

Why does ls accept duplicate switches?

I'm curious - is there a difference between ls -l and ls -lllllllllllllllllllllllllllll? The output appears to be the same and I'm confused on why ls allows duplicate switches. Is this a standard ...
12
votes
6answers
743 views

Why does “ls” require a separate process for executing?

Why does ls require a separate process for its execution? I know the reason why commands like cd can't be executed by forking mechanism but is there any harm if ls is executed without forking?
12
votes
2answers
4k views

What does the 'd' mean in ls -al results and what is that slot called?

In Linux, what does the d mean in the first position of drwxr-xr-x? And what are all of the possible letters that could be there, and what do they mean? I'm trying to learn more about the Linux file ...
12
votes
1answer
6k views

ls taking long time in small directory

Running Ubuntu, I open a terminal and do sudo bash cd / ls | head -n 1000 And predictably about 20 directories are returned. However, if I do an ls, and don't pipe it into anything, the ls just ...
12
votes
2answers
2k views

What is the number between file permission and owner in ls -l command output?

The output of ls -l command yields the following result: What is the number field between file permission and owner? i.e. what are those 1, 1, 1, and 2? I checked the --help but that doesn't ...
11
votes
6answers
8k views

How do I list every file in a directory except those with specified extensions?

Suppose that I have a folder containing .txt, .pdf, and other files. I would like to list the "other" files (i.e., files not having the extensions .txt or .pdf). Do you have any advice on how to do ...
11
votes
5answers
14k views

Linux ls to show only filename date and size

How can I use ls in linux to get a listing of filenames date and size only. I don't need to see the other info such as owner or permission. Is this possible?
11
votes
3answers
9k views

What is the Linux equivalent of DOS “dir /s /b filename”?

List all files/dirs in or below the current directory that match 'filename'.
11
votes
2answers
1k views

“ls -lh” reports total size less than sum of individual sizes

Under what circumstances would ls -lh show a total that is less than the sum of the individual files? For example: $ ls -lh /var/lib/nova/instances/_base total 100G -rw-rw-r-- 1 nova nova ...
11
votes
5answers
4k views

case-insensitive search of duplicate file-names

I there a way to find all files in a directory with duplicate filenames, regardless of the casing (upper-case and/or lower-case)?
11
votes
1answer
165 views

Include colouring in GNU ls time-style

I know, I can specify custom time format for ls like this ls -lAF --time-style="+ %Y-%b-%d %H:%M:%S" --color=always but I would like to "smuggle in" colors inside the time format. For example, I ...
11
votes
2answers
2k views

Why does ls sorting ignore non-alphanumeric characters?

When sorting file names, ls ignores characters like -,_. I expected it to use those characters in sorting as well. An example: touch a1 a2 a-1 a-2 a_1 a_2 a.1 a.2 a,1 a,2 Now display these files ...
10
votes
6answers
32k views

How to list files without directories, and filter by name (ls options)

I have a directory called uploads. It contains a bunch of files, plus a few subdirectories which in turn contain files. Is there a way I can (in one step) do the following: List ONLY the files in ...
10
votes
2answers
547 views

Highlight the three last updated files in ls output

Is there any way to overload or wrap the ls command so that it will highlight / underline / otherwise make obvious the last three modified files? I know that I can simply ls -rtl to order by reverse ...
10
votes
6answers
4k views

What does the “number” in the owner field of files signify in linux?

I copied many files to my new linux host. I see that all files have the owner and group both set to 515. What does that mean?
10
votes
1answer
1k views

ls everything that is _not_ a symlink

Does ls have a way to show negated conditions like "all files which are not a symlink"? I use the latter a lot in a project directory but other negations would be useful as well. For now, my research ...
9
votes
1answer
17k views

How can I assign the result of a command to a shell variable?

I want to assign the result of an expression to a variable and concatenate it with a string, then echo it. Here's what I've got: #!/bin/bash cd ~/Desktop; thefile= ls -t -U | grep -m 1 "Screen Shot"; ...
9
votes
2answers
19k views

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?
9
votes
3answers
878 views

EXT3: If block size is 4K, why does ls -l show file sizes below that?

If you run ls -l on a file that contains one letter, it will list as 2B in size. If your file system is in 4k blocks, I thought it rounded files up to the block size? Is it because ls -l actually ...
9
votes
3answers
2k views

Why is sorting files by access time not working?

I tried to use command ls --time=atime it was working in one directory but wasn't working in another directory. I opened certain files in vim, evince and other applications but after the command file ...
9
votes
4answers
2k views

What is the “directory order” of files in a directory (used by `ls -U`)?

According to the man page for ls, ls -U means: do not sort; list entries in directory order. What does "directory order" mean, and how is it determined? The following test (executed on an ...
9
votes
3answers
5k views

dircolors: modify color settings globaly

I understand ls uses dircolors to display colored output. dircolors has default database of colors associated with file extensions, which can be printed wiht the command dircolors --print-database ...
8
votes
6answers
6k views

Show only hidden files (dot files) in ls alias

I'm using the command ls -a | grep '^\.' for showing only the hidden files. I added the line alias hidden='ls -a | grep '^\.'' # show only hidden files to .bash_aliases file but this does not ...
8
votes
5answers
9k views

How to report number of files in all subdirectories?

I need to inspect all sub-directories and report how many files (without further recursion) they contain: directoryName1 numberOfFiles directoryName2 numberOfFiles
8
votes
2answers
3k views

List all files with the same inode number?

Lets say, when I do ls -li inside a directory, I get this: 12353538 -rw-r--r-- 6 me me 1650 2013-01-10 16:33 fun.txt As the output shows, the file fun.txt has 6 hard links; and the inode number is ...
8
votes
4answers
6k views

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 to be executed I need to wait for ls to finish execution, and with directories with an ...