anonymously132526
anonymously132526

Reputation: 177

Pipe find command output to ls command

Need to pipe find command output to ls command limiting ls command to a certain date. Sort of a filter by date modified but I want with the format of the ls -lth --full-time. The find command gives me last modified files within 365 days.
But ls shows me everything.

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
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

Upvotes: 0

Views: 5296

Answers (2)

ceving
ceving

Reputation: 23824

Use the exec option of find with a terminating plus:

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

Upvotes: 2

KamilCuk
KamilCuk

Reputation: 140970

xargs takes input from stdin and passes it as arguments to some command.

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

Upvotes: 4

Related Questions