Questions tagged [ls]

The ls command lists the contents of a directory.

Filter by
Sorted by
Tagged with
52 votes
7 answers
12k 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, other ...
erch's user avatar
  • 5,040
52 votes
8 answers
158k 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 ...
Andrew's user avatar
  • 16.9k
51 votes
15 answers
111k views

'ls -1' : how to list filenames without extension

ls -1 lists my elements like so: foo.png bar.png foobar.png ... I want it listed without the .png like so: foo bar foobar ... (the dir only contains .png files) Can somebody tell me how to use ...
Colin's user avatar
  • 631
50 votes
11 answers
168k views

How to list all files in a directory with absolute paths

I need a file (preferably a .list file) which contains the absolute path of every file in a directory. Example dir1: file1.txt file2.txt file3.txt listOfFiles.list: /Users/haddad/dir1/file1.txt /...
arabian_albert's user avatar
49 votes
3 answers
31k views

How can I do the equivalent of tail -f with ls? [duplicate]

Possible Duplicate: Is it possible to follow a command (run repeatedly)? as one would follow a file using tail -f? I would like to monitor files that are being downloaded to a directory in real ...
T. Brian Jones's user avatar
48 votes
4 answers
141k views

List of Recently Modified Files

How can I Get a list of all files modified , say 3 months ago. I checked this question but I was not able to apply it to my scenario. I am trying this now , it seems to be working , but I know there ...
GoodSp33d's user avatar
  • 595
48 votes
2 answers
113k views

How do I get the total size of everything in a directory in one line? [duplicate]

I know I can use du -h to output the total size of a directory. But when it contains other subdirectories, the output would be something like: du -h /root/test . . . . 24K /root/test/1 64K /root/...
AGamePlayer's user avatar
  • 7,605
47 votes
3 answers
11k 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 ...
Timo's user avatar
  • 6,332
47 votes
3 answers
51k views

Where is "showing the output of the 'ls' command vertically" documented?

I found out it's possible to show the output of the ls command vertically using the -1 switch: $ ls -1 But couldn't find it in the manual of ls. Is it a secret option?
B Faley's user avatar
  • 4,343
46 votes
4 answers
130k views

Why does "ls | wc -l" show the correct number of files in current directory? [duplicate]

Trying to count number of files in current directory, I found ls -1 | wc -l, which means: send the list of files (where every filename is printed in a new line) to the input of wc, where -l will count ...
Kirill's user avatar
  • 995
46 votes
6 answers
51k views

Why does "ls -all" show time for some files but only year for others?

If you issue the ls -all command some files are displayed with the timestamp containing the year without the time and others with the timestamp containing the time but not the year. Why does this ...
Jonathan Kittell's user avatar
45 votes
3 answers
33k views

How to ls using the long format (-l) while still following directory symlinks?

I've noticed that ls -l doesn't only change the formatting of the output, but also how directory symlinks are handled: > ls /rmn biweekly.sh daily.sh logs ... > ls -l /rmn lrwxrwxrwx 1 root ...
RomanSt's user avatar
  • 555
45 votes
3 answers
106k views

What does ">" do vs ">>"? [duplicate]

I am currently doing preparation for my GCSE computing controlled assessment on Linux. I type ls > list and ls >> list into the command line, but it does not do anything. I have googled it ...
ayy lmao's user avatar
  • 781
44 votes
4 answers
17k views

Why would the command "ls *" generate an error about invalid options?

There is a thread that talks about ls "*" not showing any files, but I actually wonder why the simple ls * command doesn't output anything in my terminal other than ls: invalid option -- '|' Try '...
MaelPJ's user avatar
  • 605
44 votes
2 answers
9k views

Why does "ls" take extremely long in a small directory that used to be big? How to fix this?

I'm running Arch Linux, and use ext4 filesystems. When I run ls in a directory that is actually small now, but used to be huge - it hangs for a while. But the next time I run it, it's almost ...
Belen's user avatar
  • 551
38 votes
3 answers
14k 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 -...
oli206's user avatar
  • 759
36 votes
6 answers
98k views

List files larger than {size} sorted by date

