Hello All,
What I would like to do is search for a file and then run a mv command to rename the file to have todays date appended to it. The find when I run it finds eight or so files and I would like to append a date stamp to each file. If possible using one line command would be great. Can xargs do this or is there a way to do it in exec? Any help would be appreciated.
below is what I have so far, they are the pieces just trying to put it together.
1. mv test.out test.out.`date +%Y-%m-%d`
2. find . \! -name \*gz -mtime +7 -type f | xargs mv
Thank you,
jack
Try that one:
find . \! -name \*gz -mtime +7 -type f -exec sh -c 'mv "$0" "$0".$(date +%Y-%m-%d)' {} \;
jlliagre,
I ran the code but nothing happened. None of the files had the date appended.
-jack
Okay. Are you sure any file match the find conditions ?
What prints the same command without the -exec clause ?
find . \! -name \*gz -mtime +7 -type f
jlliagre,
My fault the original find did not find anything. So I changed the find param to find something now. I ran the whole script with the find of +0 and I get an error.
find . \! -name \*gz -mtime +0 -type f -exec sh -c 'mv "$0" "$0".$(date +%Y-%m-%d)' {} \;
Results of running the above
./wdns: syntax error at line 1: `(' unexpected
./wdns1: syntax error at line 1: `(' unexpected
./wdns2: syntax error at line 1: `(' unexpected
./wdns3: syntax error at line 1: `(' unexpected
./wdns4: syntax error at line 1: `(' unexpected
Running only the find command
>find . \! -name \*gz -mtime +0 -type f
./wdns
./wdns1
./wdns2
./wdns3
./wdns4
-jack
My mistake. I'm running OpenSolaris with sh being POSIX compliant.
Solaris 10 and older have a non compliant sh.
Just replace sh by ksh.
find . \! -name \*gz -mtime +0 -type f -exec ksh -c 'mv "$0" "$0".$(date +%Y-%m-%d)' {} \;
jlliagre,
Thank you for your help. What you sent worked great.
much appreciated,
-jack