Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'mv' command throwing error but executing fine in docker

When I execute the following command (which moves all files with the .txt and .sbreaks extension to another folder):

sudo docker exec name mv xyz/data/outputs/*.{sbreaks,txt} <>/data/spare

I get the following error:

mv: cannot stat ‘xyz/data/outputs/*.sbreaks’: No such file or directory
mv: cannot stat ‘xyz/data/outputs/*.txt’: No such file or directory

But, when I go into docker via sudo docker exec -it name bash and execute the same command: mv xyz/data/outputs/*.{sbreaks,txt} xyz/data/spare, it executes fine.

What am I doing wrong here?

PS: Both local and the Docker container are ubuntu environments

like image 508
Dawny33 Avatar asked Mar 26 '26 19:03

Dawny33


1 Answers

That is because the * is expanded by a shell program (i.e. bash). (Psst, this is typical interview question).

So pass your command to a shell and let it launch the mv for you:

sudo docker exec cypher bash -c 'mv xyz/data/outputs/*.{sbreaks,txt} .......'

When you do docker exec some_program some_param, docker searches for some_program and executes it directly without doing anything extra, and just pass some_param as a parameter (a star in your case). mv expects real file names, and not *.

like image 150
Robert Avatar answered Mar 28 '26 10:03

Robert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!