Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove file from different directory

Tags:

bash

shell

How do I remove certain files from a different directory than $PWD using the bash shell script.

Looking at the documentation for rm, it appears that rm only works in $PWD.

Am I forced to use this method:

oDir=$PWD
cd directorytoremovefiles
rm files
cd oDir
like image 903
Elpezmuerto Avatar asked Aug 06 '26 13:08

Elpezmuerto


1 Answers

rm certainly does work for deleting files in another directory.

Whatever gave you that idea from the man page, I certainly hope it's not this:

rm removes each specified file. By default, it does not remove directories.

The documentation you refer to, talks only about having write & execute permission to the directory you are deleting from.

So you only need:

rm directorytoremovefiles/files

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!