[SOLVED] How to copy and paste via the terminal, without mentioning the directories?
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to copy and paste via the terminal, without mentioning the directories?
Hello! I hope I wrote this in the right section... I was searching everywhere on how to do as the title indicates, maybe I was googling wrong or something, but I couldn't find the answer. It's for a class homework but I can't seem to remember the teacher demonstrating this.
It goes something like this:
-From the repc/repd directory, copy all files from the repb directory to the repc/repd directory with only one command, without the words repc or repd appearing in the command.
I believe the first step is to do cd ~/repc/repd, but afterwards, I'm completely lost...
I don't care much about which subforum, I only look at whats new
but, I believe you go the correct one
lesson 1, code tags
[code]
write your code example here
[/code]
Quote:
I believe the first step is to do
Code:
cd ~/repc/repd
, but afterwards, I'm completely lost...
well, that would be incorrect, the question was clear about one command
Quote:
From the repc/repd directory, copy all files from the repb directory to the repc/repd directory with only one command, without the words repc or repd appearing in the command.
it is an awful question, but I understand what they are demonstrating
there is a few ways of doing it
I shall show you the wrong way
Code:
cp ./repb/* ./repc/*d/
that works but fails the question
but I hope it jogs a memory
the question is to demonstrate an understanding of wildcards
hence the restriction
Yes. Only one command "From the repc/repd directory," which I read "as after being in that directory"...so after the cd -- which the OP had already correctly figured out.
And Yes, my example was incorrect. I've edited it to copy all the files.
As originally posted, the response would have been
Code:
cp: omitting directory '~repb'
and no copy would have happened, as a cp command with no options will not copy a directory.
I stand by my evaluation that it was about learning what "." means.
Not sure about the pattern matching, and I suspect you're correct that that would not follow the spirit of the question...I'll read up on that, but that cp command would try to copy from ~/repc/repd/repb/* (although, upon review of the OP, it doesn't specifically state where repb is...I presumed it was ~/repb, but we don't really know)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,802
Rep:
Quote:
Originally Posted by lemonspaghetti
...
It goes something like this:
-From the repc/repd directory, copy all files from the repb directory to the repc/repd directory with only one command, without the words repc or repd appearing in the command.
I believe the first step is to do cd ~/repc/repd, but afterwards, I'm completely lost...
You left out a rather important bit about the directory structure: the relationship between repb, repc, and repd. (Well, you did tell us that repd is under repc.)
If they're not all nested, what about:
Code:
$ cd repc/repd ; find /repb -maxdepth 1 -type f -exec cp {} . \;
I'm not sure if that qualifies as one command, though. You have to get to the "repc/repd" directory somehow. Heck, with practice you can write gnarly while/do with complex `if-else-fi's as a "single command" before you finally press Enter.
Snarky answer:
Code:
$ dolphin
Only one command. Copy via dragging and dropping. :^D
Quote:
[Using RedHat CentOS7, if it changes anything]
It doesn't. (Although Red Hat has done some strange things over the years that have wound up making their way into most other distributions, so maybe...)
Actually, if you read the OP carefully, he doesn't mention the location of the repb dir, so it's not necessarily about relative dirs (although you could do it that way).
I'd also argue that given
Quote:
It goes something like this:
-From the repc/repd directory,
cd'ing into 'repc/repd' initially is not only allowed, but indeed implied ...
Actually, if you read the OP carefully, he doesn't mention the location of the repb dir, so it's not necessarily about relative dirs (although you could do it that way).
I'd also argue that given
cd'ing into 'repc/repd' initially is not only allowed, but indeed implied ...
if you read the question carefully you see cd ~/repc/repd
which creates the ambiguity which lead me to the dir struct
Code:
repb/
repc/repd/
and cd is one command, cp is another
together that are more than one
implied is that you start in repd
but in my mind ../../repb/ was too simple, which is why I invented this scenario
that it was about wildcards
Code:
cp repb/* r*c/r*d/
but now I see the repa/repb/repc/repd clearly after correcting the question
and ignoring the cd ~/repc/repd
Not sure about the pattern matching, and I suspect you're correct that that would not follow the spirit of the question...I'll read up on that, but that cp command would try to copy from ~/repc/repd/repb/* (although, upon review of the OP, it doesn't specifically state where repb is...I presumed it was ~/repb, but we don't really know)
Sorry for the late clarification, the directories are as go ~/repd ~/repc/repd
That was my bad!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.