I want to solve the problem 'list the top 10 most recent files in the current directory over 20MB'. With ls I can do: ls -Shal |head to get top 10 largest files, and: ls -halt |head to get top 10 ...
EoghanM's user avatar
  • 887
36 votes
1 answer
43k views

+ or @ mark after running 'ls -al' [duplicate]

In Mac OS X, run 'ls -al' gives me something like this. drwxrwxrwx+ 4 smcho staff 136 May 5 09:18 Public drwxr-xr-x+ 6 smcho staff 204 Feb 1 2010 Sites drwxrwxrwx 9 smcho staff ...
prosseek's user avatar
  • 8,558
36 votes
2 answers
31k views

What does a dot after the file permission bits mean?

I performed an ls -la on directory on my CentOS 6.4 server here and the permissions for a given file came out as: -rwxr-xr-x. I understand what -rwxr-xr-x means, what I don't understand is the . ...
gtludwig's user avatar
  • 873
34 votes
1 answer
15k 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 ...
Gradient's user avatar
  • 3,669
33 votes
1 answer
5k views

"/usr/bin/ping" is shown as yellow-on-red in the default Fedora bash color scheme -- what does it mean?

When listing the directory /usr/bin, one sees that ping is shown as yellow-on-red: The file has no special features: $ file /usr/bin/ping /usr/bin/ping: ELF 64-bit LSB shared object, x86-64, ...
David Tonhofer's user avatar
33 votes
4 answers
12k 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 ...
daniel kullmann's user avatar
33 votes
4 answers
21k views

How do I make ls sort underscore characters first?

I like being able to name files and directories with an underscore prefix if it's something I want to keep separate from other files and directories at the same level. On Windows and Mac, for example, ...
Tom Auger's user avatar
  • 634
32 votes
10 answers
110k views

How can I list files by type with ls?

When I use the ls command with the option -l, the first string of letters gives the info about each file, and the first letter in this string gives the file's type. (d = directory, - = standard file, ...
dziadek1990's user avatar
32 votes
1 answer
6k views

Why can Linux show a file name containing character '/'?

The following picture is snapped in a real Linux environment. Why can Linux show a file name containing character '/'?
xmllmx's user avatar
  • 1,830
32 votes
8 answers
54k 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
ShyBoy's user avatar
  • 635
31 votes
3 answers
12k views

No colored output in less for the ls command

If I run ls I get colored output which I find pretty handy for quickly getting a glance of the kind of file. When I try to pipe it to less even with the -r and -R flags the coloring always get lost. I ...
nunos's user avatar
  • 477
31 votes
2 answers
18k views

Fix LS Colors for directories with 777 permission? [duplicate]

When I run ls on a folder with directories that have a 777 permission, the ls colors are purple text with a green background, which is unreadable: What can I do to make this more pleasant to look at?
JoshuaD's user avatar
  • 789
31 votes
5 answers
7k views

How can I make “ls” show dotfiles first while staying case-insensitive?

Create the following files in a directory. $ touch .a .b a b A B 你好嗎 My default ls order ignores the presence of leading dots, intermingling them with the other files. $ ls -Al total 0 -rw-r--r-- 1 ...
Sparhawk's user avatar
  • 20k
30 votes
12 answers
18k 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 methods ...
user avatar
30 votes
5 answers
77k views

Get the latest directory (not the latest file)

My folder parent has the following content: A.Folder B.Folder C.File It has both folders and files inside. B.Folder is newer. Now I just want to get B.Folder, how could I achieve this? I tried this, ...
Daniel's user avatar
  • 719
30 votes
3 answers
30k views

How can I display octal notation of permissions with ls - and can octal represent all permissions? [duplicate]

After looking at the man page for ls on my system and searching Google, I see there IS a hack of way to use awk or perl to show octal permissions when using ls, but with bash is there anything more ...
cwd's user avatar
  • 45.4k
29 votes
1 answer
3k views

Why would /etc/passwd be used every time someone executes `ls -l` command?

Read from APUE, just feel curious: The password file is used every time a user logs in to a UNIX system and every time someone executes an ls -l command.
Rick's user avatar
  • 1,157
