The ls command lists the contents of a directory.

learn more… | top users | synonyms

9
votes
5answers
39k views

ls list files not matching given string in filename

I have a directory in which lots of files (around 200) with the name temp_log.$$ are created with several other important files which I need to check. How can I easily list out all the files and ...
1
vote
1answer
443 views

ls --color=auto (dir colors) not working in one directory

I changed ownership of a folder to provide restricted access to some users (it previously was only visible to root) and after that, all files are now one color (bright green) and directories are blue. ...
80
votes
3answers
217k 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?
12
votes
1answer
26k views

Alias for directory listing sorted by time modified in reverse order

When I need to find my recently used files, this command: ls -lt lists in ascending order (by time), when there are lots files, I need to scroll to the top to see needed files, because wont fit in ...
0
votes
2answers
38 views

Doing ls -l /dev [duplicate]

When experimenting with the ls -l command I noticed that in the /dev folder ls -l was sometimes printing something like this in the first column : crw-rw----+ What is this "+"? What does it mean? ...
1
vote
1answer
117 views

`ls` behavior on EACCES error for /root and /root/some-rubbish

I'm trying to code a clone of the ls command as part of a school exercise. I'm wondering why the following output is displayed by ls: $> ls -- -test_dir /root /root/some-rubbish ls: /root/some-...
28
votes
2answers
15k 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. ...
0
votes
2answers
52 views

List Most Recent File per Sub-Folder

I have a File structure of : FOLDER/SUB_FOLDER/Text_File I have over 1k+ FOLDER and each FOLDER has at least 2 different SUB_FOLDER with each SUB_FOLDER their own Text_File. I'm trying to ...
1
vote
1answer
65 views

Terminal color usage does not stay

I was wondering if any of you knew why doesn't my terminal keep displaying stuff colored, after I use the command ls -l -a --color=always I would like it to stay colored, so when the next time I type ...
4
votes
1answer
352 views

Permission errors even though permissions are wide open

I installed anaconda on our new VM and I can't list its contents. I can change my directory to .../anaconda/ but when I type ls -l I get: ls: cannot open directory .: Permission denied However, ...
1
vote
7answers
608 views

Matching n letter filename with ls

I am using the ls command in bash, trying to find all files or directory of length n. Let's say n=5 My command is: ls ????? But this would also include characters that are non letters such as ...
6
votes
1answer
1k views

Piping the output of ls or tree to less loses colors?

tree and ls can distinct file types by coloring filenames differently. tree and ls often output a long list of files (including directories), so I pipe the stdout output to less. But less doesn't ...
5
votes
5answers
93 views

execute command on a defined range of directories

Is it possible to 'partition' a directory listing - say in to blocks of some number, to perform different actions on each 'range'? For example, lets say I have the following directories inside ...
2
votes
2answers
40 views

Instead of using ls, how does it make work with `find`?

I have this command: ls -Ra | grep -cve/ -e'^\.*$' and I would like to do exactly the same with find I tried this find . -name "^\.*$" -o -print | wc -l but the problem is, if I create new file ...
0
votes
2answers
38 views

Universal abstraction of ls

Specs OS: OS X; Client: Terminal; Shells: sh, bash Problem I'm writing a shell script that adds a layer of abstraction to the ls command. I want to make it "unbreakable", so I started by figuring ...
-2
votes
3answers
48 views

listing files with pattern with starting and ending

I want to list all files in a directory that start with 'abc' and end with '.zip' I'm trying to use ls. The directory has a lot of zip files starting with abc<date> and xvz<date>. I only ...
5
votes
5answers
545 views

Is it possible to run ls or find and pipe it through stat?

