script finding files, placing them and naming the
Hi,
I would like to create a script which will do the following: 1. Find all files following a regular expression finging following names: *.img *.IMG *.jpg *.JPG *.eps *.EPS 2. Move these files to a specified directory naming them: 1filename 2filename 3filename etc. etc. If this can be easily done (tcsh,bash,perl) please help :-) |
Here's a little bash diddy which may help.
#!/bin/bash for i in *.jpg *.gif *.img do n=$(( $n + 1 )) echo mv "$i" "/home/$n$i" done |
Perfect, but I would like it to search my entire structure from / and so forth ... can that be done ?
|
I would use:
find / \( -name "*.jpg" -o -name "*.img" -o - name "*.eps \) -print to find the files, and then use xargs to pipe them to a shell script like homey gave you to do the moving. So the final result is: find / \( -name "*.jpg" -o -name "*.img" -o - name "*.eps \) -print | xargs move_script Then change the for loop in the script to "for i in $@" ($@ is all the arguments in bash). |
Quote:
#!/bin/bash for i in *.jpg *.gif *.img do n=$(( $n + 1 )) echo cp "$i" "/home/$n$i" done |
All times are GMT -5. The time now is 03:36 AM. |