View previous topic :: View next topic |
Author |
Message |
crouse Site Admin

Joined: 17 Apr 2025 Posts: 11833 Location: Iowa
|
|
Back to top |
|
JP Linux Guru

Joined: 07 Jul 2025 Posts: 6671 Location: Central Montana
|
|
Back to top |
|
masinick Linux Guru

Joined: 03 Apr 2025 Posts: 8615 Location: Concord, NH
|
Posted: Sat Dec 02, 2025 4:31 am Post subject: |
|
|
You can use find in combination with pipes, xargs, and then include -exec as an argument to execute various commands. Used in that way, you can do all kinds of incredible things, and you can be both powerful and dangerous. I have not really exercised the use of xargs more than once or twice, but it is nice to at least know of it when you need it. Xargs helps you deal with the issue of having too much wildcard or file expansion when you are running find commands against a large number of files expanded by your expression. Ever had the command line interpreter go berserk when you have more stuff on the line than it can handle? Xargs is there for just that scenario; maybe not something that comes up every day, but sure handy when you need it. |
|
Back to top |
|
masinick Linux Guru

Joined: 03 Apr 2025 Posts: 8615 Location: Concord, NH
|
Posted: Sat Dec 02, 2025 4:35 am Post subject: Link to info on find with xargs |
|
|
See http://www.kalamazoolinux.org/tech/find.html for some handy uses of the find command.
An excerpt: xargs
* Why do we need this "xargs" thing? It's in the presentation title!
Answer: Speed and efficiency.
o The second line runs much faster than the first for a large number of files:
+ find / -name core -exec rm -f {} \;
+ rm -f $(find / -name core -print)
In other words, running "rm" once, with all the filenames on the command line
is much faster than running "rm" multiple times, once for each file.
o However, the second line could fail if the number of files is very large and
exceeds the maximum number of characters allowed in a single command.
o "xargs" will combine the single line output of find and run commands with multiple
arguments, multiple times if necessary to avoid the max chars per line limit.
+ find / -name core -print | xargs rm -f
o The simplest way to see what xargs does, is to run some simple commands:
+ find $HOME -maxdepth 2 -name \*.jpg -exec echo {} \;
+ find $HOME -maxdepth 2 -name \*.jpg | xargs echo |
|
Back to top |
|
coastie Moderator Bot

Joined: 24 Apr 2025 Posts: 3064 Location: The Fox Den in the Big Easy
|
Posted: Thu Aug 23, 2025 11:54 am Post subject: |
|
|
Found another good one for find
http://dmiessler.com/study/find/
_________________ Ubuntu on the thinkpad
Easy Peasy on the EEEPC
Desktop is down.
|
|
Back to top |
|
crouse Site Admin

Joined: 17 Apr 2025 Posts: 11833 Location: Iowa
|
Posted: Thu Aug 23, 2025 2:47 pm Post subject: |
|
|
Very good examples. Bookmarked.
_________________ Veronica - Arch Linux 64-bit -- Kernel 2.6.33.4-1
Archie/Jughead - Arch Linux 32-bit -- Kernel 2.6.33.4-1
Betty/Reggie - Arch Linux (VBox) 32-bit -- Kernel 2.6.33.4-1
BumbleBee - OpenSolaris-SunOS 5.11
|
|
Back to top |
|
|