The ls command lists the contents of a directory.

learn more… | top users | synonyms

1
vote
2answers
56 views

How to order several options of a command (ls)?

Why doesn't ls behave the same after exchanging the order of options -l and -f? $ ls -l -f 0821131236.jpg 0823130821.jpg $ ls -f -l total 33176 -rw-rw-r-- 1 t t 364186 Jan 6 16:06 ...
5
votes
3answers
25k views

How do I echo just 1 column of output from ls command?

Lets say when I do ls command the output is: file1 file2 file3 file4 Is it possible to display only a certain column of output, in this case file2? I have tried the following with no success: echo ...
0
votes
1answer
31 views

Listing files with a certain extension

I'm suppose to write a command that would list all files that end in .tx with an optional t at the end. So far all I got is listing the files that end in .tx which is: ls *.tx Now my problem is ...
49
votes
7answers
14k 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 ...
13
votes
5answers
325 views

How can I find the first missing directory in a long path?

Imagine I have a path that doesn't exist: $ ls /foo/bar/baz/hello/world ls: cannot access /foo/bar/baz/hello/world: No such file or directory But let's say /foo/bar does exist. Is there a quick way ...
1
vote
2answers
46 views

using ls in bash

I have some files like this: a.10 a.15 a.20 a.30 a.40 a.50 if I want to do a same work for all of them I can use for data in `ls a*| sort -n` If I want to do same work one by one. I can use: ...
3
votes
2answers
39 views

Strange discrepancy of file sizes from ls

I've been using ls -sh to check file sizes ever since 1997 or so, but today something strange happened: ninja@vm:foo$ ls -sh total 98M 1,0M app 64M app_fake_signed.sbp 800K loader 804K ...
3
votes
1answer
48 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 ...
12
votes
3answers
272 views

Why is 'ls' suddenly surrounding 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 ...
2
votes
5answers
481 views

ls | grep works doesn't work with ls --color

I'm trying to list all hidden dirs with the following command ls -lhAF1 | grep -E '^d.*[0-9]{2}:[0-9]{2} \.' which works perfectly fine Explanation for Regex: I'm trying to get all rows that ...
12
votes
5answers
32k views

Difference between ls -l and ll?

I'm relatively new to programming as a whole and some tutorials have been telling me to use ls -l to look at files in a directory and others have been saying ll. I know that ls is a short list, but ...
11
votes
2answers
406 views

Why does `watch` make `ls /tmp` list contents of $HOME?

I'm trying to watch number of files in my /tmp/ directory. For this I thought this command would work: watch sh -c 'ls /tmp/|wc -l' But it appears to work as if ls had no arguments. Namely, I'm in ...
6
votes
2answers
7k 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. ...
1
vote
3answers
54 views

How to exclude the output file from ls output

Let's say I have these files on desktop: aaa.jpg bbb.jpg I want to list these two jpg's and output them to a .txt file: #!/bin/bash cd ~/Desktop ls -1 > all.txt With this code the ...
1
vote
1answer
46 views

ls -lu does not give last access time

The manpage of ls says: -u with -lt: sort by, and show, access time; with -l: show access time and sort by name; otherwise: sort by access time but that doesn't seem to work: ...
1
vote
1answer
47 views

udev creates the right rules, but rights disappear as soon as I try to access files via C++

I'm facing a really strange problem using udev. As I already explained here I'm trying to access some folders/files as a no root user Here are my udev rules for the gpio folder: KERNEL=="gpio*", ...
1
vote
2answers
88 views

Full file date (without GNU utilities)

I am trying to obtain the full date (created or modified) of a particular file for passing to another program. I have tried variations of options with the ls command but none provide a full date for ...
1
vote
2answers
36 views

files per directory in a single line

I have following directories: Sample1 Sample2 Each of it contains multiple subfolders like Sample1/R1/ Sample1/R2/ Sample1/R3/ Sample2/R1/ Sample2/R2/ Sample2/R3/ Which further contains ...
0
votes
2answers
4k views

Making a text file of list of directory entries in bin

How could I make a text file of the list of directory entries in /bin/ along with the attributes of all the files stored there?
0
votes
1answer
31 views

my home directory appears in my download directory

In my Downloads folder when I run ls I see the home directory, and I don't know why, I want to remove it but I am afraid to remove my home folder. Can anyone tell me how I can just remove the home ...
3
votes
4answers
23k views

Unix Command to return all files that end with single digit and TXT extension

Which command returns all files that end with a single digit and have the TXT extension ?
16
votes
3answers
11k 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 ...
0
votes
1answer
67 views

Strange directories in /home

There are some strange directories appearing in /home (so far, maybe in other locations too). These directories do not show up in ls but do with bash's tab autocomplete, when doing things like cd. ...
3
votes
2answers
21k views

How to sort results from ls command by modification date (directories first)?

I can fire ls -lrt to get files and folders sorted by modification date, but this does not separate directories from files. I want ls to show me first directories by modification date and then ...
1
vote
2answers
54 views

