LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 06:36 AM   #1
rlich
LQ Newbie
 
Registered: Apr 2013
Posts: 10

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, 06:42 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
no, it needs to be absolute or relative to your current location.
 
1 members found this post helpful.
Old 05-31-2013, 07:44 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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, 11:48 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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, 01:31 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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 01:33 PM. Reason: minor rewording
 
  


Reply



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 04:41 PM
CLI copy is greater than GUI copy ?? 0_o killahsmurf Slackware 14 01-04-2006 11:53 AM
boot error after using Copy Commander to copy debian system onto larger new drive Interceptor Linux - Hardware 7 05-04-2003 12:40 PM

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

All times are GMT -5. The time now is 10:36 PM.

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