[英]List files in current directory with full path using Bash
Situation 情况
I have the following Structure: 我有以下结构:
+ Folder 1
--20140410.txt
--20140409.txt
--20140408.txt
--20140407.txt
--20140406.txt
--20140405.txt
--20140404.txt
+ Folder 2
--20140410.txt
--20140409.txt
--20140408.txt
--20140407.txt
--20140406.txt
--20140405.txt
--20140404.txt
I need the "newest" (depending on the file name) 5 Files from that directory, including Path. 我需要“最新”(取决于文件名)该目录中的5个文件,包括Path。 Currently i'm using the following code to do so: 目前,我正在使用以下代码来做到这一点:
for i in `find /mydirectory/ -type d` ; do cd $i && ls *.* | sort -n -r | head -5 >> /mydirectory/myfile.txt ; done
So for every directory I find, I list the files, inverse-sort them by name and cut after line 5. 因此,对于找到的每个目录,我都会列出文件,然后按名称对它们进行反排序,并在第5行后剪切。
Here's the result: 结果如下:
20140410.txt
20140409.txt
20140408.txt
20140407.txt
20140406.txt
20140410.txt
20140409.txt
20140408.txt
20140407.txt
20140406.txt
How do i write the current working directory "before" the file name? 如何在文件名“之前”写入当前工作目录?
代替解析ls ,再次使用find
:
for i in $(find /mydirectory/ -type d); do cd $i && find $PWD -type f -name "*.*" | sort -nr | head -5 >> /mydirectory/myfile.txt; done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.