28 votes
9 answers
88k views

Find files whose name is 4 characters long [duplicate]

I would like to find files whose name has only 4 characters. Example, there are three files under /tmp: $ ls /tmp txt file linux Output should only show file because it only has 4 characters.
Mike's user avatar
  • 393
28 votes
2 answers
26k views

How to ls without recursive

I am trying to ls some files with a pattern in a directory. I only want to scan the first level not recursive. My script: for i in $(ls $INCOMINGDIR/*$BUSSINESSDATE*) do echo $i; done Above ...
Sas's user avatar
  • 1,083
28 votes
2 answers
3k views

Inconsistent color output from `ls` command

I teach an Intro to UNIX/Linux course at a local college and one of my students asked the following question: Why are some of the files in my directory colored white and others are gray? Are the ...
Bill R's user avatar
  • 393
28 votes
10 answers
41k views

display only files starting with . (hidden)

I tried to display only hidden files but don't know how to do it. That is working (but matching also dots in other places) ls -la | grep '\.' Was trying adding ^ but didn't find the solution.
user3014282's user avatar
28 votes
1 answer
4k 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 0m0....
Sebastian's user avatar
  • 8,827
27 votes
8 answers
54k views

ls content of a directory ignoring symlinks

I have a directory in which I would like to list all the content (files and sub directories) without showing the symbolic links. I am using GNU utilities on Linux. The ls version is 8.13. Example: ...
TheMeaningfulEngineer's user avatar
27 votes
8 answers
34k views

Convert ls -l output format to chmod format

Say I have the following output from ls -l: drwxr-xr-x 2 root root 4096 Apr 7 17:21 foo How can I automatically convert this to the format used by chmod? For example: $ echo drwxr-xr-x | chmod-...
Tyilo's user avatar
  • 5,991
27 votes
2 answers
56k views

Want to sort files by update date including sub-directories

I want to sort only files by update dates including sub-directories. I found out ls -lrtR | grep ^-. but it doesn't seem to sort by update dates. And I need to save this list into a file. Is it ...
Deckard's user avatar
  • 391
27 votes
3 answers
42k views

What is "total" in the output of "ls" command? [duplicate]

I have an empty directory. I am using following command to view the contents of that directory. ls -lart The output I get is below. total 12 drwxr-xr-x 5 root root 4096 Oct 2 12:26 .. drwxr-xr-x 2 ...
g4ur4v's user avatar
  • 1,764
26 votes
4 answers
51k 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?
Mirage's user avatar
  • 1,557
26 votes
1 answer
36k 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 ...
TJ Shah's user avatar
  • 1,761
26 votes
3 answers
1k views

Byte count of "ls -l <random file>" versus that of "wc -c <random file>"

Is there any possible situation when ls -l file.txt is showing not the same number of bytes as wc -c file.txt In one script I found comparison of those two values. What could be the reason of ...
Rokas.ma's user avatar
  • 563
25 votes
3 answers
5k views

Is it now safe to parse the output of GNU ls?

The accepted wisdom for the past few decades has been that it is never a good idea to parse the output of ls ([1],[2]). For example, if I want to save a file's modification date along with its name ...
terdon's user avatar
  • 242k
25 votes
4 answers
20k 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 ext3 ...
Stefan's user avatar
  • 353
25 votes
1 answer
5k views

= sign at the end of .sock files in the ls output

I'm running the zsh shell in emacs. When I run ls I get a = at the end of .sock files. What does the = mean? Is it unique to unix sockets?
c-o-d's user avatar
  • 696
24 votes
1 answer
72k views

ls: how do I list directories sorted by timestamps of the files it contains

How do I list directories by their access time in the sense that some new files/directories are created (say, directories containing the most recently created files).
Ketan's user avatar
  • 9,226
23 votes
2 answers
46k views

syntax of ls --hide= and ls --ignore=

ls --hide and ls --ignore provides the possibility leave out files defined through regular expressions set after the --ignore= part. The latter makes sure that this option isn't turned off via -a, -A. ...
erch's user avatar
  • 5,040

1
2
3 4 5
28