LinuxQuestions.org
Review your favorite Linux distribution.
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 02-10-2015, 07:47 PM   #1
linux_walt
Member
 
Registered: Dec 2014
Location: Houston, TX
Distribution: Debian wheezy
Posts: 127

Rep: Reputation: 28
cp -r *.* /<dest folder>: What does *.* literally mean in Linux?


I have been using this command a lot lately:
Code:
sudo cp -r *.*  /<dest folder owned by root>
Goal: to copy all contents of current folder into destination folder.

I know there are other ways, and have tried several, but gave up in confusion (was also in a hurry to get on with it). Finally gave the windows *.* a shot, and it did exactly what I wanted.

Now that my task is completed, it would be nice to know what *.* literally means in Linux. I just looked though man cp, and also ran
Code:
info coreutils 'cp invocation'
but didn't see any '*' options listed. Now I remember having come across '.' before somewhere, in the cp command, so possibly the '*' are ignored, and the only thing that matters is the 'dot'?

Last edited by linux_walt; 02-10-2015 at 08:10 PM.
 
Old 02-10-2015, 10:36 PM   #2
ulto
Member
 
Registered: Apr 2004
Posts: 52

Rep: Reputation: 1
* would generally mean a wildcard, which would accept any alphanumeric character. So any file for example taht you be [A-Za-z0-9].[A-Za-z0-9]
Not too sure about special characters but from memory they match aswell.

http://en.wikipedia.org/wiki/Wildcard_character
Quote:
When specifying file names (or paths) in CP/M, DOS, Microsoft Windows, and Unix-like operating systems, the asterisk pattern character ("*", also called "star") matches zero or more characters.
This will also flesh it out for you.

http://www.linfo.org/wildcard.html
 
Old 02-10-2015, 11:13 PM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,145

Rep: Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351
That *.* would match any file or directory name that had a literal "." in it. Copying from Windows, it would ignore any name with no extension. (Such files are a lot more common in Linux than they are in Windows. In Windows, names with no extension are likely to be directories.)

Last edited by rknichols; 02-10-2015 at 11:15 PM.
 
Old 02-11-2015, 12:07 AM   #4
linux_walt
Member
 
Registered: Dec 2014
Location: Houston, TX
Distribution: Debian wheezy
Posts: 127

Original Poster
Rep: Reputation: 28
Thanks for the input, I've restored some energy and have looked at your links, and come up with one of my own as well:
http://www.tldp.org/LDP/GNU-Linux-To...tml/x11655.htm

rknichols, hello. That is not the way it was working for me. The main use I had for it was the multiple time I had to do the following for a Linux build:
Quote:
Copy contents of
~/sysdev/linux-sunxi/output/lib/modules
to /mnt/sd2/lib/modules on the target root file system

cd ~/sysdev/linux-sunxi/output/lib/modules
sudo cp -r *.* /mnt/sd2/lib/modules/
There are all sorts of dotted and un-dotted files in there, as well as subdirectories. All were copied, and Image is working.

Still not too clear on the original question though, since It looks like the cp command can use wildcards (globbing patterns) and also regular expressions? If so how does the command know which type you mean?

From man 7 glob (Wildcards)
Quote:
'*' (not between brackets) matches any string, including the empty
string.

NOTES
Regular expressions
Note that wildcard patterns are not regular expressions, although they
are a bit similar. First of all, they match filenames, rather than
text, and secondly, the conventions are not the same: for example, in a
regular expression '*' means zero or more copies of the preceding
thing.
I don't see any mention of the 'dot', as a wildcard in man 7 glob. However, in the link above it is mentioned in the 'regular expression' section when combined with an asterisk:
Quote:
.* (dot and asterisk)

is used to match any string, equivalent to * in standard wildcards.

* (asterisk)

the proceeding item is to be matched zero or more times. ie. n* will match n, nn, nnnn, nnnnnnn but not na or any other character.
So, as a regular expression, *.* should (?) mean:
[any number of preceding white spaces][any string]
This is the way it seems to be working.

As a wildcard expression *.* should mean:
[any number of characters].[any number of character]
Only file names or folders that include a 'dot' in the name. This is not the way it's working.

I would test out some examples, but I'm tired again.
...
Just squeezed one test in and got an error:
Code:
cp: cannot stat `*.*'
I'm 100% positive I used it just this morning.

Ok this is p*.* me off. Tried it several ways and ended up with just using the 'dot':

Code:
walter@cubier:~$ tree -al cptest
cptest
|-- destination
`-- origin
    |-- .config
    |-- README
    `-- morestuff
        |-- baloney
        `-- notes.txt

