Ajinkya
Ajinkya

Reputation: 83

list the multiple file in directory

I want to list below multiple file daily so I need the list the file by date should select from system only in file name.

ls -lrt test_20160322.csv 

I am getting error while using below command :-

ls -lrt test_${date +"%Y%m%d"}

-bash: ${date +"%Y%m%d"}: bad substitution

Upvotes: 1

Views: 46

Answers (2)

Andreas Louv
Andreas Louv

Reputation: 47099

Your substitution is wrong you need a command substitution:

ls -lrt test_$(date +"%Y%m%d")

Please note that I changed { and } with ( and ).

Also note that command substitutions will undergo word splitting and should usually be quoted, though in your exact case this will not be the problem.

Upvotes: 2

Maroun
Maroun

Reputation: 95948

You should change it to:

ls -lrt test_$(date +"%Y%m%d")
              ↑              ↑

Upvotes: 2

Related Questions