LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-19-2014, 07:02 AM   #1
technizia
LQ Newbie
 
Registered: Aug 2014
Posts: 6

Rep: Reputation: Disabled
Question "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
 
Old 08-19-2014, 07:55 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 8,012

Rep: Reputation: 799Reputation: 799Reputation: 799Reputation: 799Reputation: 799Reputation: 799Reputation: 799
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} .
 
Old 08-19-2014, 10:34 AM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,136

Rep: Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336
Quote:
Originally Posted by technizia View Post
Shell information : csh

Where am I wrong?
You're trying to use bash's extended globbing with csh.
 
Old 08-19-2014, 01:37 PM   #4
technizia
LQ Newbie
 
Registered: Aug 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
@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?
 
Old 08-19-2014, 02:19 PM   #5
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,136

Rep: Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336
Code:
Warning: Untested!
find . ! \( -name file1 -o -name file2 \) -delete
I think that should work in any shell.
 
Old 08-19-2014, 10:00 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,696

Rep: Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261Reputation: 1261
Quote:
Originally Posted by technizia View Post
@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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Please upgrade util-linux ("partx" e.g. is badly broken) Sl4ck3ver Slackware 1 08-06-2013 08:10 PM
error: Error for wireless request "Set Mode" (8B06) : invalid argument "roaming" penguin chick Linux - Wireless Networking 5 08-22-2008 01:16 PM
Regular expression matching , match "error string" but not "other error" jmcmillan Programming 3 07-07-2008 09:50 AM
How might I restore kmail folders/mail/settings from a "badly" saved "home"? deh6 Linux - Software 5 03-08-2008 09:25 PM
Samba "badly formed line in configuration file" maerong Linux - Networking 5 02-02-2005 05:19 PM


All times are GMT -5. The time now is 02:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration