On 4/18/22 16:39, Michael Barnes wrote:
I use the locate command often to find files on my machine. How can I act
on that list?
For example, I do
locate -i bozo
and get a list of all files containing bozo in the name. Now I want to copy
all those files into a new directory. I've tried various combinations of
pipe to something, but no joy.

Locate is such an easy command and finds everything I need, while using
find I need a bunch of parameters I can never remember.

Thanks for any ideas.

I don't think this will work for your use case since you need to specify the destination directory, but xargs could work in some instances. As Russell mentioned, spaces in filenames are dangerous, but both locate and xargs support the -0 option. This example doesn't use spaces in filenames, but it would handle it if they existed.


[galens@toto tmp]$ locate -0 redhat-release | xargs -0 ls
/etc/redhat-release

/usr/share/doc/redhat-release:
Contributors  GPL

/usr/share/redhat-release:
EULA


galen
--
Galen Seitz
[email protected]

Reply via email to