LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-06-2016, 03:53 AM   #1
hilou
Member
 
Registered: May 2013
Posts: 93

Rep: Reputation: Disabled
rm to exclude file


I am using !(filename) sytax to exclude file from rm command.

It's working when I run it directly in bash.

But not working when used in a ssh command like below:

ssh 10.23.10.138 'rm -rf /tmp/td/d1/d2/!(*.py)'
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `rm -rf /tmp/td/d1/d2/!(*.py)'

Can someone tell me why ?

Thank you in advance!
 
Old 04-06-2016, 04:39 AM   #2
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,645

Rep: Reputation: 278Reputation: 278Reputation: 278
run: shopt -s extglob

then try running the command again it should be okay.

to turn off: shopt -u extglob
 
Old 04-06-2016, 04:42 AM   #3
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,667

Rep: Reputation: 494Reputation: 494Reputation: 494Reputation: 494Reputation: 494
Login first and run bash as local.
 
Old 04-06-2016, 06:51 AM   #4
hilou
Member
 
Registered: May 2013
Posts: 93

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by JJJCR View Post
run: shopt -s extglob

then try running the command again it should be okay.

to turn off: shopt -u extglob
Nope, tested not working.
 
Old 04-06-2016, 06:51 AM   #5
hilou
Member
 
Registered: May 2013
Posts: 93

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by malekmustaq View Post
Login first and run bash as local.
I will need to run this in a script.
 
Old 04-06-2016, 07:11 AM   #6
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,667

Rep: Reputation: 494Reputation: 494Reputation: 494Reputation: 494Reputation: 494
Quote:
I will need to run this in a script.
Put and run the script in the host remote machine.
 
Old 04-06-2016, 01:54 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,844

Rep: Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478Reputation: 1478
I think the sshd is getting confused between a command and a shell...

You might try
Code:
ssh 10.23.10.138 bash -c 'rm -rf /tmp/td/d1/d2/!(*.py)'
 
Old 04-06-2016, 11:18 PM   #8
hilou
Member
 
Registered: May 2013
Posts: 93

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
I think the sshd is getting confused between a command and a shell...

You might try
Code:
ssh 10.23.10.138 bash -c 'rm -rf /tmp/td/d1/d2/!(*.py)'
Same error!
 
Old 04-07-2016, 01:50 AM   #9
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,645

Rep: Reputation: 278Reputation: 278Reputation: 278
as Jpollard suggested try double quotes:

Quote:
ssh 10.23.10.138 bash -c "rm -rf /tmp/td/d1/d2/!(*.py)"
 
Old 04-07-2016, 10:15 AM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,360

Rep: Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001
You might also include "-v" in the bash options so that you can see what command line actually got passed.
 
Old 04-07-2016, 12:14 PM   #11
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179
You probably need to use single-quotes to enclose the command, which then itself includes quotes to tell the shell on the other side not to do its own expansion.

But I admit that I'm getting a little froggy about this. I'd use ssh to execute some sort of script on the remote side which does your bidding.
 
  


Reply

Tags
linux, rm


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
Using Find with an exclude/exclude file metallica1973 Linux - General 8 11-06-2011 10:39 PM
[SOLVED] Tar using include-file and exclude file one liner? metallica1973 Linux - Server 5 10-20-2011 03:25 PM
CVS Exclude : Exclude sub directories from check out On Linux from command line shajay12 Linux - Newbie 1 08-03-2009 01:36 AM
mod_security - exclude one file from checking ddaas Linux - Security 2 05-22-2009 09:37 AM
tar --exclude-from=FILE GATTACA Programming 1 07-29-2005 01:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:20 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