Re: [PLUG] Acting On Locate Results
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 gal...@seitzassoc.com
Re: [PLUG] Acting On Locate Results
you can iterate over the response in several ways, e.g.: for i in $(locate -i bozo) ; do echo $i ; done or locate -i bozo | while read f ; do echo $f ; done Be careful about files with whitespace in the filenames. Also, BE VERY CAREFUL, it's possible to do a lot of damage pretty fast. On Mon, Apr 18, 2022 at 4:39 PM 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. > > Michael
[PLUG] Acting On Locate Results
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. Michael