* Find command in shell script
@ 2002-06-18 2:24 Rowan Eppelstun
2002-06-18 5:19 ` rDNS blocked Kilaru Sambaiah
2002-06-18 6:57 ` Find command in shell script Camelia NASTASE
0 siblings, 2 replies; 6+ messages in thread
From: Rowan Eppelstun @ 2002-06-18 2:24 UTC (permalink / raw)
To: linux-admin
Hi,
I am trying to do the following command in a script but cannot seem to get
the escape characters right for the find - exec mv command.
I am trying to move all files named 200206*.pdf to a subdirectory of their
currnet directory called "jun". Once I get the syntax correct for this I
will automate it for the year, but have got stuck at this bit.
Could anyone please advise what I am missing.
----------------------------------------------------------------------------
-------------
#!/bin/sh
MONTH='date +%m'
DATE='date +%Y%m'
DIR=/home/rowan/eod/2002/ba
if DATE=200206; then FILENAME="'200206*.pdf'"
fi
if MONTH=06 ; then MONDIR=$DIR/jun/
fi
cd $DIR
pwd
find ./ -name $FILENAME -exec mv -f '{}' $MONDIR ';'
exit 0
----------------------------------------------------------------------------
------------------
Thanks in advance.
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
^ permalink raw reply [flat|nested] 6+ messages in thread* RE: Find command in shell script
@ 2002-06-18 11:19 johnjulian1
2002-06-18 12:18 ` John Hallam
0 siblings, 1 reply; 6+ messages in thread
From: johnjulian1 @ 2002-06-18 11:19 UTC (permalink / raw)
To: "Rowan Eppelstun", linux-admin
remove the double quotes from FILENAME="'200206*.pdg'"
remove the single quotes from '{}'
remove the single quotes from ';' and preceed the ; with \ ie \;
"Rowan Eppelstun" <reppelstun@yahoo.com.au> wrote:
>Hi,
>
>I am trying to do the following command in a script but cannot seem to get
>the escape characters right for the find - exec mv command.
>
>I am trying to move all files named 200206*.pdf to a subdirectory of their
>currnet directory called "jun". Once I get the syntax correct for this I
>will automate it for the year, but have got stuck at this bit.
>
>Could anyone please advise what I am missing.
>----------------------------------------------------------------------------
>-------------
>#!/bin/sh
>
>MONTH='date +%m'
>DATE='date +%Y%m'
>DIR=/home/rowan/eod/2002/ba
>
>if DATE=200206; then FILENAME="'200206*.pdf'"
>fi
>
>if MONTH=06 ; then MONDIR=$DIR/jun/
>fi
>
>cd $DIR
>
>pwd
>
>find ./ -name $FILENAME -exec mv -f '{}' $MONDIR ';'
>
>exit 0
>----------------------------------------------------------------------------
>------------------
>
>Thanks in advance.
>
>
>_________________________________________________________
>Do You Yahoo!?
>Get your free @yahoo.com address at http://mail.yahoo.com
>
>-
>To unsubscribe from this list: send the line "unsubscribe linux-admin" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at http://vger.kernel.org/majordomo-info.html
>
__________________________________________________________________
Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/
Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/
^ permalink raw reply [flat|nested] 6+ messages in thread* RE: Find command in shell script
2002-06-18 11:19 johnjulian1
@ 2002-06-18 12:18 ` John Hallam
2002-06-18 12:29 ` John Hallam
0 siblings, 1 reply; 6+ messages in thread
From: John Hallam @ 2002-06-18 12:18 UTC (permalink / raw)
To: johnjulian1; +Cc: Rowan Eppelstun, linux-admin
Hmm. Almost right, I think. See below:
On Tue, 18 Jun 2002 johnjulian1@netscape.net wrote:
> remove the double quotes from FILENAME="'200206*.pdg'"
> remove the single quotes from '{}'
> remove the single quotes from ';' and preceed the ; with \ ie \;
>
> "Rowan Eppelstun" <reppelstun@yahoo.com.au> wrote:
>
> >Hi,
> >
> >I am trying to do the following command in a script but cannot seem to get
> >the escape characters right for the find - exec mv command.
> >
> >I am trying to move all files named 200206*.pdf to a subdirectory of their
> >currnet directory called "jun". Once I get the syntax correct for this I
> >will automate it for the year, but have got stuck at this bit.
> >
> >Could anyone please advise what I am missing.
> >----------------------------------------------------------------------------
> >-------------
> >#!/bin/sh
> >
> >MONTH='date +%m'
> >DATE='date +%Y%m'
> >DIR=/home/rowan/eod/2002/ba
> >
> >if DATE=200206; then FILENAME="'200206*.pdf'"
> >fi
> >
> >if MONTH=06 ; then MONDIR=$DIR/jun/
> >fi
This target is absolute, i.e. it generates the path
/home/rowan/eod/2002/ba/jun rather than ./jun implied by the second
paragraph of the spec above.
> >
> >cd $DIR
> >
> >pwd
> >
> >find ./ -name $FILENAME -exec mv -f '{}' $MONDIR ';'
So how about:
DATE=`date +%Y%m`
DIR=/home/rowan/eod/2002/ba
MON=`date +%b | tr A-Z a-z`
cd $DIR
find ./ -name $DATE\*.pdf -exec mv -f {} $DIR/$MON \;
> >
> >exit 0
If you really mean that you want relative paths, i.e.
./foo/bar/baz/200206xxx.pdf goes into ./foo/bar/baz/jun/200206xxx.pdf not
into /home/rowan/eod/2002/ba/jun/200206xxx.pdf, then replace $DIR/$MON in
the find command with ./$MON I think.
John.
^ permalink raw reply [flat|nested] 6+ messages in thread* RE: Find command in shell script
2002-06-18 12:18 ` John Hallam
@ 2002-06-18 12:29 ` John Hallam
0 siblings, 0 replies; 6+ messages in thread
From: John Hallam @ 2002-06-18 12:29 UTC (permalink / raw)
To: johnjulian1; +Cc: Rowan Eppelstun, linux-admin
On Tue, 18 Jun 2002, John Hallam wrote:
> So how about:
>
> DATE=`date +%Y%m`
> DIR=/home/rowan/eod/2002/ba
> MON=`date +%b | tr A-Z a-z`
> cd $DIR
> find ./ -name $DATE\*.pdf -exec mv -f {} $DIR/$MON \;
>
> If you really mean that you want relative paths, i.e.
> ./foo/bar/baz/200206xxx.pdf goes into ./foo/bar/baz/jun/200206xxx.pdf not
> into /home/rowan/eod/2002/ba/jun/200206xxx.pdf, then replace $DIR/$MON in
> the find command with ./$MON I think.
Actually, of course not: you'd need to create the relative ./jun
directories before the mv, otherwise it would fail (badly -- by renaming
all the *.pdf files in the given directory to `jun', so only the last
found in any given directory would remain). Fixing that is left as an
exercise :-)).
John.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-06-18 12:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-18 2:24 Find command in shell script Rowan Eppelstun
2002-06-18 5:19 ` rDNS blocked Kilaru Sambaiah
2002-06-18 6:57 ` Find command in shell script Camelia NASTASE
-- strict thread matches above, loose matches on Subject: below --
2002-06-18 11:19 johnjulian1
2002-06-18 12:18 ` John Hallam
2002-06-18 12:29 ` John Hallam
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).