walter@cubier:~$ cd cptest/origin
walter@cubier:~/cptest/origin$  cp -r . ~/cptest/destination
walter@cubier:~/cptest/origin$ tree -al ~/cptest

/home/walter/cptest
|-- destination
|   |-- .config
|   |-- README
|   |-- destination
|   |   `-- .config
|   `-- morestuff
|       |-- baloney
|       `-- notes.txt
`-- origin
    |-- .config
    |-- README
    `-- morestuff
        |-- baloney
        `-- notes.txt

Last edited by linux_walt; 02-11-2015 at 01:05 AM.
 
Old 02-11-2015, 01:05 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
Just to confirm:
Quote:
There are all sorts of dotted and un-dotted files in there, as well as subdirectories.
Does 'dotted' files mean files starting with a dot, ie .bashrc? If so, this would not be the norm so I would be guessing maybe you have sort of alias that is somehow interpreting the parameter differently.

I would also add that the below is slightly incorrect:
Quote:
So, as a regular expression, *.* should (?) mean:
[any number of preceding white spaces][any string]
As a regular expression this should fail, because you are assuming the space before the first asterisk is not a continuation of the previous character.

Lastly, it is important to remember that the shell will expand your unquoted glob prior to the data being passed to the cp command.
As a simple test, try the following:
Code:
$ cd ~/sysdev/linux-sunxi/output/lib/modules
$ set -xv
$ ls *.*
$ set +xv
After the ls line you will see what is expanded prior to ls showing you the output.

You may also want to look into the '-r' option for what it is doing

Last edited by grail; 02-11-2015 at 01:06 AM.
 
1 members found this post helpful.
Old 02-11-2015, 01:16 AM   #6
linux_walt
Member
 
Registered: Dec 2014
Location: Houston, TX
Distribution: Debian wheezy
Posts: 127

Original Poster
Rep: Reputation: 28
Thanks grail, will have to try that tomorrow, got to get some sleep now. I'll leave this more confused than before, because cp *.* -did- work. I was using the same system that I just ran the tests above (which just made a mess), however I was going though the process of building a kernel, so may have been in some weird mode, like 'chroot' or a different shell, I don't know. I know at the moment, in normal mode , *.* is not working anymore, as you pointed out it wouldn't.

Thanks for the input, and good night!
 
Old 02-11-2015, 09:33 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,145

Rep: Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351
Since you were using the "-r" option in cp, any directory whose name contained "." would match, and that would cause everything under that directory to be copied.

And no, "." is not a special character in a glob expression. It is somewhat special as the first character in a file or directory name, in that an initial "." is not by default matched by "?" or "*". (There are various shell options that affect how pathname expansion is done.)

It's a lot easier to see if you just try "echo *.*" in a directory with a mix of file names.

Last edited by rknichols; 02-11-2015 at 09:35 AM.
 
Old 02-12-2015, 02:16 PM   #8
linux_walt
Member
 
Registered: Dec 2014
Location: Houston, TX
Distribution: Debian wheezy
Posts: 127

Original Poster
Rep: Reputation: 28
Quote:
Originally Posted by grail View Post
Just to confirm:

Does 'dotted' files mean files starting with a dot, ie .bashrc? If so, this would not be the norm so I would be guessing maybe you have sort of alias that is somehow interpreting the parameter differently.

I would also add that the below is slightly incorrect:

As a regular expression this should fail, because you are assuming the space before the first asterisk is not a continuation of the previous character.

Lastly, it is important to remember that the shell will expand your unquoted glob prior to the data being passed to the cp command.
As a simple test, try the following:
Code:
$ cd ~/sysdev/linux-sunxi/output/lib/modules
$ set -xv
$ ls *.*
$ set +xv
After the ls line you will see what is expanded prior to ls showing you the output.

You may also want to look into the '-r' option for what it is doing
Excellent, thank you. I'm leaving the 'set -xv' turned on for now. This will help a great deal in understanding.
Code:
~/sysdev/linux-sunxi/output/lib/modules$ ls *.*
ls *.*
+ ls --color=auto 3.4.103-00033-g9a1cd03
build              modules.builtin      modules.devname  modules.symbols.bin
kernel             modules.builtin.bin  modules.order    source
modules.alias      modules.dep          modules.softdep
modules.alias.bin  modules.dep.bin      modules.symbols
Quote:
Does 'dotted' files mean files starting with a dot, ie .bashrc? If so, this would not be the norm so I would be guessing maybe you have sort of alias that is somehow interpreting the parameter differently.
Yes, that's what I meant, particularly thinking of .config files.


