A
A
Anton2020-01-07 15:51:48
linux
Anton, 2020-01-07 15:51:48

How to copy file with dynamic name in bash?

There is a folder where files with random names arrive ( 10275_20191228125519.xml , 10275_20191228124422.xml, etc.)
I would like to take the last downloaded file and copy it to another folder, overwriting the existing one. head -n 1 I will copy like this cp random_name ../../another_folder PS Along the way, it is desirable to clean the files in this folder, so that the last one always remains.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Semenov, 2020-01-07
Semenov

Found the answer myself:

cp -fv "$(ls -t1 /home/user/public_html/*.xml | head -n 1)" /home/user/public_html/xmlfilename.xml

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question