LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-26-2010, 01:38 PM   #1
thisguy2222
LQ Newbie
 
Registered: May 2010
Location: CT
Distribution: Ubuntu
Posts: 2

Rep: Reputation: 0
Question cp, mv destination name change


Hello all, probably a really quick and easy anwser to this, but didn't really know what to search for or how to word it. So my question is ..

When I use the cp or mv command to copy/move files is there a way for me to have the destination file assume the same name of the source file, however add an additional suffix. For example

Code:
#>cp /tmp/testfileReallyReallyLongNameDoNotWantToHaveToType.log /tmp/logs/
this will copy test.log into the /tmp/logs/ directory, resulting in the file create /tmp/logs/test/log

now what if I wanted this...

Code:
#>cp /tmp/testfileReallyReallyLongNameDoNotWantToHaveToType.log /tmp/logs/testfileReallyReallyLongNameDoNotWantToHaveToType.log.bak
Do I have to type the destination file out manually everytime? or is there a quick way for the cp or mv command to assume the source file name and add the .bak
 
Old 05-26-2010, 01:50 PM   #2
HasC
Member
 
Registered: Oct 2009
Location: South America - Paraguay
Distribution: Debian 5 - Slackware 13.1 - Arch - Some others linuxes/*BSDs through KVM and Xen
Posts: 329

Rep: Reputation: 55
you could read about "-S"/"--suffix" switch on "man cp" or "man mv"

EDIT: nevermind, that switch it's for "backup mode", when you will overwrite files, the command just renames the old files using the specified "--suffix" - Not what you're asking for

Last edited by HasC; 05-26-2010 at 01:52 PM.
 
Old 05-26-2010, 02:01 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
How about
Code:
x=testfileReallyReallyLongNameDoNotWantToHaveToType.log
cp /tmp/$x /tmp/logs/$x.bak

Last edited by catkin; 05-26-2010 at 02:01 PM. Reason: Removed quote of OP post
 
Old 05-26-2010, 02:10 PM   #4
thisguy2222
LQ Newbie
 
Registered: May 2010
Location: CT
Distribution: Ubuntu
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
How about
Code:
x=testfileReallyReallyLongNameDoNotWantToHaveToType.log
cp /tmp/$x /tmp/logs/$x.bak
Yes that would work and do what I want, however if I don't want to have to type the entire name ever...aka using the tab complete perk. Is there a way to do it that way?

For example if in order to type the following line, I used the TAB key to autocomplete the file name (to prevent having to type it out)some of these files are really really long containg numbers undersscores, etc.
Code:
mv /tmp/testfileReallyReallyLongNameDoNotWantToHaveToType.log /tmp/logs/
Furthermore, is there a way to access the mem space that the mv or cp command is using to automatically output the source filename. Could you call that space like

CODE]
mv /tmp/testfileReallyReallyLongNameDoNotWantToHaveToType.log /tmp/logs/%.bak
[/CODE]

Last edited by thisguy2222; 05-26-2010 at 02:14 PM. Reason: Additional info
 
Old 05-26-2010, 02:13 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by thisguy2222 View Post
Yes that would work and do what I want, however if I don't want to have to type the entire name ever...aka using the tab complete perk. Is there a way to do it that way?
How about
Code:
cd /tmp
x=tes
and then use tab completion to get the full name.
 
1 members found this post helpful.
Old 05-26-2010, 06:45 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
If the path is short as described you could just tab complete twice and the add the path change:
Code:
mv /tmp/test[tab] /tmp/test[tab]
Now change file ending and backtrack to start of second path and alter as needed.
 
  


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
how to change destination for httpd log mandrivian Linux - Server 3 02-25-2010 06:04 AM
How to change the destination of downloads when using wget? Uxq Linux - Newbie 1 07-02-2008 08:56 PM
change /var/log destination turbo_acura Linux - Software 4 02-14-2008 06:14 AM
change port using destination alaios Linux - Networking 3 03-01-2005 04:06 AM
Change the destination URL by IPTABLES swmok Linux - Networking 4 09-14-2004 11:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:46 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
Open Source Consulting | Domain Registration