![]() |
piping output of find to another command or loop
Hi
I am trying to run a find command on a directory and then pipe the output to either awk or into a loop for further processing. My find command works fine and outputs line of results, however, when I try to pipe the output to another command or loop, nothing happens, it just freezes. The command I am currently trying is: find /media/backups/rsnapshots/ -name "CTG\.fp5" | while read i; do ls -l $i; done I cannot understand what is stopping this from working as the output from the find on its own is simply lines of output, I have done plenty of googling and cannot `find` the answer. Maybe I'm just being a bit dim. Any help would be greatly appreciated. |
The syntax looks correct. Can you show us the output of the find command by itself?
|
The syntax looks ok. You could try this instead :-
find /media/backups/rsnapshots/ -name "CTG\.fp5" -exec ls -l '{}' \; |
output
the output of the find command I was using was this:
/media/backups/rsnapshots/weekly.1/mnt/FM_daily_backups/Wednesday/CTG.fp5 /media/backups/rsnapshots/weekly.1/mnt/FM_daily_backups/Friday/CTG.fp5 /media/backups/rsnapshots/weekly.1/mnt/FM_daily_backups/Tuesday/CTG.fp5 /media/backups/rsnapshots/weekly.1/mnt/FM_daily_backups/Sunday/CTG.fp5 /media/backups/rsnapshots/weekly.1/mnt/FM_daily_backups/Thursday/CTG.fp5 Arfa that works great, thanks. What does the " '{}' \ " bit do? And I am still confused about why my find command won't pipe to a loop or awk. |
You could use a for loop, especially if you want to do more complex stuff than just 'ls'
Code:
for file in `find media/backups/rsnapshots/ -name 'CTG.fp5' -type f` Here's a good page on the find cmd http://lowfatlinux.com/linux-find-files.html |
Quote:
name for find or in shell-globbing if it's not in the first position of the path, anyway. Cheers, Tink |
Quote:
The '{}' puts the output of the find command in its place. If you do a "man find" you will see many options for the find command. There are heaps of great things you can do with the find command. When I run your command on my system (Fedora 11 - find (GNU findutils)4.4.0)I get the following "error" :- $ find . -name "song-name\.ogg" find: warning: Unix filenames usually don't contain slashes (though pathnames do). That means that '-name `song-name\.ogg'' will probably evaluate to false all the time on this system. You might find the '-wholename' test more useful, or perhaps '-samefile'. Alternatively, if you are using GNU grep, you could use 'find ... -print0 | grep -FzZ `song-name\.ogg''. |
All times are GMT -5. The time now is 09:37 AM. |