LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   "Badly placed ()'s." error while trying to do selective rm -rf (https://www.linuxquestions.org/questions/linux-newbie-8/badly-placed-s-error-while-trying-to-do-selective-rm-rf-4175515449/)

technizia 08-19-2014 07:02 AM

"Badly placed ()'s." error while trying to do selective rm -rf
 
Hi,

My directory consists of different files and folders. I want to delete all but 2 files. I'm invoking the following command.

rm -rf !(file1|file2) where file1 and file2 are the files I want to keep.

Upon executing the above command I see this error : Badly placed ()'s.

Shell information : csh

Where am I wrong?

Thanks,
Technizia

business_kid 08-19-2014 07:55 AM

You are asking for trouble, as linux does have a friendly undelete facility. Try something like

Code:

cp file1 file2 /tmp
rm -rf <whatever>
mv /tmp/{file1,file2} .


ntubski 08-19-2014 10:34 AM

Quote:

Originally Posted by technizia (Post 5223562)
Shell information : csh

Where am I wrong?

You're trying to use bash's extended globbing with csh.

technizia 08-19-2014 01:37 PM

@business_kid I want to remove the other files without doing the copy and move back.

@ntubski Is there a similar approach that can be used in csh?

ntubski 08-19-2014 02:19 PM

Code:

Warning: Untested!

find . ! \( -name file1 -o -name file2 \) -delete

I think that should work in any shell.

jpollard 08-19-2014 10:00 PM

Quote:

Originally Posted by technizia (Post 5223721)
@business_kid I want to remove the other files without doing the copy and move back.

@ntubski Is there a similar approach that can be used in csh?

mv doesn't copy unless you are moving the file to a different filesystem.


All times are GMT -5. The time now is 08:36 AM.