LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-22-2010, 11:54 PM   #1
tibberous
Member
 
Registered: Oct 2004
Posts: 56

Rep: Reputation: 15
Copying the files inside a folder, without copying the folder (hopefully easy)


I want to copy everything in templates/blue to the folder code/

However:

cp -r 'templates/blue' 'code'

Creates a folder called blue inside code. I tried cp -r 'templates/blue/*' 'code', but that didn't do anything.

Can anyone help me out?
 
Old 12-23-2010, 12:10 AM   #2
crosstalk
Member
 
Registered: Jul 2010
Distribution: Gentoo, Debian, Mint, Xubuntu
Posts: 150

Rep: Reputation: 35
The issue is the quotes (assuming you actually typed them) (you should've gotten an error message ("no such file or directory")):
Code:
$ ls
test1  test2
$ ls test1
1  2
$ ls test2
$ cp -r test1/* test2
$ ls test1
1  2
$ ls test2
1  2
I hope this helps.
 
1 members found this post helpful.
Old 12-23-2010, 01:29 AM   #3
tibberous
Member
 
Registered: Oct 2004
Posts: 56

Original Poster
Rep: Reputation: 15
That was it. To be honest, I don't quite understand quotes in Linux. It seems like you would need to quote file names in case there happened to be spaces, but I guess they work a little different.

I still don't know how to type a literal !. If I want to wget from server to server, and there is a ! in the password, I'll just change the password, lol.
 
Old 12-23-2010, 01:50 AM   #4
crosstalk
Member
 
Registered: Jul 2010
Distribution: Gentoo, Debian, Mint, Xubuntu
Posts: 150

Rep: Reputation: 35
I think the following is accurate:

bash, the shell (command interpreter), will do "shell expansion" of special characters. This means that, when I ran 'cp -r test1/* test2' above, it found test1/1 and test1/2, so the command that actually gets run is 'cp -r test1/1 test1/2 test2', which copies test1/1 and test1/2 into test2. The "cp" command itself does not interpret this.

There are other special characters that are interpreted, too, such as "$". Putting an argument inside double quotes will cause it to all be one argument -- whether or not there are spaces. Furthermore, it does not do the filename expansion. Putting the argument in single quotes will do the same, but it will also disable additional parsing, such as looking for variables ("$").

To escape (make bash ignore the special meaning of) one character, you can use a backslash. You would need to use single quotes or two backslashes in a row to pass a backslash to a command.

You can use "echo" to learn how this works. Try the following commands, and see if you can understand why they behave as they do:
Code:
echo *
echo "*"
echo '*'
echo \*
echo $PATH
echo "$PATH"
echo '$PATH'
echo \$PATH
echo "\$PATH"
echo \\
echo "\\"
echo '\\'
echo '\'
echo ;
echo \;
The last few are more difficult -- but try to at least learn what the first four mean.

By the way, it is kind of insecure to pass passwords as part of the command -- given that that is logged. If wget doesn't automatically ask for a password, you should be able to use "--ask-password" to force it to do so (see "man wget" and "wget --help").

I hope this helps and am glad you got it working.
 
1 members found this post helpful.
  


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
There was an error copying the file into smb:// PcName/Folder/Folder morbid_bean Linux - Networking 3 01-19-2017 04:44 AM
Copying latest 10 files from one folder to another kingjaffi Linux - Newbie 5 11-20-2010 01:09 AM
[SOLVED] copying folder structure with files. myusuf3 Linux - Newbie 1 07-13-2010 01:20 PM
Copying Latest Files to Another Folder nformosa Programming 9 04-23-2009 06:40 AM
copying folder and changing extension of files in it? stratotak Linux - Newbie 18 03-10-2009 01:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:14 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration