Find files of type within folder copy multiple results to different folders
Ok question number two: I'd like to search a directory for multiple file types (rar, txt, deb) and depending on what's found, copy those files to folders named Rar, TextFiles, and Debs. I'm looking for speed here so the faster the script the better. I want it to be a function that I pass 1 argument to which is the location to search. Running this function will search that directory for files and copy them to their correct folders. Here's my unfinished function:
How about this - it does do three searches thru the location (for each of the filetypes) but I can't think of a way to find all three filetypes and then have them moved to the right folers.
This User Gave Thanks to Chubler_XL For This Post:
I think I may need to use a loop to do it. Like, "if this directory exists, loop through while x=1 and test for filetype a, if that exists then copy it to blah, increment x to 2, if x=2 then test for filetype b, etc, etc, etc, last test end this loop. I just don't know if that's feasible and how to implement that. I'm thinking a for loop... for [x=1, something here, x++] but I'm no good with combining my tests and looping.
I'm totally floored by the rapid response and the attention to detail you guys display. Holy expletive here. Thank you so much
---------- Post updated 01-28-11 at 12:09 AM ---------- Previous update was 01-27-11 at 10:41 PM ----------
So i love it, works great. One last question: can I export "$file" so that I may use the var in another script that's a bit different? I've export(ed) "$loc" but since "$file" is being created with a while loop, is there a way?
---------- Post updated at 01:58 AM ---------- Previous update was at 12:09 AM ----------
Ok last thing guys, I used rdcwayx's solution and in his function he returns a 1 or 2 depending on error status. I need to know do I use the trap command to exit my script for that? Should, instead of returning 1 or 2 should I exit 1 if i want it to stop everything at that point?
forgot to add, I'm trying to incorporate grep -n "$loc" into the "valid directory test".
I can't seem to get echo to allow me to use grep. I tried backticks, concatenation, and holding my breath til it worked. You shocked too? None worked. How would I say "$loc is not a valid directory, see line (grep -n $loc /this/script.sh)
I'm trying to copy a file myfile.scr from my local Linux server to multiple folders on remote AiX server using single rsync command.
Below command helps me copy the file "myfile.scr" from my localhost to a remote host folder "/app/deployment/tmpfiles"
rsync --delay-updates -F --compress... (1 Reply)
How to execute multiple files in multiple folders and also output to be generated in the same folder?
Hello Team,
I have a path like Sanity_test/*/* and it has around 100+ folders inside with files. I would like to run/execute those files and output of execution to be placed on same /... (1 Reply)
How do you compare one local folder and a remote folder and copy the difference to a third folder in a remote folder.e.g.
Folder A -- Is in a remote server and it has the following files
TEST1.OUT
TEST2.OUT
TEST3.OUT
Folder B --Is in a local server and it has the following files
... (5 Replies)
I have a directory that is in the below order (the --- is not part of the directory tree, only there to help illustrate:
DATE --- main level
Folder1 --- level under DATE
plugin_out --- level under Folder1
variantCaller_out.40 --- level under plugin_out
001,002,003 --- level under... (3 Replies)
Hi,
I have a zipped file a.zip. This has got multiple folders in it say x and y. x contains a.txt and y contains a.txt. Is it possible to unzip this file and have the 2 files extracted and rename them to unique names.
Thanks in advance. (1 Reply)
This has been tearing my hair out.
I need to:
1: compare server1:/data/archive/ to server2:/data/archive/ (through rsync, ssh, etc)
2: filenames that don't match, get copied (scp) to server2:/data/
server1 and server2 have ssh, scp, rsync access between eachother.
Is there any option in... (3 Replies)
Please help ,
I am in an urgent need, Please help
nawk '{for(i=1;i<=NF;i++){printf("%s\n",$i)}}' filename | sed 's/.*com//' | nawk '/pdf/ {printf("F:%s\n",$0)}' | while read line; do mv $line /images/; done
the above script works for without spaces but,My path is also having some space... (3 Replies)
i have users home directories in /home
all the users have some files starting with character e
and i want to copy all these files in a folder in my (root) home
using a script
i tried the script
for i in m5
do
cd m5
cp e1* /home/pc/exam
cd ..
done
but get these... (3 Replies)
Hi all,
*I use Uwin and Cygwin emulator.
I´m trying to search for all text files in the current folder (C/Files) and its sub folders using
find -depth -name "*.txt"
The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Hi there,
I would like to write a script to automate the copy and renaming of files in multiple dir.
I have a generic file named s253e.prb and would like to copy this to multiple dir and rename it.
Example:
Dir is AL-M1 and the prb file name is AL-M1.prb. I would like to be able to... (6 Replies)