-4

I want to move all .XML files in the current working directory whose name starts with DAPRETAIL followed by the current date in YYYYMMDD format to a separate directory.

I tried:

DATE='date +%Y%m%d'
mv DAPRETAIL${DATE}*.XML /some/destination

But it returns a: mv: cannot stat 'date +%Y%m%d' error.

4
  • I don't want to change file name just move the file name using date in file name Commented Aug 11, 2024 at 19:37
  • 3
    Use date=$(...) in place of DATE='...' and "$date" in place of ${DATE}. Commented Aug 12, 2024 at 7:03
  • 1
    Examples? What system are you running this on (not putty, but the system itself) Commented Aug 12, 2024 at 8:21
  • 1
    It can't return the stated error with the code example you've provided Commented Aug 12, 2024 at 8:22

1 Answer 1

-2
dt=$(date +%Y%m%d)

mv DAPRETAIL$dt*.XML destination_folder_path
2
  • 1
    I suspect (but I don't know) that the downvote for your code is because you haven't explained what's going on Commented Aug 12, 2024 at 23:40
  • 1
    I would further suggest, looking at your answer history, that your series of negative scores is at least partly due to the lack of explanations generally. Code solves the problem, sure, but doesn't necessarily teach the person asking the question how to apply your answer in a different situation Commented Aug 12, 2024 at 23:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.