The ls command lists the contents of a directory.

learn more… | top users | synonyms

2
votes
1answer
112 views

cd and ls in the same call [duplicate]

I often have to cd to a directory and ls to see the directory listing. Can it be done with one shot, so that I can add to .bashrc as alias. I searched on Google, there were some answers, but ...
4
votes
4answers
423 views

linux + how to ignore (filter) file with space

Sometimes a file name is created from a couple of names and space between each name as the following: $ touch "A B C" $ ls A B C <-- one file but has three words ! ...
4
votes
3answers
1k views

Something's special about /dev/fd/3

I've been trying to learn about file descriptors. When I type "ls -l /dev/fd/" I get lrwx------ 1 me users 64 May 2 16:02 0 -> /dev/pts/5 l-wx------ 1 me users 64 May 2 16:02 1 -> ...
2
votes
3answers
941 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 ...
5
votes
3answers
371 views

When you type “ls -a”, what is the significance of “.” and “..”?

Whenever you type ls -a into the command prompt, you usually get all of your folders, files, and then you see that the first two entries are . and .. Just curious, but what is the significance of ...
8
votes
2answers
5k 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 ...
2
votes
6answers
1k views

sort ls output by users

On Linux, is there a way to sort ls output by users? What I try to achieve is something like this: user_a   file1 user_a   file2 user_b   another_file user_c   this_file user_c ...
1
vote
1answer
335 views

ls -ld /dir, Solaris [duplicate]

Always when I run ls -ld /dir the output give me the size = 512 even if there are files in it or not. but when I run du -sh the output give me the actual size of the directory including its content.
4
votes
1answer
986 views

Pass colors from ls through pipe to awk 'print' statement

This is a follow-up to my question from yesterday, Show sum of file sizes in directory listing. Thanks to Zero Piraeus and a point in the right direction by Mauritz Hansen, I now have function ...
2
votes
2answers
180 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
103 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
246 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
3k 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 ...
1
vote
1answer
820 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 ...
10
votes
2answers
615 views

Highlight the three last updated files in ls output

Is there any way to overload or wrap the ls command so that it will highlight / underline / otherwise make obvious the last three modified files? I know that I can simply ls -rtl to order by reverse ...
1
vote
1answer
141 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
726 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
108 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 ...
5
votes
4answers
601 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 ...
3
votes
2answers
471 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 ...
6
votes
1answer
2k 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 ...
19
votes
2answers
8k 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. ...
4
votes
4answers
377 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 ...
1
vote
1answer
680 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
658 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
7k 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 ...
4
votes
2answers
553 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 ...
3
votes
0answers
956 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 ...
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.
9
votes
4answers
5k 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, ...
4
votes
2answers
807 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
243 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 ...
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 ...
3
votes
3answers
3k views

How to search and replace text in all php-files in a directory and it's subdirectories

I am looking for a shell script that recursively traverses all .php files in a directory and performs a search & replace of a particular text pattern. The search pattern is quite long ( > 5000 ...
1
vote
1answer
613 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 ...
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 ...
3
votes
5answers
476 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
683 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
2answers
2k views

How to list files and directories with directories first

I have two questions. First, which command lists files and directories, but lists directories first? Second question: I want to copy a list of files into a single directory, but make the target ...
5
votes
3answers
311 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 ...
0
votes
1answer
489 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 ...
12
votes
1answer
7k 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 ...
1
vote
1answer
558 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 ...
2
votes
2answers
8k 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
4k 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?