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 09-23-2019, 03:26 PM   #1
lemonspaghetti
LQ Newbie
 
Registered: Sep 2019
Posts: 7

Rep: Reputation: Disabled
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...

[Using RedHat CentOS7, if it changes anything]
 
Old 09-23-2019, 04:32 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
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
 
Old 09-23-2019, 05:42 PM   #3
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
I think the problem wants you to understand how to indicate "here" in a command.

Code:
cd ~/repc/repd
cp ~/repb/* .
the "." means "the directory I'm in" You can see that if you cd to a directory, then type
ls -la
...you'll see two entries at the top of the output:
Code:
ls -la 
dr-xr-x---. 25 root root 4096 Sep 17 15:04 .
dr-xr-xr-x. 18 root root 4096 Sep 13 12:20 ..
The . is the directory you're in and the .. is the parent of that directory.

I'm not sure what you'd use for a search term to find something that would explain that.

Last edited by scasey; 09-23-2019 at 06:24 PM. Reason: Correct cp command
 
Old 09-23-2019, 05:45 PM   #4
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
maybe the question got mashed up somewhere

but I read "only one command"

cd and cp is two commands


and it is files in the dir, not the dir

the question is to demonstrate an understanding of wildcards
hence the restriction
Quote:
"without the words repc or repd appearing in the command. "

Last edited by Firerat; 09-23-2019 at 05:49 PM.
 
Old 09-23-2019, 05:51 PM   #5
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
to stick two fingers up at teacher

Code:
cp repb/* +([cper])/+([pder])/
but that is going to get you caught at cheating

https://www.linuxjournal.com/content...-matching-bash
 
Old 09-23-2019, 06:02 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,701

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
I agree with scasey the question is about parent directories and dot notation. As always, we will help you but not provide the answers.
 
Old 09-23-2019, 06:32 PM   #7
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by Firerat View Post
maybe the question got mashed up somewhere

but I read "only one command"

cd and cp is two commands

and it is files in the dir, not the dir

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.
 
Old 09-23-2019, 06:37 PM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by Firerat View Post
to stick two fingers up at teacher

Code:
cp repb/* +([cper])/+([pder])/
but that is going to get you caught at cheating

https://www.linuxjournal.com/content...-matching-bash
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)
 
1 members found this post helpful.
Old 09-23-2019, 06:45 PM   #9
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
I assumed the dirs were in /repa/
and we were in /repa/

Code:
/repa/repb/
/repa/repb/afile.sh
/repa/repb/bfile.sh
/repa/repb/cfile.sh
/repa/repc/
/repa/repc/repd/
and wanted to move the files to /repa/repc/repd/
 
Old 09-23-2019, 06:57 PM   #10
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
ahh, yeah, your right


Quote:
From the repc/repd
so

Code:
/repa/repb/repc/repd/
we are in repd
and the files are in ../../


Code:
mkdir -p repa/repb/repc/repd
touch repa/repb/{a..d}file.sh
cd repa/repb/repc/repd
# begin test
I still prefer my version

Last edited by Firerat; 09-23-2019 at 06:58 PM.
 
1 members found this post helpful.
Old 09-23-2019, 09:29 PM   #11
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,802

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by lemonspaghetti View Post
...

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 {} . \;
If the directories are "repb/repc/repd":
Code:
$ cd /repb/rebc/repd ; find ../../ -maxdepth 1 -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...)

HTH...
 
Old 09-24-2019, 12:49 AM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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 ...
 
Old 09-24-2019, 04:33 AM   #13
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by chrism01 View Post
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
 
Old 09-24-2019, 02:11 PM   #14
lemonspaghetti
LQ Newbie
 
Registered: Sep 2019
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
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!
 
Old 09-24-2019, 02:24 PM   #15
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
and where do you start?

do you have the full question, verbatim?

I *need* to know now
 
  


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
how to copy and paste text directly from the terminal using keyboard and mouse without writing commands? sandyiitism Linux - Newbie 6 09-02-2017 09:07 AM
[SOLVED] Preventing the screen copy and paste error on first paste slackartist Slackware 0 04-03-2016 06:48 PM
I felt that this was worth mentioning.... szboardstretcher General 6 02-26-2014 06:13 AM
LXer: Open-Source RPG Projects Worth Mentioning LXer Syndicated Linux News 0 01-12-2014 01:51 AM
How to resume download by curl without mentioning the no. of bytes? Arighna Programming 5 06-02-2011 10:08 AM

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

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