Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

xargs rm gives error

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
LukeCubox
Posts: 2
Joined: 2018-04-26 00:09

xargs rm gives error

#1 Post by LukeCubox »

I am having trouble piping to rm using xargs. It keeps giving me this error.
rm -i *.mp3
rm: cannot remove ‘*.mp3’: No such file or directory
The command I used is below.

Code: Select all

$ ls -l | egrep -Eiv '^d' | egrep -Eio '\..*$' | uniq | sed 's/.*/*&/' | xargs -t rm  
There is definitely a .mp3 file there
~/test$ ls -l
total 12
-rw-r--r-- 1 luke luke 6 Apr 26 08:34 rmtest
-rw-r--r-- 1 luke luke 30 Apr 25 23:47 testfile
drwxr-xr-x 2 luke luke 4096 Apr 25 13:36 testing
-rw-r--r-- 1 luke luke 0 Apr 26 00:01 text.mp3
And when I run the command separately it works. I can't seem to find out why. I can only assume it is the * causing the issue as hardcoding the filename works, as below:
:~/test$ ls -l | egrep -Eiv '^d' | egrep -Eio '\..*$' | uniq | sed 's/.*/text\.mp3/' | xargs -tp rm -i
rm -i text.mp3 ?...y
rm: remove regular empty file ‘text.mp3’?
Any idea on how I can get the asterisk to work?

LukeCubox
Posts: 2
Joined: 2018-04-26 00:09

Re: xargs rm gives error

#2 Post by LukeCubox »

I have managed to find some info on Google about using 'sh -c' now I get the 'missing operand' fault. I have tested it by substituting the find command and the wildcards still work. Anyone have a clue to what I am missing?

User avatar
ralph.ronnquist
Posts: 342
Joined: 2015-12-19 01:07
Location: Melbourne, Australia
Been thanked: 6 times

Re: xargs rm gives error

#3 Post by ralph.ronnquist »

The pipeline includes this sub command:

Code: Select all

sed 's/.*/*&/'
which says "replace the whole line with *&" (star, ampersand). That's surely not what you intended?

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: xargs rm gives error

#4 Post by debiman »

LukeCubox wrote:

Code: Select all

$ ls -l | egrep -Eiv '^d' | egrep -Eio '\..*$' | uniq | sed 's/.*/*&/' | xargs -t rm  
what is this supposed to achieve?
why not just

Code: Select all

rm *.mp3
???

Post Reply