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.

Most Use Action

Option - Action

-a - list hidden files

-d - list the name of the current directory

-F - show directories with a trailing '/' executable files with a trailing '*'

-g - show group ownership of file in long listing

-i - print the inode number of each file

-l - long listing giving details about files and directories

-R - list all subdirectories encountered

-t - sort by time modified instead of name

Documentation

1200 questions
1066
votes
26 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
  • 43,989
  • 14
  • 80
  • 146
535
votes
25 answers

ls command: how can I get a recursive full-path listing, one line per file?

How can I get ls to 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
  • 27,818
  • 25
  • 108
  • 169
376
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
  • 4,573
  • 5
  • 15
  • 17
337
votes
24 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
  • 71,088
  • 29
  • 81
  • 100
268
votes
7 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
  • 13,562
  • 14
  • 54
  • 74
232
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
  • 134,677
  • 87
  • 206
  • 257
191
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
  • 9,999
  • 17
  • 86
  • 145
179
votes
1 answer

'ls' in CMD on Windows is not recognized

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
  • 1,895
  • 3
  • 10
  • 15
146
votes
5 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,115
  • 29
  • 92
  • 163
141
votes
13 answers

Unix's 'ls' sort by name

Can you sort an ls listing by name?
Devang Kamdar
  • 4,867
  • 6
  • 22
  • 16
120
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
  • 67,681
  • 68
  • 159
  • 239
118
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.
  • 58,798
  • 40
  • 127
  • 191
94
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
  • 947
  • 1
  • 6
  • 4
80
votes
12 answers

How to get file creation date/time in Bash/Debian?

I'm using Bash on Debian GNU/Linux 6.0. Is it possible to get the file creation date/time? Not the modification date/time. ls -lh a.txt and stat -c %y a.txt both only give the modification time.
NoodleFolk
  • 1,701
  • 1
  • 12
  • 23
77
votes
13 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
  • 883
  • 1
  • 6
  • 11
1
2 3
79 80