LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-24-2014, 07:55 AM   #1
validator456
Member
 
Registered: Apr 2013
Location: Rotterdam, The Netherlands
Distribution: Crunchbang Linux
Posts: 135

Rep: Reputation: Disabled
creating copies of files in the same directory


I want to create copies of files in the same directory. So something like:
image1027.jpg
image1028.jpg
image1029.jpg
to:
image1027.jpg
image1027_a.jpg
image1028.jpg
image1028_a.jpg
image1029.jpg
image1029_a.jpg

I think it can be done with regex but I don't have any experience with it.
 
Old 02-24-2014, 08:30 AM   #2
rlx
LQ Newbie
 
Registered: Jul 2009
Location: Montréal
Distribution: Slackware customized
Posts: 28

Rep: Reputation: 4
Quote:
Originally Posted by validator456 View Post
I want to create copies of files in the same directory. So something like:
image1027.jpg
image1028.jpg
image1029.jpg
to:
image1027.jpg
image1027_a.jpg
image1028.jpg
image1028_a.jpg
image1029.jpg
image1029_a.jpg

I think it can be done with regex but I don't have any experience with it.
>for i in 7 8 9; do cp -p image102$i.jpg image102$i_a.jpg; done
# or if you want to copy all jpeg's,
>for i in *.jpg; do b=$(basename $i .jpg); do cp -p $b.jpg $b_a.jpg; done
# or
>for i in *.jpg; do b=$(echo "$i" | sed -e 's|\.jpg||'); do cp -p $b.jpg $b_a.jpg; done
# or, if file names may have weird characters in such as 'spaces',
>\ls *.jpg | while read i; do b=$(echo "$i" | sed -e 's|\.jpg$||'); a="cp -p '$b.jpg' '${b}_a.jpg'"; echo "$a"; eval "$a"; done

Have fun!

Last edited by rlx; 02-24-2014 at 08:33 AM.
 
Old 02-24-2014, 08:46 AM   #3
validator456
Member
 
Registered: Apr 2013
Location: Rotterdam, The Netherlands
Distribution: Crunchbang Linux
Posts: 135

Original Poster
Rep: Reputation: Disabled
The last line worked. Thank you, rlx.
 
  


Reply


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
cp -u copies old files that already exist in the destination directory terence Linux - General 3 11-08-2012 05:07 PM
Creating a script that removes the oldest files on /tmp directory danndp Linux - Newbie 6 11-18-2010 10:47 AM
[SOLVED] scp -r copies files repeatedly MorayJ Linux - Software 2 07-30-2009 06:26 PM
thunar copies directory files to usb stick out of order. curmudgeonbob Linux - General 1 07-28-2009 12:59 PM
make duplicate copies of files Paul Griesbaum Linux - Newbie 7 06-08-2009 11:39 AM


All times are GMT -5. The time now is 05:54 AM.

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