[英]Pipe find command output to ls command
需要pipe find command output to ls command限制ls
命令到某个日期。 按修改日期排序的过滤器,但我想要ls -lth --full-time
的格式。 find
命令为我提供了 365 天内最后修改的文件。
但是ls
向我展示了一切。
find . -mtime -365 | ls -lth --full-time
找到给我:
$ find . -mtime -365
.
./en_mapp
./main.py
./file1.txt
./file2.csv
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
从 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
使用带有终止加号的 find 的 exec 选项:
find . -mtime -365 -exec ls -lth --full-time '{}' +
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.