Tagged Questions

The ls command lists the contents of a directory.

learn more… | top users | synonyms

7
votes
7answers
16k 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 ...
2
votes
2answers
172 views

Can I `ls` all files in a directory from “1”, “2”,…,“9”, “10”, “11”, …, “20”, “21”, …?

I have a directory with files named "1", "2",...,"9", "10", "11", ..., "20", "21", ... inside. Can I list them in the order of "1", "2",...,"9", "10", "11", ..., "20", "21", ...? I have tried ls ...
2
votes
1answer
100 views

Which option of ls should be used for understanding metadata changes?

How can one find the latest time of metadata changes to a file? Let's say I changed the ownership of a file and then I did ls -l. It still shows the latest file changes. But I want to see the time ...
0
votes
1answer
220 views

What is the @ after directory listing mean? [duplicate]

so I have some files in a directory and when I type ls -l I get -rw-r--r-- 1 home staff 275 Apr 9 16:01 index.js -rwxr-xr-x@ 1 home staff 2565 Apr 8 10:38 person.js -rwxr-xr-x@ 1 home ...
1
vote
4answers
3k views

Is there a command to list files, exclude sub-directories and display size and date?

Before I begin please assume I have only basic knowledge in UNIX. Basic meaning I have only started reading about it since last week for a work related purpose. I have been experimenting with the ls ...
5
votes
1answer
2k views

Listing both ls information and mount points of a directory?

On my Ubuntu Natty, typically all new drives inserted (e.g. USB Flash thumbdrives) are mounted under /media. So, on my system, I can do something like this: $ mount | grep '/media' /dev/sda6 on ...
3
votes
7answers
5k 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 | ...
1
vote
1answer
758 views

What is a sure fire way to find all files and/or path that contains 2 keywords?

I was doing a find . -iname '*sitesearch*' | grep demo because I know the file should be some/path/SiteSearch/demo/SiteSearch.html, but it turned out a person put the file in as ...
0
votes
1answer
2k views

Must parse ls -Al output and get file or directory name [duplicate]

I must parse ls -Al output and get file or directory name ls -Al output : drwxr-xr-x 12 s162103 studs 12 march 28 2012 personal domain drwxr-xr-x 2 s162103 studs 3 march 28 ...
3
votes
3answers
4k views

output only file names(with spaces) in ls -Al

I should echo only names of files or directories with this construction: ls -Al | while read string do ... done ls -Al output : drwxr-xr-x 12 s162103 studs 12 march 28 12:49 personal ...
1
vote
1answer
131 views

mark or color empty directories for `ls`

ls's -F flag allows to see the types of file and distinguish directories. Is there a way to add a functionality to distinguish an empty directory?
2
votes
2answers
679 views

Working of rm/ls with [0-9]

