I have some files like T24_STFBNK_CUSTOMER_2018100107553815383733380046446200.txt. The bold numbers 20181001
is the date of the file,I need a shell script to list the files which its date is yesterday only! how can I do this?
Asked
Active
Viewed 1,315 times
0

Tarek Sayed
- 23
1 Answers
1
Use the date
command:
date --date=yesterday +%Y%m%d
20181103
You can substitute it in a string with:
$ echo pre__"$(date --date=yesterday +%Y%m%d)"__post
pre__20181103__post
If you understand this, you can now use ls
and globbing, adjusting the searched pattern as needed. Eg.:
$ ls *pre__"$(date --date=yesterday +%Y%m%d)"__post*
pre__20181103__post
This has listed the file pre__20181103__post
present in the current directory.
20181001
, you don't have to produce it with any automatic tool. It is a valid string itself. – Nov 04 '18 at 13:22ls
. https://unix.stackexchange.com/questions/128985/why-not-parse-ls-and-what-do-to-instead – Nov 04 '18 at 18:13