- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Mass renaming of directory tree using unique names
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2005 11:51 PM
10-25-2005 11:51 PM
The problem:
I have a directory tree, filled with JPEG files.
I would like to rename all these jpegs using unique numerical names - say starting at `date +"%Y%m%d%H%M%S"` and making sure that at least one second passes before the next rename operation.
The Request:
Can you suggest a way to do this _without_ writing a script, namely, from the shell command line ?
My non-working solution:
$ find . -type f -name "*jpg" -exec cp {} ../results/`date +"%Y%m%d%H%M%S"`.jpg \; -exec sleep 1 \;
My problem is that find seems to optimize the operation, and calculates date +"%Y%m%d%H%M%S" only once (thus, all the files are copied to one name).
Conclusion:
If you could suggest a way to make the date command to re-calculate for each file renaming, it'd solve the problem.
Of course, full points will be given to shell-command-line solutions other than using find (Perl/sed/awk one-liners are welcome).
Thanks,
Ron.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2005 12:00 AM
10-26-2005 12:00 AM
Re: Mass renaming of directory tree using unique names
for FILE in `ls $1`; do
cp $FILE ../results/`date +"%Y%m%d%H%M%S"`.jpg
sleep 1
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2005 12:06 AM
10-26-2005 12:06 AM
Re: Mass renaming of directory tree using unique names
for FILE in "*.jpg"
do
cp $FILE ../results/`date +"%Y%m%d%H%M%S"`.jpg
done
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2005 12:11 AM
10-26-2005 12:11 AM
Re: Mass renaming of directory tree using unique names
As I said, I need to rename files in a directory _tree_: I don't think your solution will be able to solve that (it doesn't descend to subdirectories).
Bye,
Ron.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2005 12:11 AM
10-26-2005 12:11 AM
Re: Mass renaming of directory tree using unique names
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2005 12:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2005 12:23 AM
10-26-2005 12:23 AM
Re: Mass renaming of directory tree using unique names
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2005 12:40 AM
10-26-2005 12:40 AM
Re: Mass renaming of directory tree using unique names
You can easily do what you want by pushing the '-exec' arguments into a small script snippet:
#cat /tmp/myexec
cp $1 ../results/`date +"%Y%m%d%H%M%S"`.jpg
sleep 1
...Now do:
# find . -type f -name "*jpg" -exec /tmp/myexec {} \;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2005 12:43 AM
10-26-2005 12:43 AM
Re: Mass renaming of directory tree using unique names
VAR=0
BASE=`date +"%Y%m%d`
for JPG in `find ./path -name "*.jpg"`
do
cp -p $JPG ./newpath/${BASE}-${VAR}.jpg
VAR=$((VAR + 1))
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2005 06:03 AM
10-26-2005 06:03 AM
Re: Mass renaming of directory tree using unique names
Thanks Pete.