[NTLUG:Discuss] scripting help

Philip Stetz philip_stetz at yahoo.com
Sat Mar 6 22:14:03 CST 2004


Here's a simple script that may be some use to you. 
It will rename the file by appending the date the file
was saved on to the end in order to prevent
duplicates.

(formatting is probably not going to hold...sorry)

--

#!/bin/bash

#########################################################
# Simple shell script move files from one dir to      
 #
# another.  Will re-name file by appending the date   
 #
# to the end of the name to prevent duplicates        
 #
#                                                     
 #
# Usage: cleanMove.sh [Source Dir] [Dest Dir] [reg
exp] #
#  -use [reg exp] .*jp.*g to move .jpg and .jpeg files
 #
#########################################################


SourceDir="$1"
DestDir="$2"
Ext="$3"

cd "$SourceDir"

find "$SourceDir" -type f -maxdepth 1 -iregex "$Ext"
-printf "%f\n" | while read MyFile ; do
(

fileDate=`ls -l "$MyFile" | awk '{print $6}'`

fileName=`ls -l "$MyFile" | awk '{print $8}' | awk -F.
'{print $1}'`

fileExt=`ls -l "$MyFile" | awk '{print $8}' | awk -F.
'{print $2}'`

newName=$fileName$fileDate"."$fileExt

echo "Moving $MyFile to $DestDir$newName"
mv $MyFile $DestDir$newName

)
done

--- Mailing Lists <rich-lists at multicam.com> wrote:
> MadHat wrote:
> 
> > On Mar 5, 2004, at 8:18 AM, Mailing Lists wrote:
> > 
> >> I need to consolidate a large number of image
> files into a single 
> >> directory. Currently the images are spread out
> over multiple 
> >> directories. Is there an easy way to find all of
> these files and move 
> >> them to a specified directory.  The files are
> images for a large 
> >> website and i want to consolidate them all into a
> 
> >> /var/www/mywebsite/images directory. How can I do
> this.
> >>
> > 
> > find . -type f -name "*.jpg" -exec mv {}
> /var/www/mywebsite/ \;
> > 
> > or if you are a little scared, you can do
> > 
> > find . -type f -name "*.jpg" -ok mv {}
> /var/www/mywebsite/ \;
> > 
> > and it will prompt before each mv command.
> > 
> > 
> > _______________________________________________
> > https://ntlug.org/mailman/listinfo/discuss
> > 
> Thanks Much
> 
> _______________________________________________
> https://ntlug.org/mailman/listinfo/discuss

__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com



More information about the Discuss mailing list