Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question