Try this: find. You can do the following to make the command non-recursive: find. Improve this answer. Triforcey 5 5 silver badges 10 10 bronze badges. No, xargs specifically splits up the list and issues several commands if necessary. Dennis: -maxdepth 1 needs to be the first argument after the path. Find has a -delete flag to delete the files it finds, and even if it didn't it would still be considered better practice to use -exec to execute rm, rather than invoking xargs which is now 3 processes and a pipe instead of a single process with -delete or 2 processes with -exec.
But this is reading NULL-delimited input. And the whole dangerous broken, exploitable, etc. Assuming find does the deletion directly, using -delete should be the only process that would be invoked. Show 19 more comments. Solution: Using find If you insist, you can use find but really don't use xargs as it "is dangerous broken, exploitable, etc. References I'm getting "Argument list too long". How can I process a large list in chunks? Great answer, this is how all SO questions should be answered.
I've used find before, but I'm always looking up how to do it as I forget the options, etc. The find -exec solution seems to be MUCH faster than the for loop. Five years later at 4. Show 6 more comments. ThiefMaster ThiefMaster k 77 77 gold badges silver badges bronze badges. This would still return "Argument list too long". At least for me it does. Using xargs , as per Dennis' answer, works as intended.
That sounds like a bug in find. Sergio had same issue, it was caused by the missing quotes around name pattern. Add a comment. For deleting command in linux, which can be a disaster if you are an engineer and you typed a mistake, I believe it is the 'safest and I know what's going on' is the best one.
Not fancy stuff that if you miss type a dot will let your company crash down in one minute. How can we make this the default expansion for certain commands? There's a good many "standard" linux commands where it's known if they need them all at once or not like "rm" — user Note that this only works where echo is a shell builtin.
If you end up using the command echo , you'll still run into the program arguments limit. There is also still the inherent problem that echo could produce something else than the literal file names.
If a file name contains a newline, it will look to xargs like two separate file names, and you get rm: firsthalfbeforenewline: No such file or directory. On some platform, file names which contain single quotes will also confuse xargs with the default options. And the -n is probably way too low; just omit the option to let xargs figure out the optimal number of processes it needs.
I choose -n as a conservatively low number because I don't think there is any reason to increase n to the point of being "optimal" here.
Bibin Joseph Bibin Joseph 4 4 silver badges 3 3 bronze badges. I did sudo find. Took about 20 seconds. Or you can try: find. Jon Lin Jon Lin k 27 27 gold badges silver badges bronze badges. This deletes files from subdirectories as well. How to prevent that? NikunjChauhan Add -maxdepth option: find. I am not able to insert the maxdepth option — Vicky. That option may be a Linux-only option, as per Dennis's answer, above the selected answer.
Then copy the dummy. All this for security reasons. BigMike BigMike 6, 1 1 gold badge 23 23 silver badges 23 23 bronze badges. I don't have a direct access to this server to run the tests. I'm just trying to recover a picture of the world crushed by this example. More details if they matter : The temp file is small just a few lines. It's not used by any processes.
I can instantly write to the another file s on the same disk - no delays. The delay of the file deletion is increasing with the number of the processes: 3 sec if the script launches only 4 processes and 13 sec if 36 processes were started. These processes do write to the same disks but it's just a few kilobytes. It would depend on what "additional work" the aliased "rm" is made to do. My feeling is that the "rm" being executed might not be the "out of the box" "rm".
Really the sript is dbmon. That article is old what kernel version, what FS? Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Explaining the semiconductor shortage, and how it might end.
Does ES6 make JavaScript frameworks obsolete? Featured on Meta. Now live: A fully responsive profile. Related 5. Hot Network Questions. Question feed. For Loop Taking Too Long. I'm new from UNIX scripting. Please help. Is there a better way to re-write the Red Hat. I'm having a bit of a login performance issue..
Here's the scenario Linux Red Hat ES 4 update 5 regardless of where I login from ssh or on the text console after providing the password the system seems to pause for between RedHat Commands.
OpenSolaris Commands. Linux Commands. SunOS Commands. FreeBSD Commands. Full Man Repository. Advanced Search. Contact Us. Forum Rules. Mark Forums Read. Thread Tools.
0コメント