jojo
jojo

Reputation: 331

list command grep current date output filename only

I would like to know how to list a file by current date and output filename only

my current command:

ls -l /var/www/html/test --time-style=+%D  | grep $(date +%D) 

output:

-rwxrwxr-x 1 root test  146 04/03/18 file1.txt
-rwxrwxr-x 1 root test  146 04/03/18 file2.txt

I tried ls /var/www/html/test --time-style=+%D | grep $(date +%D), and it didn't work.

basically, I want the output as filename only file1.txt and file2.txt

Upvotes: 1

Views: 1446

Answers (2)

soft87
soft87

Reputation: 511

ls -l /var/www/html/test --time-style=+%D | grep $(date +%D) | awk '{print $7}'

edit: formatting code

Upvotes: 1

Dudi Boy
Dudi Boy

Reputation: 4900

I believe find command is better for the task. Read this answer.

find /var/www/html/test -type f -newermt $(date +%F) 

I think it is more elegant solution.

Upvotes: 0

Related Questions