LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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-31-2013, 07:36 AM   #1
rlich
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Rep: Reputation: Disabled
copy help


ok, I'm fine with how to use copy, but looking for advice on whether it's possible to use relative paths with the src and dst parameters with copy command. For example,

cp /some/path/that/is/really/long/here /some/path/that/is/really/long/here/but/even/longer/than/source

Is there any way to tell linux to copy the file/folder to the same beginning path as the src? In psuedo-code:

cp /some/path/that/is/really/long/here ./but/even/longer/than/source

The idea is to cut down on having to type out the long path twice. I realize I could just cd to the folder where the source file is, but I was wondering if there was something simple I was missing. I also realize I could create a variable that contains the path and use that. Thanks for any tips.
 
Old 05-31-2013, 07:42 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
no, it needs to be absolute or relative to your current location.
 
1 members found this post helpful.
Old 05-31-2013, 08:44 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,120

Rep: Reputation: 1345Reputation: 1345Reputation: 1345Reputation: 1345Reputation: 1345Reputation: 1345Reputation: 1345Reputation: 1345Reputation: 1345Reputation: 1345
Quote:
Originally Posted by rlich View Post
ok, I'm fine with how to use copy, but looking for advice on whether it's possible to use relative paths with the src and dst parameters with copy command. For example,

cp /some/path/that/is/really/long/here /some/path/that/is/really/long/here/but/even/longer/than/source

Is there any way to tell linux to copy the file/folder to the same beginning path as the src? In psuedo-code:

cp /some/path/that/is/really/long/here ./but/even/longer/than/source
You could make use of bash brace expansion:
Code:
cp /some/path/that/is/really/long/here{,/but/even/longer/than/source}
which will expand to
Code:
cp /some/path/that/is/really/long/here /some/path/that/is/really/long/here/but/even/longer/than/source
 
3 members found this post helpful.
Old 05-31-2013, 12:48 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,476
Blog Entries: 10

Rep: Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639
As acid kewpie said, it needs to be a full path or relative to where you are, and then to cut it way down, relative will need to be close for both ends of the copy, otherwise it will still be lengthy.

You can create environment variables, and if this is in a script, that is very important to do. Create the variables to point to the base level, and then off of that base, include the subdirectories which fulfill the entire pathname. In the end, you'll still be using the entire pathname, but that is required.

Same for if it's not a script; if you happen to have very long paths, there either is a common base or some point where the root of the main tree is uniform; I'd suggest setting up an environment variable for that and if there are still lengthy means to get to the sub-directories, then you have further environment variables which get set up based on the root. So when you establish a new root, you can invoke a script to re-establish the lower tree environment variables.
 
Old 05-31-2013, 02:31 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
I think the cleanest option is just to cd into the common directory and operate the command from there. You can use (..) subshell brackets so that the change only affects that command. When the subshell exits you'll be back in the directory you started from.

Code:
(
    cd /some/path/that/is/really/long/here
    cp ./* ./but/even/longer/than/source
)

Last edited by David the H.; 05-31-2013 at 02:33 PM. Reason: minor rewording
 
  


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
dow copy copy-protected cds with dd commant gh_D_ir Linux - Software 4 04-01-2011 05:41 PM
CLI copy is greater than GUI copy ?? 0_o killahsmurf Slackware 14 01-04-2006 12:53 PM
boot error after using Copy Commander to copy debian system onto larger new drive Interceptor Linux - Hardware 7 05-04-2003 01:40 PM


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