我想递归地搜索一个目录,并输出:
文件名日期路径大小
我什么都有但Path...which是$$$$buster..。
到目前为止,我的命令如下:
ls -lThR {DIRECTORY_NAME_HERE} | awk '/^-/ {print $10 " " $6 " " $7 " " $8 " " $5}'我希望有办法将这一命令与以下内容结合起来:
find ./{DIRECTORY_NAME_HERE} -type f 它只显示/path/to/filename itself...no其他元数据afaik。
任何不需要编程语言的ideas...hopefully?
编辑:假设文件是5个字节,下面是我想要的确切输出:
myfile.txt 12月2日10:58 /path 5
UPDATE:下面是我最后得到的命令:
find ./{DIRECTORY_NAME_HERE} -type f -ls |
while read f1 blocks perms blocks owner group size mon day third file;
do echo `basename $file` `ls -lrt $file | tr -s " " | cut -d" " -f6-8` `dirname $file` `ls -lrt $file | tr -s " " | cut -d" " -f-5`; done如果有人能改进的话,那就太好了,但这很管用.
发布于 2010-12-04 01:45:57
还可以使用find的-printf特性来显示所需文件的正确属性:
find {DIRECTORY_NAME_HERE} -type f -printf '%f %Tb %Td %TH:%TM %h %s\n'我得到了这样的结果:
config Nov 10 10:02 /etc/w3m 1185
mailcap Nov 10 10:02 /etc/w3m 44
hosts.allow Apr 29 05:25 /etc 580
rsyslog.conf Feb 24 10:26 /etc 1217
user-dirs.conf Apr 16 15:03 /etc/xdg 414
user-dirs.defaults Apr 16 15:03 /etc/xdg 418发布于 2010-12-04 19:15:52
我会在这个任务中使用Perl:
#!/opt/local/bin/perl -w
use File::Find;
use POSIX qw(strftime);
find(\&wanted, ($DIRECTORY_NAME_HERE));
sub wanted {
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime) = stat;
printf("%s %s %s %d\n", $_,
strftime("%b %e %H:%M %Y", localtime($mtime)),
$File::Find::dir,
$size);
}https://stackoverflow.com/questions/4351096
复制相似问题