LinuxQuestions.org
Help answer threads with 0 replies.
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 08-25-2009, 07:42 PM   #1
since1993
Member
 
Registered: Aug 2009
Location: Seoul in Korea
Distribution: Debian 5.0.2 lenny
Posts: 36
Blog Entries: 2

Rep: Reputation: 16
cp command....


There are five files.

ycp@gray:~/sttst$ ls
result sall temp temp1 temp2

I would like to make copies of this files into the same directory and with adding ".txt" at the end of the files.

it would look like :

ycp@gray:~/sttst$ ls
result result.txt sall sall.txt temp temp.txt temp1 temp1.txt temp2 temp2.txt

Can I do this with a sing cp command and options?
 
Old 08-25-2009, 07:48 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
As long as you are in the directory where the files are, you can try the following script:
Code:
for i in *
 do
   cp $i $i.txt
 done
 
Old 08-25-2009, 09:27 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
I'd run that script from another dir and use cd <targetdir> as 1st cmd, otherwise it'll cp the script as well.
Been there, done that ...
 
Old 08-25-2009, 09:32 PM   #4
mushroomboy
Member
 
Registered: Jan 2006
Distribution: Debian Testing ALWAYS!!!
Posts: 363

Rep: Reputation: 43
Errr use a script.

Last edited by mushroomboy; 08-25-2009 at 09:36 PM.
 
Old 08-25-2009, 11:29 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by chrism01 View Post
I'd run that script from another dir and use cd <targetdir> as 1st cmd, otherwise it'll cp the script as well.
Been there, done that ...
So don't actually write a script.....

One liner in a terminal:

Code:
for i in *; do cp $i $i.txt; done
 
Old 08-26-2009, 03:13 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
An alternative using sed with a null command and the ability to make a backup copy of the original files:
Code:
sed -i.txt '' *
 
Old 08-26-2009, 06:11 AM   #7
since1993
Member
 
Registered: Aug 2009
Location: Seoul in Korea
Distribution: Debian 5.0.2 lenny
Posts: 36
Blog Entries: 2

Original Poster
Rep: Reputation: 16
Wink Need to lean more about sed......

Thank you all for responses
 
  


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
URGENT! Is there any command to get a history command lines and time in SUSE Linux.? igsoper Linux - Software 5 06-25-2009 03:14 AM
Automatically append another piped command to issued command in bash amateen Programming 1 05-07-2009 07:36 AM
LXer: The Linux Command Shell For Beginners: Fear Not The Command Line! LXer Syndicated Linux News 0 12-22-2008 07:30 PM
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 03:23 AM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 08:14 PM


All times are GMT -5. The time now is 06:24 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