Is there a way to run ls or find to get the list of files within a directory and then run stat to get all of the specific information (i.e. File Group, File Name, File Owner, File Size (displayed in K,...
5
votes
1answer
677 views

“The entry is a door” in Solaris “ls” man page

I found this in a man page for ls in solaris linux. http://www.unix.com/man-page/opensolaris/1/ls/ What does it mean when it says: D the entry is a door?
-1
votes
1answer
52 views

What does this command do, exactly?

I have this command, but I don't get what it does. ls -Ra | grep -cve/ -e'^\.*$' And how can I do the same with 'find' command.
1
vote
1answer
56 views

List hidden files only (not just dot files) using an ls alias

I would like to use an ls alias (like l.) to output a colored list, consisting of only hidden files & directories, whether or not they begin with a dot. Any suggestions? Example of desired ...
2
votes
2answers
89 views

“ls” command stuck trying to list a stale mount point. How do you kill/stop it?

When working with remote filesystems such as sshfs or smbfs, it is command that they become stale due to network problems. To check if the mount is stale or not, I usually use the command ls to see if ...
0
votes
3answers
1k views

find -exec ls -lR {} \; returns every item twice

Background: I'm currently writing an archiving script, which creates gzipped tarballs from some folders and their contents. It should be able to synchronize the gzipped archives with the sources ...
1
vote
1answer
67 views

Set ls -l time format

I would like for all my ls commands that display a date, such as ls -l, to print the date column in a format of my choosing. Currently, I manually set this every time with --time-style. Is there any ...
2
votes
1answer
27 views

make ls gray out files that end with tilde (`~`) using `LS_COLOR`

Problem: I am trying to modify LS_COLORS to gray out all files ending with the tilde character. Question: Can anybody spot my mistake? Here is what I did: # write dircolors file: dircolors -p > ...
62
votes
4answers
102k views

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?
24
votes
6answers
30k 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 or tail to be executed I need to wait for ls to finish execution, and with directories ...
2
votes
2answers
45 views

List all the files in ending with several file extensions?

If I want files ending with .fas I know I can do the following with ls command : ls -l /users/jenna/bio/*.fas and this lists out all the files ending with .fas. But how can I get files ending with ...
7
votes
2answers
5k views

How do regular expressions differ from wildcards used to filter files

While we use * to denote zero or more previous characters in grep, we use *.c to find all C files when we use it with the ls command like ls *.c. Could someone tell how the use of * differs in these ...
3
votes
4answers
199 views

How do I extract a long listing field?

I want to extract the access day of a file in a shell script. I tried by writing the following script but it doesn't work. When I echo accessday, the output is "staff". file=$1 accessday=$(ls -lu $...
95
votes
8answers
15k 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 ...
2
votes
5answers
170 views

Have the ls command behave differently based on the number of entries

Is it possible to have the ls command behave differently based on the number of directory entries that may be listed? If I just use ls (with no modifying options, but I can specify directories or ...
1
vote
1answer
80 views

What is the number at the top for the results for ls -l? [duplicate]

When you type in ls -l, there is a number on the first line labeled "total 22037"? What does this number mean? I am attempting to write my own version of ls -l( in C), and how do I get this value or ...
0
votes
0answers
27 views

File and folder size using ls and du [duplicate]

I created a folder and copied a 992 byte jpg file in it. Then I created a hard and soft links for the file. The hard link is the same size of the file and the soft link is 8 bytes. Now when I checked ...
-9
votes
1answer
52 views

Unix “ls” command? [closed]

Can someone explain to me what are all the options available with the -la flags for the ls command ? I have read the man pages, but still not sure.
3
votes
1answer
68 views

Change dir colour in bash output

Under Mac OSX, I am trying to change the dir colour when ls outputs in the bash shell. So I placed this line at the end of my .bashrc file and reloaded. LS_COLORS=$LS_COLORS:'di=0;32:' ; export ...
6
votes
3answers
467 views

How do I get `ls -l` output for a link recursively until reached the original file?

Let me give an example (it's just an example taken from here): $ ls -l /usr/bin/gnome-text-editor lrwxrwxrwx 1 root root 35 Mar 16 2015 /usr/bin/gnome-text-editor -> /etc/alternatives/gnome-text-...
6
votes
1answer
882 views

Can the command completion for `cd` be modified to only show directories and ignore files?

When I am in a directory in bash, and I press cd Space Tab, it shows everything in the directory as a possibility. (Show all 1000 possibilities?) This is really cumbersome when I am in a directory ...
3
votes
2answers
69 views

Quoted filenames with spaces in ls output on OSX

The problem I don't want to see filenames quoted when they contain spaces. Example On OSX I see this when running ls: > ls -l total 0 drwxr-xr-x 2 mafro staff 68 Mar 16 09:02 'dir with spaces' ...
4
votes
1answer
139 views

Why does “ls” sporadically output only “.” in the root directory of an external drive?

In the root directory of my USB flash drive, sometimes when I run ls, the output is normal and it lists the files. At other times, the output is simply one line: $ ls . If I try ls -la at one of ...
3
votes
1answer
45 views

Argument list too long when running ls -d “$PWD”/* command

I'm trying to execute ls -d "$PWD"/* > formmlFileList43k.list But I get the following error: bash: /bin/ls: Argument list too long I've read using a pipe won't have such limitation, how can I ...
2
votes
1answer
93 views

Different output of `find | xargs ls` for the same command on different Ubuntu versions

I have two Ubuntu installations: A: 14.04.3 LTS (GNU/Linux 3.13.0-77-generic x86_64) B: 14.04.2 LTS (GNU/Linux 3.13.0-61-generic x86_64) I'm running the following command: find . -name "nosuch....
9
votes
2answers
5k views

How can I use ms-dos style wildcards with ls and mv?

I have the misfortune of coming from a MS-DOS background - but at least it makes me appreciate how much more powerful Linux is. I've been working on getting my Linux-Fu up to par, but there are a ...
12
votes
5answers
967 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....
-1
votes
1answer
49 views

wildcard usage for a directory displaying filenames in linux?

so one of the questions i have been working on is to display the contents of a directory files by using its wildcards do display specific contents, in this case aim using ls and the portion that I got ...
0
votes
1answer
75 views

Size of a character/block file

Why is the size of a character or block file given as comma separated? crw-rw-rw-. 1 root root 1, 3 Mar 8 10:15 /dev/null brw-rw----. 1 root disk 8, 1 Mar 8 10:15 /dev/sda1 Size of a file is ...
1
vote
1answer
51 views

What does @ in front of a directory name imply?

On my Synology NAS, when I do ls on my volume, I see that a few directories a leading @ in their names. A few also have a trailing @. What does this imply? Examples: @optware @autoupdate
2
votes
2answers
83 views

Sorting ls output where files end in numbers [duplicate]

Here is the output of my normal ls command: f1 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19 f2 f20 f3 f4 f5 f6 f7 f8 f9 So I have 20 files. I need them displayed as : f1 f2 f3 f4 ...
0
votes
4answers
62 views

use ls > filelist and change file list content to file list

I need to use the ls > filelist and, however when is use "cat filelist" it displays all the content in the filelist with filelist as one of the names in it, but i need to change it "* * * File List ...
2
votes
5answers
4k views

List files of certain type under a dir?

If you want to list just directories (in the present directory) use ls -d */ What if you want to list just ordinary files, just executable files, or just soft links, or files of any other type? ...
5
votes
3answers
15k views

How do I find the inode of any directory?

There is literally nothing on google that I can find that will help me answer this question. I presume it is passing some other parameter to ls -i?