Questions tagged [ls]

A utility in Unix-like systems such as Linux used for listing files and directories.

A utility in Unix and Unix-like operating systems used for listing files and directories. It is analogous to the dir command used in DOS and Windows.

Documentation

1314 questions
1259
votes
29 answers

Listing only directories using ls in Bash?

This command lists directories in the current path: ls -d */ What exactly does the pattern */ do? And how can we give the absolute path in the above command (e.g. ls -d /home/alice/Documents) for listing only directories in that path?
Sibi
  • 47,472
  • 16
  • 95
  • 163
638
votes
26 answers

How can I get a recursive full-path listing, one line per file?

How can I spit out a flat list of recursive one-per-line paths? For example, I just want a flat listing of files with their full…
dreftymac
  • 31,404
  • 26
  • 119
  • 182
462
votes
1 answer

Count number of files within a directory in Linux?

To count the number of files in a directory, I typically use ls directory | wc -l But is there another command that doesn't use wc ?
Kantura
  • 5,763
  • 5
  • 18
  • 17
409
votes
28 answers

How can I generate a list of files with their absolute path in Linux?

I am writing a shell script that takes file paths as input. For this reason, I need to generate recursive file listings with full paths. For example, the file bar has the path: /home/ken/foo/bar but, as far as I can see, both ls and find only give…
Ken
  • 77,016
  • 30
  • 84
  • 101
335
votes
8 answers

How do I list one filename per output line in Linux?

I'm using ls -a command to get the file names in a directory, but the output is in a single line. Like this: . .. .bash_history .ssh updater_error_log.txt I need a built-in alternative to get filenames, each on a new line, like this: . .. …
fixxxer
  • 15,568
  • 15
  • 58
  • 76
253
votes
14 answers

List files recursively in Linux CLI with path relative to the current directory

This is similar to this question, but I want to include the path relative to the current directory in unix. If I do the following: ls -LR | grep .txt It doesn't include the full paths. For example, I have the following directory…
Darryl Hein
  • 142,451
  • 95
  • 218
  • 261
241
votes
1 answer

How to list files in windows using command prompt (cmd). I've tried using ' ls ' as in Linux but it shows an error?

When I tried to use list ls on a Windows command prompt, the system doesn't recognize it. I already added C:\Windows\System32 in the path.
Abdullah
  • 2,531
  • 3
  • 13
  • 15
215
votes
8 answers

Linux delete file with size 0

How do I delete a certain file in linux if its size is 0. I want to execute this in an crontab without any extra script. l filename.file | grep 5th-tab | not eq 0 | rm Something like this?
Franz Kafka
  • 10,623
  • 20
  • 93
  • 149
181
votes
7 answers

How can I list (ls) the 5 last modified files in a directory?

I know ls -t will list all files by modified time. But how can I limit these results to only the last n files?
Ryan
  • 14,682
  • 32
  • 106
  • 179
171
votes
14 answers

Sort 'ls' output by name

Can you sort an ls listing by name?
Devang Kamdar
  • 5,617
  • 8
  • 24
  • 16
134
votes
10 answers

How to get a list of file names in different lines

I want to get a list of all the files in a directory, like with ls, so that each filename will be on a seperate line, without the extra details supplied by ls -l. I looked at ls --help and didn't find a solution. I tried doing ls -l | cut --fields=9…
Amir Rachum
  • 76,817
  • 74
  • 166
  • 248
130
votes
19 answers

How to create ls in windows command prompt?

I want to use ls in windows command prompt and make it run the dir command. How can I do that?
aF.
  • 64,980
  • 43
  • 135
  • 198
114
votes
3 answers

How do I assign ls to an array in Linux Bash?

array=${ls -d */} echo ${array[@]} I have three directories: ww ee qq. I want them in an array and then print the array.
Jordin Youssef
  • 1,147
  • 2
  • 7
  • 4
110
votes
13 answers

How to display only files from aws s3 ls command?

I am using AWS CLI to list the files in an AWS S3 bucket using the following command (aws s3 ls): aws s3 ls s3://mybucket --recursive --human-readable --summarize This command gives me the following output: 2013-09-02 21:37:53 10 Bytes…
Borealis
  • 8,044
  • 17
  • 64
  • 112
104
votes
14 answers

To show only file name without the entire directory path

ls /home/user/new/*.txt prints all txt files in that directory. However it prints the output as follows: [me@comp]$ ls /home/user/new/*.txt /home/user/new/file1.txt /home/user/new/file2.txt /home/user/new/file3.txt and so on. I want to run…
Ashish
  • 1,153
  • 2
  • 7
  • 12
1
2 3
87 88