簡體   English   中英

Pipe 找到命令 output 到 ls 命令

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM