The command to list the contents of a folder/directory in Unix and Unix-like systems.

learn more… | top users | synonyms

514
votes
7answers
340k views

How can I sort the output of 'ls' by last modified date?

How can I sort the output of ls by last modified date?
43
votes
10answers
29k views

Unix: ls, how to sort first directories then files etc

I would like to use ls command to first show direcotries and then files. I tried ls -la | sort -k 1 But I got a wrong order.
42
votes
6answers
58k views

How to list folders using bash commands?

Is there any way to list just the folders in a directory using bash commands? ( as the ls command lists all the files and folders )
39
votes
2answers
9k views

Icon? file on OS X desktop

When I ls my Desktop from terminal (by using ls ~/Dekstop), I see a file, Icon?. As far as I can tell, it's empty (nano Icon? shows nothing). It doesn't show up on my actual Desktop, and open Icon? ...
36
votes
7answers
13k views

What does the @ mean on the output of “ls” on OS X' terminal?

When doing an ls in a directory I get the following output: 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 ...
34
votes
5answers
43k views

what does the asterisk mean after a filename if you do ls -l

I've done an ls -l inside a directory, and my files are displaying like this : james@nevada:~/development/tools/android-sdk-linux_86/tools$ ll total 9512 drwxr-xr-x 3 james james 4096 2010-05-07 ...
34
votes
3answers
21k views

How to have Linux ls command show second in time stamp

Something annoying about ls -l command is it shows only hour and minute for a file(like 08:30). How can I see the second portion(like 08:30:44)? man 1 ls and search for 'second' does not give any ...
30
votes
6answers
18k views

How do I get ls --color=auto to work on Mac OS X?

I'm trying to move my bash configuration from Ubuntu to Mac OS X and it looks like ls is slightly different. For instance, it won't accept the --color option. How do I get this to work?
29
votes
7answers
28k views

ls -d is not displaying directories. Is there a way to get ls to only display directories instead of files and directories

Is there a way to get ls to only display directories instead of files and directories From the man page. -d, --directory list directory entries instead of contents, and do not ...
23
votes
0answers
23k views

ls -la symbolics… what does that last symbol mean?

Possible Duplicate: what does the @ mean on the output of ls on os x terminal? when I type ls -la I get this familiar output... drwxr-xr-x+ 38 kent staff 1292 Nov 6 11:09 . ...
21
votes
2answers
13k views

How do I interpret the results of the `ls -l` command?

I want to learn about the meaning of values for example first line; drwxr-xr-x 2 ataka root 4096 2008-11-04 16:58 ataka is ataka here the owner of directory ? kioutsovkm@orkide:/users/lnxsrv2/ee$ ...
16
votes
2answers
2k views

What is the magic separator between filenames in ls output?

The output of ls (with no arguments) appears to separate filenames with linebreaks. Evidence: ls | grep foo works as expected, with grep treating each filename as a separate line of input. ls > ...
15
votes
3answers
2k views

How can I make “ls” show dotfiles first?

Somewhere along the way I screwed up my ls command and now I get this ordering when running $ ls -AhHl --color=auto -rwxr-xr-x 1 clang clang 640 Mar 1 02:46 apple-touch-icon-precomposed.png ...
15
votes
2answers
12k views

How do I limit the number of displayed lines through ls?

Let's say I have a command ls -Bgclt /somwhere/in/the/past How do I limit the output to show me only first 2 files? (except for having only 2 files in that directory)
13
votes
2answers
6k views

How to diff file names in two directories (without writing to intermediate files)?

I am trying to do something along the lines of: diff `ls -1a ./dir1` `ls -1a ./dir2` But that doesn't work for obvious reasons. Is there a better way of achieving this (in 1 line), than this? ls ...
13
votes
2answers
8k views

What does the @ in ls -al mean? [duplicate]

Possible Duplicate: ls -la symbolics… what does that last symbol mean? What does the @ in the below execution of ls -al mean? atom:Lib fak$ ls -al total 1056 drwxr-xr-x 5 fak staff ...
12
votes
8answers
26k views

Tell `ls` to print only the base filename

