Need help searching through a list of directories
Hi everyone! :0)
I am trying to find a specific file in a 100+ list of directories. The script needs to cycle through these dirs, scanning every folder for a file. I know how to do this for a single directory, but I am not sure what to do with a list. Secondly, I need to search for a certain text, in all the files with a certain extension in these directories.. I would truly appreciate your help! |
Research the "find" and "grep" commands. I think you'll have all you need with them.
|
Right.
It would be Code:
find /media/disk -mtime -5 -print | grep .mp3 But how would I do this for a list of dirs? I.e. exact, specific list of dirs? It would seem I'd need to do a loop in bash, but every example I've looked up doesn't deal with a list, but rather general search.... SlowCoder, thank you for your reply, though. P.S. how come I can't upload an avatar? _______________ before submitting, I've found a couple of things, and modified them accordingly Code:
cat example.txt | while read line ; do find "$line" -mtime -5 -print ; done If I plug-in do echo, I see the output Code:
find /media/disk/dir But still.. it needs to remove newline breaks like so Code:
sed '/^.*$/N;s/\n//g' Code:
sed '{:q;N;s/\n//g;t q}' Code:
cat example.txt | perl -p -e 's/s+$/ /g' I still can't figure out how to search inside files... darn it why is this so hard. simple search operations shouldn't be an exercise in futility... plz oh magnificent gurus, shine your light of knowledge upon me! :) |
Go the Advanced Bash-scripting Guide, and look up 'redirection'. Specifically, redirecting input from a file instead of to a file.
Something like: for i in < list_of_directories.txt; do find $i -mtime -5 -print | grep .mp3; done |
Code:
for i in < list_of_directories.txt; do find $i -mtime -5 -print | grep .mp3; done If I remove -mtime -5 and write to file, I get this Code:
/home/example/ while this is supposed to work as well Code:
while read line < list.txt ; do find “$line” -mtime -5 -print ; done I did read the simple man http://www.tuxfiles.org/linuxhelp/iodirection.html, its all quite logical.. Advanced Bash-Scripting Guide http://tldp.org/LDP/abs/html/io-redi...tml#IOREDIRREF wasn't as clear But this code is supposed to work now, though! :( |
Let's back up a bit. How do you generate the list of directories to search through? What command do you use, and what does the output look like?
|
All times are GMT -5. The time now is 06:43 AM. |