How to recursively list all files and directories

前端 未结 8 1751
长发绾君心
长发绾君心 2021-02-01 03:32

Using the tcsh shell on Free BSD, is there a way to recursively list all files and directories including the owner, group and relative path to the file?

ls -alR comes cl

8条回答
  •  失恋的感觉
    2021-02-01 04:05

    Use a shell script. Or a Perl script. Example Perl script (because it's easier for me to do):

    #!/usr/bin/perl
    use strict;
    use warnings;
    foreach(`find . -name \*`) {
      chomp;
      my $ls = `ls -l $_`;
      # an incomprehensible string of characters because it's Perl
      my($owner, $group) = /\S+\s+\S+\s+(\S+)\s+(\S)+/;
      printf("%-10s %-10s %s\n", $owner, $group, $_);
    }
    

    Perhaps a bit more verbose than the other answers, but should do the trick, and should save you having to remember what to type. (Code untested.)

提交回复
热议问题