rknichols, I tried echo *.* but apparently it's not understood, it just responds by printing out *.* again:
Code:
~/cptest/origin$ ls -al
total 3
drwxr-xr-x 3 walter walter 1024 Feb 10 23:35 .
drwxr-xr-x 4 walter walter 1024 Feb 10 23:38 ..
-rw-r--r-- 1 walter walter    0 Feb 10 23:34 .config
-rw-r--r-- 1 walter walter    0 Feb 10 23:34 README
drwxr-xr-x 2 walter walter 1024 Feb 10 23:36 morestuff

~/cptest/origin$ echo *.*
*.*
Quote:
And no, "." is not a special character in a glob expression. It is somewhat special as the first character in a file or directory name, in that an initial "." is not by default matched by "?" or "*". (There are various shell options that affect how pathname expansion is done.)
I did find the shell option to turn 'dot' on, so it would be included by "?" and "*". Can't remember what the command was at the moment, but left the option turned off. Felt like 'hacking' to get around my ignorance.


Tried another command that will copy all the contents of one folder to another, including hidden files: rsync.
From inside the folder whose content you wish to copy:
Code:
rsync -rt . ~/cptest/destination/
-r: recursive
t: preserve file's creation time

My next task, now that I have a bit clearer understanding of what it is that I don't know, is looking more into the difference between wildcards and regular expression. When each applies, and use the 'new' set -xv tool.

Last edited by linux_walt; 02-12-2015 at 02:29 PM.
 
Old 02-12-2015, 04:08 PM   #9
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,145

Rep: Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351
Quote:
Originally Posted by linux_walt View Post
rknichols, I tried echo *.* but apparently it's not understood, it just responds by printing out *.* again:
Code:
~/cptest/origin$ ls -al
total 3
drwxr-xr-x 3 walter walter 1024 Feb 10 23:35 .
drwxr-xr-x 4 walter walter 1024 Feb 10 23:38 ..
-rw-r--r-- 1 walter walter    0 Feb 10 23:34 .config
-rw-r--r-- 1 walter walter    0 Feb 10 23:34 README
drwxr-xr-x 2 walter walter 1024 Feb 10 23:36 morestuff

~/cptest/origin$ echo *.*
*.*
Correct. There are no files in that directory that match "*.*", so the shell just leaves that argument as you wrote it. Try it again in a directory that has a file like "stuff.txt" that does contain an embedded "." in its name.
 
1 members found this post helpful.
Old 02-12-2015, 09:09 PM   #10
linux_walt
Member
 
Registered: Dec 2014
Location: Houston, TX
Distribution: Debian wheezy
Posts: 127

Original Poster
Rep: Reputation: 28
Ok, I tried it and it printed out only the one file:

Code:
walter@cubier:~/cptest/origin$ ls -al
total 3
drwxr-xr-x 3 walter walter 1024 Feb 12 19:12 .
drwxr-xr-x 4 walter walter 1024 Feb 10 23:38 ..
-rw-r--r-- 1 walter walter    0 Feb 10 23:34 .config
-rw-r--r-- 1 walter walter    0 Feb 10 23:34 README
drwxr-xr-x 2 walter walter 1024 Feb 10 23:36 morestuff
-rw-r--r-- 1 walter walter    0 Feb 12 19:11 test.txt

walter@cubier:~/cptest/origin$ set -xv
walter@cubier:~/cptest/origin$ echo *.*
echo *.*
+ echo test.txt
test.txt
I also tried the cp command again with *.*, and it also only worked if there is a file with a dot inside the name, but not as the leading character.

Now, I would have to rebuild my SD card image again, to see exactly under what conditions cp *.* actually copied the contents of one folder into another.
 
  


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
Making a (literally) raw cd jmoschetti45 Linux - Software 3 02-04-2010 10:08 AM
My desktop is literally gone hoosierfan24 Linux - Desktop 8 06-12-2009 02:08 PM
read variable literally CrossMAX Programming 5 02-18-2009 07:17 AM
Linux Installation from scratch, literally... Kernel loading floppy question EnigmaX Linux - General 3 08-05-2004 09:50 PM
Literally know nothing about ethernet zella_19 Linux - Newbie 1 03-14-2002 12:01 AM


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