Results 1 to 9 of 9
I'm trying to find a way to search multiple directories using the find command.
For example, I want to find all files in directories called /home/username/HTML, /home/username/Documents, & /var/www that ...
- 07-01-2009 #1
Find command
I'm trying to find a way to search multiple directories using the find command.
For example, I want to find all files in directories called /home/username/HTML, /home/username/Documents, & /var/www that end with ~ (tilde) and move or copy them to a directory called .Trash.
Any ideas on how to do this?
- 07-02-2009 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
welcome to the forum
"find" lets you specify directories to search, so try something like this:
find /home/username/HTML /home/username/Documents /var/www *~ \
-exec cp '{}' .Trash \;
where the first '\' represents the line continuing.
v. "man find"
another way would be with a "for loop" in the shell, something like this
for i in /home/username/HTML /home/username/Documents /var/www
do
cd $i; cp *~ /.Trash; cd /
donethe sun is new every day (heraclitus)
- 07-02-2009 #3
Thanks
I'll give it a try. I appreciate it....
- 07-03-2009 #4
I've tried the code you sent me and found that it takes a long time to run through the file system directories.
I've create a bash script as follows:
# Cleanup bash script
find /home/username/Business -iname '*.*~' -type f -exec mv '{}' /home/username/.Trash \;
find /home/username/HTML -iname '*.*~' -type f -exec mv '{}' /home/username/.Trash \;
find /home/username/Documents -iname '*.*~' -type f -exec mv '{}' /home/username/.Trash \;
find /var/www -iname '*.*~' -type f -exec mv '{}' /home/username/.Trash \;
echo "All files cleaned up."
It works very well. I changes it so it moves the files instead of copying them. I, also, copied it to the /usr/local/bin directory so its available globally.
- 07-03-2009 #5
What you can do to speed up the find command is running (as root):
And find your stuff withCode:updatedb
Note that `updatedb` creates a database of all your files, and `slocate` is 'just' a `grep pattern database` equivalent, so the output is different from what you get with the find command.Code:slocate filename
But it is a lot quickerer
Can't tell an OS by it's GUI
- 07-04-2009 #6
Found something that works...
I've found the following that I'm using as a bash script that works the best:
# Cleanup bash file cleans /home/username & /var/www directories of all files ending with ~
# and sends error messages to /dev/null directory.
find /home/username -iname '*.*~' -type f -exec mv '{}' /home/username/.Trash \; 2>/dev/null
find /var/www -iname '*.*~' -type f -exec mv '{}' /home/username/.Trash \;
echo "All files cleaned up."
I appreciate everyones help...
- 07-06-2009 #7Just Joined!
- Join Date
- Jul 2009
- Posts
- 7
updatedb is also good but depending on file system size and new files created on system it takes time to update the DB so find might give fast output. If the file system is not that big then definately updatedb is good.
- 07-11-2009 #8
Dumb question but why are you using find for this? Why not a simple 'mv' call?
# Cleanup bash file cleans /home/username & /var/www directories of all files ending with ~
mv /home/username/*~ /home/username/.Trash
mv /var/www/*~ /home/username/.Trash
echo "All files cleaned up."
- 07-11-2009 #9A candle looses nothing by lighting other candles. - Khalil Zibran.
Registered Linux User #490076


Reply With Quote