Listing line number of results in `find` and `ls` [duplicate]

Is it possible with either find or ls to see, in a list of results, if any given entry is the nth result, what n is? So, for example, pretend ls -l returns: total 0 -rw-rw---- 1 bigdog bigdog 0 Jan ...
39
votes
4answers
8k 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?
1
vote
4answers
67 views

How to show only hidden directories, and then find hidden files seperately

I'm trying to list all the hidden files in a directory, but not other directories, and I am trying to do this using only ls and grep ls -a | egrep "^\." This is what I have so far, but the problem ...
2
votes
1answer
30 views

size of directory reported by ls [duplicate]

I understand the size reported by ls corresponds with number of inodes inside the directory, not their actual size. I have noticed peculiar behavior, when displaying directory size with ls. Here is ...
6
votes
3answers
253 views

Flatten the output of a recursive directory listing

Is there a way to list out all the files within a directory tree in a single list, sorted by modification time on Linux? ls -Rlt lists out files recursively, but they are grouped under different ...
0
votes
1answer
32 views

ls default sorting inconsistent

Why does adding identical characters to the end of filenames change the sort order as shown below? In any sane string comparison method I would expect the comparison of 2 strings to not differ if the ...
3
votes
1answer
50 views

ls & dircolors - differentiate between symlink to directory and symlink to regular file

Is it possible to have the colors for symlinks-to-directories be colored differently than other symlinks? I know I can do: Link target to get the symlinks to take the color settings of their ...
21
votes
6answers
39k 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?
3
votes
5answers
667 views

List files with line count and date

I want to be able to list files showing the number of lines the each file has and the date. I can happily get the line count using wc -l *. Not a problem. I can get the date using ls -l. Is there a ...
38
votes
13answers
16k 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 ...
0
votes
1answer
46 views

bash: How to determine the largest number (newest version) from: ls *.tar.gz | cut -c 2-4

Hi I'm trying to get the largest number (newest version) of a file, I got a bunch of tar.gz files in a directory, versions of some software in the format v${version_number}_software.tar.gz, where ...
95
votes
6answers
131k views

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

I tried to obtain the size of a folder (containing folders and sub folders) 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 ...
0
votes
0answers
12 views

What are the possible file type characters `ls -l` can make, and what do they all mean? [duplicate]

Running ls -l, I can get a lot of different prefixes for the permissions, for example: lrwxr-xr-x drwxr-xr-x prw-r--r-- These are permission from a link, a directory, and a pipe respectively. What ...
14
votes
7answers
24k 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 ...
34
votes
8answers
73k views

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 . ...
1
vote
0answers
26 views

change ls color on OpenWrt

I am not able to change the color of dir entries for ls command (dark blu is a very annoying color to read) on my OpenWrt device. I've added the line LS_COLORS=$LS_COLORS:'di=0;37:' ; export ...
18
votes
11answers
65k views

Show sum of file sizes in directory listing

The Windows dir directory listing command has a line at the end showing the total amount of space taken up by the files listed. For example, dir *.exe shows all the .exe files in the current ...
1
vote
3answers
2k views

zsh alias being overridden somehow

I'm on a system running OS X 10.8.5. I recently tried to alias ls to ls -G -la command. I opened up ~/.zshrc, put in the alias, relaunched the terminal, but the change didn't take effect. Upon ...
3
votes
5answers
13k views

Sort the output of find -exec ls

Is it possible to the output of find … -exec ls -ls ; sorted alpabetically, by filename? This is my cron command: find /home/setefgge/public_html -type f -ctime -1 -exec ls -ls {} \; This command ...
1
vote
4answers
167 views

How to sort files by part of the filename?

Given the files below: ABC38388.SC01.StatueGrade_MKP ABC38388.SC02.Statue_GKP DEF38389.SC03.Statue_HKP XYZ38390.SC00.Statue_WKP How can I list them all based on the SC value, like this: ...
8
votes
6answers
2k views

How do I pipe ls to grep, and delete the files filtered by grep?

I wanted to delete some package in my home file, but the filename was too long (google-chrome-stable_current_i386.deb). So, I decided to use the command ls|grep chrome|rm to pipe the files to grep to ...
7
votes
2answers
6k views

Why does a new directory have a hard link count of 2 before anything is added to it?

Say I just create directory newDirectory and then I do ls -ld command. I see that the number of hard links is 2. What exactly makes the hard link 2 from the start? Also is the number of subdirectories ...
38
votes
7answers
7k 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, ...
50
votes
4answers
75k 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?
3
votes
3answers
343 views

List the first 4 lines of all the files in a given directory

What command could I create that will list the first 4 lines of all the files in a given directory?
5
votes
3answers
536 views

ls --color: how to color executable hard links?

I created some hardlinks on an NTFS drive, but because of that, they are all executable and colored as executable instead of as hardlinks (regular file with more than one link). I did a test on my ...