A
A
Asparagales2018-11-05 14:12:50
bash
Asparagales, 2018-11-05 14:12:50

What does the * (asterisk) symbol mean in regular expressions?

I'm reading a tutorial on the basics of Linux. The textbook says that * (asterisk) is a wildcard and means any sequence of any characters.
Elsewhere, an example of a command is given that, according to the authors of the tutorial, will copy all files and folders from the dir1 directory to the dir2 directory.
cp -r dir1/* dir2
But this command does not copy files and directories whose names start with a dot. On the contrary, they will be copied if the asterisk symbol is removed. The situation is similar with the rm command.
Another example: the echo * command will not show hidden files.
So what other exceptions are there to the rule that an asterisk means any sequence of any characters?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2018-11-05
@Asparagales

Don't confuse regular expression with shell globbing.
According to the rules of shell globbing expansion, an asterisk means all characters in any number, except for lines that begin with a dot.
cp -r dir1/* dir2
means to copy all files from dir1 to dir2, except for those that start with a dot
cp -r dir1/ dir2
means to copy dir1 itself (with all contents) to dir2, so hidden files will be copied as well .
There are no other exceptions to the asterisk.
If you take not shell globbing, but for example the find command, there the asterisk is already processed by the find command itself and will find all files, for example
find / test -name "*"
finds all files and directories in /test, including those that start with a dot. That is, only the
PS shell itself has a limit on tldp.org, you can always find the truth, for example tldp.org/LDP/abs/html/globbingref.html

S
Softer, 2018-11-05
@Softer

In this case, copy all files and directories from dir1 to dir2
And yes, this is not a regular expression, here it means "all contents" :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question