This is the default behaviour of ls ls /net/nas/data/languages/pypm/sites/rex/free/2.6/*/pool/v/vi/virtual*1.4.4*pypm ...
11
votes
7answers
16k views

How can I list only non-empty files using ls?

How can I list (using ls) all files that are not empty (size > 0) using linux?
10
votes
1answer
15k views

ls | grep | rm — How to format this command?

I'm trying to delete a bunch of files in a certain directory (on Mac OS X using Terminal) ls | grep \([1-9]\) | xargs rm should do the trick, but it doesn't. I'm trying to delete any file with a ...
9
votes
1answer
6k views

ls and du shows VERY different size!

I am downloading a file with rtorrent, But when i check the folder that the file is located on ,the filesize with ls command is 4.4GB but when i check the disk with du command it shows me 219MB, also ...
9
votes
1answer
4k views

Making ls aware of “hidden” file flag

Is it possible to make ls aware of the hidden file flag on Mac OS X? Currently, a simple ls -lO produces: $ ls -lO total 0 drwxr-xr-x@ 84 danielbeck staff - 2856 29 Mai 22:44 Applications ...
9
votes
0answers
9k views

what is the @ after the permissions for in ls -l on a mac? [duplicate]

Possible Duplicate: ls -la symbolics… what does that last symbol mean? Consider the following output from ls -l on OS X 10.5.8 drwxr-xr-x 3 user staff 102 Aug 26 20:21 ...
8
votes
2answers
26k views

How to find all soft links (symbolic links) in current directory?

Question relates to shell-scripting in bash. How to check with a script which files within the current directory are soft links? In case I have used the wrong term, when I say soft links, I am ...
8
votes
3answers
7k views

Show both ctime and atime in ls output

Can I get both ctime and atime in ls output? Seems I can only pass one --time=ctime or --time=atime argument (the second is ignored). Is there any other way?
8
votes
6answers
23k views

how to list all files and directories in given directory with full path but not recursive?

Somehow like dir /b command but I need also hidden and system files there. Built in dir command doesn't allow to list such 'hidden' files with the rest and I must use /s to have full path in there, ...
8
votes
4answers
5k views

How to list files recursively and sort them by modification time?

How do I list all files under a directory recursively and sort the output by modification time? I normally use ls -lhtc but it doesn't find all files recursively. I am using Linux and Mac. ls -l on ...
7
votes
3answers
2k views

List file range with UNIX wildcards

Say for example I have the following files in my working directory: mjk0001.fits, mjk0002.fits, ... numerically increasing all the way to mjk9999.fits. Is there a way to use UNIX wildcards to list or ...
7
votes
5answers
12k views

How to list files by file owner in Unix command?

I need to list all of the files my WD sorted alphabetically by the file owner name. Does ls have something for this?
6
votes
2answers
909 views

Is there a tail -f equivalent for ls?

Basically the question is in the title. I want to monitor a directory for new files that are written or deleted, the way I can monitor a log file with tail -f. Is this possible?
6
votes
2answers
883 views

Vi can write to file despite file being read-only

The following example show how to create a file with only read permissions. As we can see, when I try to write to this file using the echo command I get, Permission denied. But why, in the case that ...
6
votes
3answers
7k views

Recursive ls with conditions

Why can't I use a command like this to find all the pdf files in a directory and subdirectories? How do I do it? (I'm using bash in ubuntu) ls -R *.pdf EDIT How would I then go about deleting all ...
6
votes
2answers
322 views

What is the modification date ls reports for directories in Bash shell?

When I run ls -l in Bash shell, it lists a modification time for both files and directories. As noted in this thread, the modification time for directories does not reflect all of its contents. It ...
6
votes
4answers
1k views

Pass the output of ls to diff

I have one file that contains a list of files from a server, and a local folder that I compare to that manifest. Obviously, I do 'ls -1 > listing_local' and then diff that file with listing_server. ...
6
votes
3answers
2k views

what does it mean a red filename shown with black background?

I have a compilation problem, and when I check my lib/ directory I get this output from "ls": What the red/black combination mean? I checked in the output of "dircolors -p" as suggested here ...
5
votes
4answers
8k views

How to rename multiple files in a directory in some pattern in Linux?

I have a directory which has files with random names. What I want to do is rename the files with file1, file2 and so on.The lexicographically smaller file name should be numbered with smaller number. ...
5
votes
1answer
952 views

Mac OS X: Is there a straightforward way to color ls output according to Finder label colors?

I have a client with a directory tree that has a number of high-level directories that I need to have on my local development machine. I rarely look at them unless something goes awry. I've marked ...
5
votes
4answers
723 views

How to turn off --classify option in ls command?

My ls command is aliased to have certain options automatically applied, including --classify (same as -F) Normally this is fine and I don't want to screw around with my .bashrc file. Just this one ...
5
votes
2answers
1k views

is there a way to read the cumulative size of all files in a folder?

I want to read the size of a folder from the command line. ls -lh shows all folders as being 4k, which presumably is the size of the footprint of the folder itself, rather than the contained files. ...
5
votes
3answers
8k views

What is the meaning of 'T' in the execution permissions of a directory?

I just found this confusing output of the ls command: whodare@ubuntu~ $: ls -l /var/spool/cron/ total 12 drwxrwx--T 2 daemon daemon 4096 Oct 29 05:02 atjobs drwxrwx--T 2 daemon ...
5
votes
1answer
710 views

What is the + at the end of Unix permissions in a long listing format?

Here's an example drwxr-xr-x+ 6 reza reza 204 Mar 5 20:23 .ssh/ Although I am the owner of this directory, I cannot modify it without using sudo! Why is that? how can I remove '+' here ...
5
votes
2answers
869 views

ls version number sorting Mac OS X

Is there an equivalent to ls -v in Mac OS X that will do version number sorting? In Mac OS X, ls -v does NOT do version number sorting, but the Finder seems to.
5
votes
2answers
1k views

How can I get colors with “ls -l | more”?

ls -l gives me color coded output. Folders are blue, executables green, etc. These colors are gone when filtering thorough | more. Anyway to achieve both paged output and colors?
5
votes
1answer
2k views

Ubuntu's ls can show unicode characters, but tree cannot, even with tree --charset unicode

Ubuntu 10.04's ls can show unicode characters, but tree cannot, even with tree --charset unicode or utf8. Is there a way to solve it. echo could interpret the escape characters except cat list.txt | ...
5
votes
2answers
913 views

How to use GNU parallel with gunzip

I have a directory full of .gz, I want to expand each archive in parallel with GNU parallel. However I did not achieve anything. I tried parallel 'gunzip {}' ::: `ls *.gz` parallel gunzip `ls *.gz` ...
5
votes
2answers
2k views

How to physically reorder files `03.mp3 01.mp3 02.mp3` (`ls -f`) in a directory?

The physical order of the files matters when I copy them onto my USB stick and listen in car mp3 player. Most of my music album folders are unsorted, e.g. ls -f may produce: 03.song3.mp3 01.song1.mp3 ...
5
votes
1answer
459 views

Linux shows several folders with the exact same name

I recently used a mac to copy several files and folders to a USB drive (ext4 through ExtFS), and now in Linux (Xbian) two folders in the root of the drive are shown four times. The output of "ls ...
4
votes
3answers
11k views

ls -rt (How to list just THE LAST file? e.g. for: | xargs gnome-open)

e.g. directory containing jpeg files: how to easily open just the most recent jpeg in the current directory?
4
votes
6answers
3k views

Listing everything else than *{.tex, .aux} by ls

How can you ls everything else the the files *{.tex, .aux}? I run unsuccessfully ls -I".tex"
4
votes
5answers
8k views

How to display the file contents recursively?

I always have to submit the source codes in my printed assignment report. I have to copy and paste my course codes into the document and I find that it is an annoying task. I want to solve this "copy ...
4
votes
3answers
1k views

What is user/owner 24561?

So, I just installed the node.js package from nodejs.org and I was poking around to see what it installed. Over in /usr/local/bin I saw this owner 24561. I see it in a few other places too. What is ...