简体   繁体   English

Pipe 找到命令 output 到 ls 命令

[英]Pipe find command output to ls command

Need to pipe find command output to ls command limiting ls command to a certain date.需要pipe find command output to ls command限制ls命令到某个日期。 Sort of a filter by date modified but I want with the format of the ls -lth --full-time .按修改日期排序的过滤器,但我想要ls -lth --full-time的格式。 The find command gives me last modified files within 365 days. find命令为我提供了 365 天内最后修改的文件。
But ls shows me everything.但是ls向我展示了一切。

find . -mtime -365 | ls -lth --full-time

find gives me:找到给我:

$ find . -mtime -365
.
./en_mapp
./main.py
./file1.txt
./file2.csv

And ls -lth --full-time gives me: ls -lth --full-time 给我:

$ ls -lth --full-time
total 8.0K
-rw-r--r--. 1 root root  174 2020-09-21 10:59:26.858601430 +0200 main.py
-rw-r--r--. 1 root root    0 2020-09-21 09:36:17.072137720 +0200 file2.csv
drwxr-xr-x. 2 root root 4.0K 2020-09-21 09:35:48.296169162 +0200 en_mapp
-rw-r--r--. 1 root root    0 2020-09-21 09:35:28.502502950 +0200 file1.txt
-rw-r--r--. 1 root root    0 2012-01-01 00:00:00.000000000 +0100 goldenfile.xls

xargs takes input from stdin and passes it as arguments to some command. xargs从 stdin 获取输入并将其作为 arguments 传递给某个命令。

find . -mtime -365 | xargs ls -lth --full-time
# or better with no dirs and handle spaces and quotes in filename
find . -type f -mtime -365 | xargs -d '\n' ls -lth --full-time
# or better - handle newlines in filenames
find . -mtime -365 -print0 | xargs -0 ls -lth --full-time

Use the exec option of find with a terminating plus:使用带有终止加号的 find 的 exec 选项:

find . -mtime -365 -exec ls -lth --full-time '{}' +

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM