Find, rename and copy files to a new directory

Clash Royale CLAN TAG#URR8PPP up vote
1
down vote
favorite
I have 3 files under a directory that represents the time which is under a directory that represents a date. Each time directory has similar files. I'm basically saving earth's magnetosphere measurements.

Now what I'm trying to do is grab all ycut2.gif files, rename them sequentially with respect to the time and copy it to a directory ycut2 which will be located under the date directory, so I can combine them to create a gif for each day.
For instance,
14:58:31 > ycut2.gif -----(rename)--> 00.gif
15:21:39 > ycut2.gif -----(rename)--> 01.gif
15:52:30 > ycut2.gif -----(rename)--> 02.gif and so on...
filemanager cp
add a comment |Â
up vote
1
down vote
favorite
I have 3 files under a directory that represents the time which is under a directory that represents a date. Each time directory has similar files. I'm basically saving earth's magnetosphere measurements.

Now what I'm trying to do is grab all ycut2.gif files, rename them sequentially with respect to the time and copy it to a directory ycut2 which will be located under the date directory, so I can combine them to create a gif for each day.
For instance,
14:58:31 > ycut2.gif -----(rename)--> 00.gif
15:21:39 > ycut2.gif -----(rename)--> 01.gif
15:52:30 > ycut2.gif -----(rename)--> 02.gif and so on...
filemanager cp
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have 3 files under a directory that represents the time which is under a directory that represents a date. Each time directory has similar files. I'm basically saving earth's magnetosphere measurements.

Now what I'm trying to do is grab all ycut2.gif files, rename them sequentially with respect to the time and copy it to a directory ycut2 which will be located under the date directory, so I can combine them to create a gif for each day.
For instance,
14:58:31 > ycut2.gif -----(rename)--> 00.gif
15:21:39 > ycut2.gif -----(rename)--> 01.gif
15:52:30 > ycut2.gif -----(rename)--> 02.gif and so on...
filemanager cp
I have 3 files under a directory that represents the time which is under a directory that represents a date. Each time directory has similar files. I'm basically saving earth's magnetosphere measurements.

Now what I'm trying to do is grab all ycut2.gif files, rename them sequentially with respect to the time and copy it to a directory ycut2 which will be located under the date directory, so I can combine them to create a gif for each day.
For instance,
14:58:31 > ycut2.gif -----(rename)--> 00.gif
15:21:39 > ycut2.gif -----(rename)--> 01.gif
15:52:30 > ycut2.gif -----(rename)--> 02.gif and so on...
filemanager cp
asked May 13 at 23:07
chipChocolate.py
1461213
1461213
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
It's easy! You can count in bash and produce/read a list of filenames:
declare -i num=0
destination="$PWD" # set to destination of files
find . -type f -name 'ycut2.gif` -print | sort | while read fn ; do
num=$(($num + 1 ))
# following line assumes no more than 99 files
j=printf "%02d" $num
cp "$fn" "$destination/$j.gif"
done
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
It's easy! You can count in bash and produce/read a list of filenames:
declare -i num=0
destination="$PWD" # set to destination of files
find . -type f -name 'ycut2.gif` -print | sort | while read fn ; do
num=$(($num + 1 ))
# following line assumes no more than 99 files
j=printf "%02d" $num
cp "$fn" "$destination/$j.gif"
done
add a comment |Â
up vote
2
down vote
accepted
It's easy! You can count in bash and produce/read a list of filenames:
declare -i num=0
destination="$PWD" # set to destination of files
find . -type f -name 'ycut2.gif` -print | sort | while read fn ; do
num=$(($num + 1 ))
# following line assumes no more than 99 files
j=printf "%02d" $num
cp "$fn" "$destination/$j.gif"
done
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
It's easy! You can count in bash and produce/read a list of filenames:
declare -i num=0
destination="$PWD" # set to destination of files
find . -type f -name 'ycut2.gif` -print | sort | while read fn ; do
num=$(($num + 1 ))
# following line assumes no more than 99 files
j=printf "%02d" $num
cp "$fn" "$destination/$j.gif"
done
It's easy! You can count in bash and produce/read a list of filenames:
declare -i num=0
destination="$PWD" # set to destination of files
find . -type f -name 'ycut2.gif` -print | sort | while read fn ; do
num=$(($num + 1 ))
# following line assumes no more than 99 files
j=printf "%02d" $num
cp "$fn" "$destination/$j.gif"
done
edited May 14 at 15:13
answered May 14 at 0:21
waltinator
20.3k73968
20.3k73968
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1035886%2ffind-rename-and-copy-files-to-a-new-directory%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password