xargs rm gives error

If none of the more specific forums is the right place to ask

xargs rm gives error

Postby LukeCubox » 2018-04-26 00:43

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

Postby LukeCubox » 2018-04-26 12:10

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?
LukeCubox
 
Posts: 2
Joined: 2018-04-26 00:09

Re: xargs rm gives error

Postby ralph.ronnquist » 2018-04-26 20:37

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
ralph.ronnquist
 
Posts: 315
Joined: 2015-12-19 01:07
Location: Melbourne, Australia

Re: xargs rm gives error

Postby debiman » 2018-04-27 06:31

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
???
User avatar
debiman
 
Posts: 2586
Joined: 2013-03-12 07:18


Return to General Questions

Who is online

Users browsing this forum: No registered users and 5 guests

fashionable