I am learning the shell commands and came across the short tags eg.[0-9],[[:digit:]] etc.. As a proof of concept i tried deleting all the files with the rm command(i know its not a good practise but i ...
1
vote
1answer
106 views

starting vim with command substitution

I am working on a project on two different machines - one running Mac OSX 10.8.3, and one running Red Hat Enterprise Linux. On my Mac, I can do this: vim $(ls -R */*.@(h|cpp) */*/*.@(h|cpp)) and ...
2
votes
3answers
914 views

Find directories that do not contain subdirectories

I'm writing script is ksh. Need to find all directory names directly under the current directory which contain only files, not subdirectories. I know that I could use ls -alR and recursively parse ...
3
votes
2answers
456 views

Why do . and .. have a file size of 4 kB and 12 kB, respectively? [duplicate]

As displayed by ls -al, for example: drwxr-xr-x 9 jb jb 4.0K Mar 8 18:05 ./ drwx------ 49 jb jb 12K Mar 17 14:15 ../ I assume this is the minimum amount of space required to store the inode's ...
5
votes
4answers
584 views

Shell command to get all the files from a complex directory structure

I'm looking for a shell command in order to get all the files in a complex directory structure. By complex directory structure I mean that there's a root folder with more than 150 subfolders and for ...
6
votes
1answer
1k views

`ls` command does not list latest directory contents

The Linux shell does not print up-to-date information when it comes to ls. For example I use my other processes (IDEs etc) to create some directories. However when I run an ls command I don't see ...
1
vote
1answer
649 views

Total vs listed directories [duplicate]

On a server when I type in ls -al I get a list of the directories -bash-3.2$ ls -al total 12 drwxr-xr-x 3 root root 0 Feb 13 2011 . drwxr-xr-x 4 root root 4096 May 11 2011 .. drwxr-xr-x 55 ...
3
votes
2answers
134 views

customise ls color for directories contain specified file/s

How can I colorize directories contain files with word INCORRECT inside? Example: I have 3 directories which contain log file. dir_a/log dir_b/log dir_c/log The file log in dir_c contain word ...
1
vote
2answers
632 views

Ignore all matches to negated extglob pattern in recursive ls

I would like to recursively list all files in a directory which match a given input pattern using ls. (Oh, and this is in Bash). The only way I can think of to do this using ls is to shopt -s extglob ...
4
votes
2answers
6k views

list all files newer than given timestamp and sort them

I want to list all files (sorted by date) that are newer than timestamp in format 20130207003851 in directory /tmp only. Subdirectories can be omitted. Using SUSE Linux Enterprise Server 11. The ...
3
votes
0answers
924 views

ls and vim color on SunOS 5.8/Solaris 8

I want to use ls and vim with color on Sunos 5.8 SunOS 5.8 Generic_117350-11 sun4u sparc SUNW,Sun-Blade-2500 I have installed ls (GNU coreutils) 6.9 and vim 7.2 In ~/.cshrc: setenv TERM sun-color ...
4
votes
2answers
542 views

Get the complement of the result of an ls command

Let's say I have a directory with multiple files, all of which are either binary files (files with no declared extensions) and source files (.c extension). I do this: $ ls and get: README.md ...
2
votes
1answer
1k views

How does wc -l `ls` give the actual number of lines?

Can anyone explain to me how does this command work. wc -l `ls` while this command gives the total number of java lines or txt lines.
11
votes
2answers
28k 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?
4
votes
2answers
752 views

Number of lines outputted by ls

When ls is called, it outputs all the files/directories in the current directory, attempting to fit as many as possible on each line. Why is it that when passed to wc -l, it outputs the number of ...
2
votes
1answer
225 views

Local, regular file causes `stat` or `ls -l` to hang

I've seen a few different questions about ls hanging. It's usually because they use the -l switch, which causes a stat on the file, which in turn is a bad symlink or pointing to an NFS mount or some ...
37
votes
6answers
6k 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 ...
0
votes
1answer
1k views

How to display directory permission without listing permission for their contents [duplicate]

Possible Duplicate: How can I make ls show information about the directory specified only, not info about its sub-files or folder contents? I am new to UNIX and I want to display the ...
1
vote
1answer
598 views

Please explain the output of the ls -all command

This is one of the many similar lines from the output from ls -all lrwxrwxrwx 1 subhrcho dba 25 Dec 6 01:36 beam-server.jpr -> .ade_path/beam-server.jpr What does the above signify ? I am ...
4
votes
4answers
2k views

List all files / binaries in current PATH

Is there an "easy" way of running an "ls -la" style command for listing all files / executable binaries in the current PATH? (I intend to pipe the output into grep, for looking for commands with ...
3
votes
5answers
468 views

Print non-existent files from a pipe input

I have a directory of lots of .PDF and .JPG files. There should be a .JPG file for each .PDF with the same name. I'm trying to use a command to find .PDF files that doesn't have a .JPG file. My ...
4
votes
2answers
658 views

how to use grep for specific files?

for example I type ls -altr | grep "23 Dec" so it will show files for 23 Dec only and I want to use grep for them, like ls -altr | grep "23 Dec" | xargs grep -l "some_string" but this doesn't ...
5
votes
3answers
305 views

What's the best way to list size of / in Terminal?

I want to see how much total space / is taking, but I don't know how to do that. I can use ls -hal and add up the subtotals, or I can use fdisk to tell me the size of that partition, but is there a ...
13
votes
2answers
6k 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 ...
0
votes
1answer
462 views

difficalty to save traceroute output in shell variable?

I need to filter and store traceroute output in shell variable (array). But I am getting some unusual output. As I try to explain in following lines. My present directory is temp, having some ...
1
vote
5answers
2k views

Identify folder in bash

I was trying to learn how to identify only folders within a folder on the main level. example: main -folder 1 -folder 2 -folder 3 I started with this script: #!/bin/bash ...
3
votes
3answers
540 views

Different count for compressed file listing vs directory listing

I was taking a backup of a folder, where I used the following command : sudo tar -zcvf www.tar.gz /var/www/ It successfully compressed, just for verifying the number of files in the compressed ...
1
vote
1answer
537 views

Why ls -lrth and ls -ltch gives different results

I was trying to find the time of database backup. Normally i use ls -ltch But this time i used ls -lrth It gave me different result for One file and all date-stamps were same for both ...
4
votes
2answers
2k 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 ...
2
votes
2answers
7k views

Solaris + display file time stamp [year][month][day]

I have Solaris 10 machine I need to verify time stamp of some file in my Solaris machine And to get the following format [year][month][day] Example of working command on Linux ls -l ...
3
votes
2answers
3k views

Displaying the last N modified files?

How can I list the 10 most recently modified files of a certain extension, not all files, or the files modified during the last 2 days for example?
1
vote
2answers
118 views

Are there any pitfalls to overriding ls?

Is there anything to watch out for if you wanted to override ls? Is there a more reliable way of getting pagination out of ls? For example: function ls() { command ls -hp $@ | more; }
7
votes
2answers
196 views

Different colour for the KiB range in `ls -l`

Is there any sane way to highlight the 4th, 5th, and 6th columns from the right of the file size in ls -l? My intention is to make it easy to read a file size be it in bytes, KiBs, or MiBs. I do know ...
4
votes
3answers
3k views

what is total in the output of ls command [duplicate]

Possible Duplicate: ls command: what does the first line mean? I have an empty directory.I am using following command to view the contents of that directory. ls -lart The output I get is ...
4
votes
4answers
367 views

List any file ending with .in and corresponding .out with shell script

I have a directory full of files ending with different extensions, how would I list/select only the files ending with .in and corresponding .out that share the same basename? e.g. file1.txt file1.in ...
6
votes
1answer
743 views

Why could the size of the “dot” file “.” exceed 4096?

Today I found an "empty" directory with a size of 4MB. It had no visible contents, so I tried ls -lah. This showed me some hidden files (not very large). Searching for the reason why the directory ...
5
votes
3answers
352 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 ...
2
votes
4answers
12k 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 ?
1
vote
1answer
1k views

Very basic question, ls a different directory and save file

I seriously can't understand where I'm going wrong with his question. The first part is. List all the file and directory names in /etc which have 1 or more numbers in their name. Remember to use ...