You are not logged in.
Pages: 1
As I want to delete all the hidden files from my music dir I came up with the following pipe:
find Música/* | egrep -Z \/\\. | xargs -0 rm
It did not work and the output was "File name too long". A funny thing is, by the way, that I needed two "\" in order to mark the "." as a literal character.
However if I do
find Música/* | egrep -Z \/\\. | xargs -0 echo
I get a nice list of files with correct lines separation.
What did I do wrong?
Last edited by macaco (2016-01-06 08:49:26)
Offline
I'm guessing three issues. First, what will happen to hidden directories that have non-hidden files in them? Second, what happens when there is a space in the name of a file? Third, what happens if there are characters in the file name that have special meaning to the shell? For example, [,],(,),*,/,.,?,'," ?
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
I can't explain your problem, but there's a better way to do this: use find's -exec flag.
First, it's good practice to use it with ls to see everything it locates:
find Música/* -type f -name ".*" -exec ls -l {} \;
After you confirm you actually want to delete everything:
find Música/* -type f -name ".*" -exec /usr/bin/rm -i {} \;
I put a -i in the rm command just to be on the safe side, it's up to you to remove it if you want.
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline
Why not use find's pattern matching?
find . -name ".*?" -exec rm {} \;
Not a Sysadmin issue, moving to Scripting...
Offline
Er, find has a "-delete" option - simplest and safest.
Offline
While -delete would be best, just as an added teaser to read the man page: "-exec rm -i {}" could also be replaced with "-ok rm {}".
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
find Música/* | egrep -Z \/\\. | xargs -0 rm
....
What did I do wrong?
To answer your original question, you have told xargs to use the NUL character as a separator (the -0 flag) but your find command isn't outputting NUL delimited data. So xargs is passing the entire output to a single invocation of rm, which evidentially does not like such a long input.
Use one of the solutions others have posted -- there is no need for any piping here, and especially no need for grep in the middle.
EDIT: your use of the -Z flag to grep isn't working quite how you expect. It does NUL delimit file name output, but in this context grep isn't outputting file names, it is outputting a string of data that just happens to be file names (but grep doesn't know they are filenames) so it doesn't insert any NUL characters.
Last edited by fukawi2 (2016-01-05 21:45:53)
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
If you really need egrep, then you need the --null-data (small -z) option and find with -print0
find ... -print0 | egrep -z ... | xargs -0 -n1 echo "Match:"
Last edited by progandy (2016-01-05 22:04:26)
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |
Offline
macaco wrote:find Música/* | egrep -Z \/\\. | xargs -0 rm
....
What did I do wrong?To answer your original question, you have told xargs to use the NUL character as a separator (the -0 flag) but your find command isn't outputting NUL delimited data. So xargs is passing the entire output to a single invocation of rm, which evidentially does not like such a long input.
Use one of the solutions others have posted -- there is no need for any piping here, and especially no need for grep in the middle.
EDIT: your use of the -Z flag to grep isn't working quite how you expect. It does NUL delimit file name output, but in this context grep isn't outputting file names, it is outputting a string of data that just happens to be file names (but grep doesn't know they are filenames) so it doesn't insert any NUL characters.
Thank you man!!! This really made me a little bit wiser
For the time being I used
find Música/* -type f -name ".*" -exec /usr/bin/rm -i {} \;
which solved the problem.
Guess I can close this thread as solved now.
Last edited by macaco (2016-01-06 09:25:32)
Offline
Pages: 1