Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Recursive copy to a RANDOM name Post 302248557 by Perderabo on Saturday 18th of October 2008 09:46:24 AM
Old 10-18-2008
There are a few problems here. A directory with 80,000 files will behave very slowly with most file systems. Directory accesses are almost always sequential. And those file names are asking for trouble. If you really want to do this, make a practice directory hierarchy will only a hundred files or so and try it out there.

Code:
$ find pix
pix
pix/a
pix/a/a.gif
pix/a.jpg
pix/b
pix/b/a.gif
pix/b/xyz 001 [1]  .jpg
pix/b.jpg
pix/c
pix/c/a.gif
pix/c.jpg
pix/d.jpg
pix/e.jpg
pix/f.jpg
pix/g.jpg
pix/h.jpg
pix/i.jpg
pix/j.jpg
pix/k.jpg
pix/l.jpg
pix/m.jpg
pix/n.jpg
pix/o.jpg
pix/p.jpg
pix/q.jpg
pix/r.jpg
pix/s.jpg
pix/t.jpg
pix/u.jpg
pix/v.jpg
pix/w.jpg
pix/x.jpg
pix/xyz 001 [1]  .jpg
pix/xyz 001 [2]  .jpg
pix/xyz 001 ]2[  .jpg
pix/y.jpg
pix/z.jpg
$
$
$
$
$ cat fixpix
#! /usr/local/bin/bash

SOURCE=pix
DEST=newpix
count=0

find $SOURCE -type f | while read pathname ; do
        ((count=count+1))
        dir=${pathname%/*}
        file=${pathname#$dir/}
        base=${file%.*}
        typ=${file##*.}
        newfile=$(printf "%s%09d.%s" "$base" $count "$typ")
        echo mv \""$pathname"\" \""$DEST/$newfile"\"
done

$
$
$
$
$
$ ./fixpix
mv "pix/a/a.gif" "newpix/a000000001.gif"
mv "pix/a.jpg" "newpix/a000000002.jpg"
mv "pix/b/a.gif" "newpix/a000000003.gif"
mv "pix/b/xyz 001 [1]  .jpg" "newpix/xyz 001 [1]  000000004.jpg"
mv "pix/b.jpg" "newpix/b000000005.jpg"
mv "pix/c/a.gif" "newpix/a000000006.gif"
mv "pix/c.jpg" "newpix/c000000007.jpg"
mv "pix/d.jpg" "newpix/d000000008.jpg"
mv "pix/e.jpg" "newpix/e000000009.jpg"
mv "pix/f.jpg" "newpix/f000000010.jpg"
mv "pix/g.jpg" "newpix/g000000011.jpg"
mv "pix/h.jpg" "newpix/h000000012.jpg"
mv "pix/i.jpg" "newpix/i000000013.jpg"
mv "pix/j.jpg" "newpix/j000000014.jpg"
mv "pix/k.jpg" "newpix/k000000015.jpg"
mv "pix/l.jpg" "newpix/l000000016.jpg"
mv "pix/m.jpg" "newpix/m000000017.jpg"
mv "pix/n.jpg" "newpix/n000000018.jpg"
mv "pix/o.jpg" "newpix/o000000019.jpg"
mv "pix/p.jpg" "newpix/p000000020.jpg"
mv "pix/q.jpg" "newpix/q000000021.jpg"
mv "pix/r.jpg" "newpix/r000000022.jpg"
mv "pix/s.jpg" "newpix/s000000023.jpg"
mv "pix/t.jpg" "newpix/t000000024.jpg"
mv "pix/u.jpg" "newpix/u000000025.jpg"
mv "pix/v.jpg" "newpix/v000000026.jpg"
mv "pix/w.jpg" "newpix/w000000027.jpg"
mv "pix/x.jpg" "newpix/x000000028.jpg"
mv "pix/xyz 001 [1]  .jpg" "newpix/xyz 001 [1]  000000029.jpg"
mv "pix/xyz 001 [2]  .jpg" "newpix/xyz 001 [2]  000000030.jpg"
mv "pix/xyz 001 ]2[  .jpg" "newpix/xyz 001 ]2[  000000031.jpg"
mv "pix/y.jpg" "newpix/y000000032.jpg"
mv "pix/z.jpg" "newpix/z000000033.jpg"
$

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

recursive copy of hidden files

I need to know how to copy hidden files recursively? cp -r sourceDir/* targetDir/. ignores the hidden files. Thank you!! (2 Replies)
Discussion started by: usfrog
2 Replies

2. Programming

recursive copy of the directory

I want to copy a directory recursively ( it again has directories) and the directory is on windows and is nfsmounted in vxWorks, i am using unix to develop the code for this, can any one suggest me how to copy the directories recursively. (7 Replies)
Discussion started by: deepthi.s
7 Replies

3. UNIX for Dummies Questions & Answers

help with recursive copy command

Hi Guys, I am experiencing a problem right now while copying a directory as well as its subdirectories to my target directory. I know this is a very simple UNIX command using cp -R source directory target directory. but unfortunatley while doing this an error comes up on the command line saying... (2 Replies)
Discussion started by: Knowledge_Xfer
2 Replies

4. Shell Programming and Scripting

scp : recursive copy doesn't work

Hi I have a problem with scp command : I try to copy a list of files from source to destination, it works fine but if there is a directory not existing on destination, it doesn't automatic create. Syntax : scp -rp /<PATH>/<NEW_DIR>/<FILE> <USER_DEST>@<HOST_DEST>:<PATH>/<NEW_DIR>/<FILE>... (5 Replies)
Discussion started by: madmat
5 Replies

5. Ubuntu

expect script for random password and random commands

Hi I am new to expect. Please if any one can help on my issue its really appreciable. here is my issue: I want expect script for random passwords and random commands generation. please can anyone help me? Many Thanks in advance (0 Replies)
Discussion started by: vanid
0 Replies

6. Shell Programming and Scripting

recursive search and copy

Hello again. Well, I need help again sooner as I thought. Now I want to search for files with a known name within all subdirs, and copy the to differently named files in the same directory. For example if I had only one file to copy, I would just usecp fileName newFileNamebut to do this... (1 Reply)
Discussion started by: cabaciucia
1 Replies

7. UNIX for Dummies Questions & Answers

recursive copy into a directory and all its subdirectories...

I want to copy a file from the top directory into all the sub-folders and all of the sub-folders of those sub-folder etc. Does anyone have any idea how to do this? Thanks in advance of any help you can give. (3 Replies)
Discussion started by: EinsteinMcfly
3 Replies

8. Shell Programming and Scripting

Recursive search for files and copy to new directories

So I have extremely limited experience with shell scripting and I was hoping someone could point out a few commands I need to use in order to pull this off with a shell script like BASH or whatnot (this is on OS X). I need to search out for filenames with account numbers in the name itself... (3 Replies)
Discussion started by: flyawaymike
3 Replies

9. Shell Programming and Scripting

Need to generate a file with random data. /dev/[u]random doesn't exist.

Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom. I create a named pipe then: dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024 but when I cat a file to the fifo that's 1024 random bytes: cat randomfile.txt >... (7 Replies)
Discussion started by: Devyn
7 Replies

10. HP-UX

Recursive copy of Folders with files

Dear All, I will appreciate any help received. Our system is running on hpux v1 My problem is as follows: We have many customer folders with name fd000100, fd000101 and so on e.g. (Testrun)(testsqa):/>ll /TESTrun/fd000100 total 48 drwxrwx--- 2 fq000100 test 96 Jun 27 2004... (17 Replies)
Discussion started by: mhbd
17 Replies
WRJPGCOM(1)						      General Commands Manual						       WRJPGCOM(1)

NAME
wrjpgcom - insert text comments into a JPEG file SYNOPSIS
wrjpgcom [ -replace ] [ -comment text ] [ -cfile name ] [ filename ] DESCRIPTION
wrjpgcom reads the named JPEG/JFIF file, or the standard input if no file is named, and generates a new JPEG/JFIF file on standard output. A comment block is added to the file. The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file. Although the standard doesn't actually define what COM blocks are for, they are widely used to hold user-supplied text strings. This lets you add annotations, titles, index terms, etc to your JPEG files, and later retrieve them as text. COM blocks do not interfere with the image stored in the JPEG file. The maximum size of a COM block is 64K, but you can have as many of them as you like in one JPEG file. wrjpgcom adds a COM block, containing text you provide, to a JPEG file. Ordinarily, the COM block is added after any existing COM blocks; but you can delete the old COM blocks if you wish. OPTIONS
Switch names may be abbreviated, and are not case sensitive. -replace Delete any existing COM blocks from the file. -comment text Supply text for new COM block on command line. -cfile name Read text for new COM block from named file. If you have only one line of comment text to add, you can provide it on the command line with -comment. The comment text must be sur- rounded with quotes so that it is treated as a single argument. Longer comments can be read from a text file. If you give neither -comment nor -cfile, then wrjpgcom will read the comment text from standard input. (In this case an input image file name MUST be supplied, so that the source JPEG file comes from somewhere else.) You can enter multiple lines, up to 64KB worth. Type an end-of-file indicator (usually control-D) to terminate the comment text entry. wrjpgcom will not add a COM block if the provided comment string is empty. Therefore -replace -comment "" can be used to delete all COM blocks from a file. EXAMPLES
Add a short comment to in.jpg, producing out.jpg: wrjpgcom -c "View of my back yard" in.jpg > out.jpg Attach a long comment previously stored in comment.txt: wrjpgcom in.jpg < comment.txt > out.jpg or equivalently wrjpgcom -cfile comment.txt < in.jpg > out.jpg SEE ALSO
cjpeg(1), djpeg(1), jpegtran(1), rdjpgcom(1) AUTHOR
Independent JPEG Group 15 June 1995 WRJPGCOM(1)
All times are GMT -4. The time now is 06:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy