Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 24 Mar 2019, 00:39
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
(Solved partly) How to use cp?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [7 Posts]  
Author Message
ITSMERSH

Joined: 02 May 2018
Posts: 911

PostPosted: Thu 29 Nov 2018, 23:35    Post subject:  (Solved partly) How to use cp?  

Hi.

I have a problem on the use of copying files.
I have a source file, but only a target parent directory.

Example:

SRCFILE=/mnt/Exernal-Settings/MYAPPS/MYSETTINGS/myappsettings.txt
TRGTDIR=/root/.config

Copying like this
Code:
cp -a -u "$SRCFILE" "$TRGTDIR"

returns the file as /root/.config/myappsettings.txt.

But I want to have the file returning as /root/.config/MYAPPS/MYSETTINGS/myappsettings.txt - without the need to make the directories first by
Code:
mkdir -p /root/.config/MYAPPS/MYSETTINGS
.

I'm sure there's a way, but don't know how.

Any hints?

Thanks!

_________________
RSH

Beware of the Dog ähem nic007! Wink

Last edited by ITSMERSH on Mon 17 Dec 2018, 15:53; edited 2 times in total
Back to top
View user's profile Send private message 
nosystemdthanks

Joined: 03 May 2018
Posts: 587

PostPosted: Fri 30 Nov 2018, 00:27    Post subject: Re: How to use cp?  

-r makes the cp command recursive, so it copies subfolders.

edit: ohh, right. no, i dont think what youre trying to do is doable without mkdir -p, sorry.

_________________
teaching computing via learning applications is like teaching cooking via going to a restaurant.
Back to top
View user's profile Send private message Visit poster's website 
musher0

Joined: 04 Jan 2009
Posts: 13754
Location: Gatineau (Qc), Canada

PostPosted: Fri 30 Nov 2018, 01:57    Post subject:  

Hi ITSMERSH.

Maybe try answer #14 here:
https://askubuntu.com/questions/124540/how-can-i-copy-a-file-to-a-new-location-creating-the-directory-as-well

As for me I got ok results with < cp --parents > if I placed myself just
above the source dir.
Code:
cd /mnt/ram1
SRCFILE=Perso/myappsettings.txt;TRGTDIR=/root/.config;cp --parents "$SRCFILE" "$TRGTDIR"
(mutatis mutandis, of course)
Otherwise it copies the whole source directory tree.

Trying the < rsync --recursive > command example from that ubuntu
thread froze my X... Sad

IHTH

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
ITSMERSH

Joined: 02 May 2018
Posts: 911

PostPosted: Fri 30 Nov 2018, 16:52    Post subject:  

Thanks musher0.

I will play a little with that in an extra testing script, to see what it can do for me and my issue...

_________________
RSH

Beware of the Dog ähem nic007! Wink
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 3768
Location: holland

PostPosted: Fri 30 Nov 2018, 18:21    Post subject:  

Hi RSH,

I would do this (but possibly can be more compact):

Code:
SRCFILE=$(echo "/mnt/Exernal-Settings/MYAPPS/MYSETTINGS/myappsettings.txt" | sed 's#/mnt/Exernal-Settings/##')
TRGTDIR=/root/.config/
cd /mnt/Exernal-Settings/
cp -a -u --parents "$SRCFILE" $TRGTDIR
cd -- # get back


Fred

_________________
Dog Linux website
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 13754
Location: Gatineau (Qc), Canada

PostPosted: Fri 30 Nov 2018, 19:57    Post subject:  

I hate to say it, but it's true:

the < copy > command in the old Dos was simpler to understand and work
with than this Linux < cp > with its needed contorsions.

_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
slavvo67

Joined: 12 Oct 2012
Posts: 1593
Location: The other Mr. 305

PostPosted: Sat 08 Dec 2018, 00:46    Post subject:  

Try cp -parents
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [7 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0383s ][ Queries: 12 (0.0095s) ][ GZIP on ]