1

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

Vinicius Placco
  • 1,683
  • 2
  • 14
  • 24
jojo
  • 291
  • 4
  • 13
  • 1
    Do you want to output a list of all files, sorted by date? Or just files with a specific date? – match Apr 03 '18 at 20:24

2 Answers2

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

edit: formatting code

kyodev
  • 573
  • 2
  • 14
soft87
  • 482
  • 2
  • 16
0

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.

Dudi Boy
  • 4,551
  • 1
  • 15
  • 30