[ACCEPTED]-How to recursively list all files and directories-shell

Accepted answer
Score: 25

How about this:

find . -exec ls -dl \{\} \; | awk '{print $3, $4, $9}'

0

Score: 21

Use tree. Few linux distributions install it 5 by default (in these dark days of only GUIs :-), but 4 it's always available in the standard repositories. It 3 should be available for *BSD also, see http://mama.indstate.edu/users/ice/tree/

Use:

tree -p -u -g -f -i

or

tree -p -u -g -f

or 2 check the man page for many other useful 1 arguments.

Score: 20

Works in Linux Debian:

find $PWD -type f     

0

Score: 10

find comes close:

find . -printf "%u %g %p\n"

There is also "%P", which removes 5 the prefix from the filename, if you want 4 the paths to be relative to the specified 3 directory.

Note that this is GNU find, I 2 don't know if the BSD find also supports 1 -printf.

Score: 8

You've already got an answer that works, but 2 for reference you should be able to do this 1 on the BSDs (I've tested it on a mac) :

find . -ls
Score: 4

If you fancy using Perl don't use it as 3 a wrapper around shell commands. Doing it 2 in native Perl is faster, more portable, and 1 more resilient. Plus it avoids ad-hoc regexes.

use File::Find;
use File::stat;

find (\&myList, ".");

sub myList {
   my $st = lstat($_) or die "No $file: $!";

   print  getgrnam($st->gid), " ", 
          getpwuid($st->uid), " ", 
          $File::Find::name, "\n";
}
Score: 1

Simple way I found was this:

ls -lthr /path_to_directory/*

" * " - represents 1 levels.

Ajiths-MBP:test ajith$ ls -lthr *
test2:
total 0
-rw-r--r--  1 ajith  staff     0B Oct 17 18:22 test2.txt

test3:
total 0
-rw-r--r--  1 ajith  staff     0B Oct 17 18:22 test3.txt

test1:
total 0
-rw-r--r--  1 ajith  staff     0B Oct 17 18:21 test1.txt
drwxr-xr-x  3 ajith  staff    96B Oct 17 18:22 test1_sub_dir


Ajiths-MBP:test ajith$ ls -lthr */*
-rw-r--r--  1 ajith  staff     0B Oct 17 18:21 test1/test1.txt
-rw-r--r--  1 ajith  staff     0B Oct 17 18:22 test2/test2.txt
-rw-r--r--  1 ajith  staff     0B Oct 17 18:22 test3/test3.txt

test1/test1_sub_dir:
total 0
-rw-r--r--  1 ajith  staff     0B Oct 17 18:22 test1_sub_file.txt

More Related questions