LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Copying the files inside a folder, without copying the folder (hopefully easy) (https://www.linuxquestions.org/questions/linux-software-2/copying-the-files-inside-a-folder-without-copying-the-folder-hopefully-easy-851933/)

tibberous 12-22-2010 11:54 PM

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?

crosstalk 12-23-2010 12:10 AM

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.

tibberous 12-23-2010 01:29 AM

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.

crosstalk 12-23-2010 01:50 AM

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.


All times are GMT -5. The time now is 05:08 PM.