Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-12-2008, 05:32 AM   #1
LQ Newbie
Registered: Oct 2008
Posts: 7

Rep: Reputation: 0
Question Shell Script to copy and number files


I need to copy several files from a directory tree. Inside this tree there are several files with the same name, and I have to copy them altogether to the same directory.

This is an example of how it looks


Now I want to copy the files to \tmp\dest1\ as

1.txt, 2.txt .. 8.txt - numbered no matter how they are originally named. I just want to keep the original file extension (that may differ).

How do I realize that?

Thank you in advance!
Old 12-12-2008, 06:29 AM   #2
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417

Rep: Reputation: 33
If you absolutely don't care about the original file name, then you can do something like this:

declare -i I=1
find $FILEPATH -regex .*/[0-9]+\.txt -print | while read FILE
    mv $FILE $NEWPATH/$I.txt
    let I=$I+1


command, find

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I compare floating number in a shell script? abefroman Programming 29 09-10-2012 11:29 AM
copy directories and files recursively using C shell or bash shell bostonuser Programming 7 06-06-2008 01:24 AM
Which data copy tool is the best if number of files are more. ssrameez Linux - General 2 02-05-2008 10:01 PM
Generate a random number from a bourne shell script lothario Linux - Software 2 03-01-2007 11:01 PM
Shell-script question about getting a number as a variable stormrider_may Programming 9 03-14-2006 08:18 AM

All times are GMT -5. The time now is 08:57 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration