LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 02: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, 03:39 AM   #2
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

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

then try running the command again it should be okay.

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

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
Login first and run bash as local.
 
Old 04-06-2016, 05: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, 05: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, 06:11 AM   #6
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,669

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

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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, 10: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, 12:50 AM   #9
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
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, 09:15 AM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

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

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
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



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

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

All times are GMT -5. The time now is 06:41 AM.

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
Open Source Consulting | Domain Registration