Questions tagged [wildcards]

Globbing means matching files by name patterns containing wildcards.

You can specify a set of files matching a certain glob pattern using wildcard characters, e.g. cp *.txt /directory. This is handled by the shell, so it is available on the command line no matter what program you are starting. Conversely, if you need to pass one of the wildcard characters to a command, it must be quoted, e.g. rsync -a --exclude='*.bak' /source /destination.

Globbing is known by various names accross shell documentations: filename generation, pathname expansion, pattern matching, wildcard matching… Advanced shells such as , and implement additions to the basic glob patterns. These additions make wildcards as expressive as regular-expressions , but with a different syntax. There are other programs, such as , that use a similar wildcards syntax to match files by name.

For more complex tasks such as matching files in subdirectories recursively or matching files by metadata such as date or size, try .

References

Further reading

1099 questions
14
votes
4 answers

How to find all files except a specified file

The ls can give a result like [root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# ls CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo But actually I hope to just find out…
yode
  • 1,047
9
votes
4 answers

List all the files ending with 10 or 11 or 12

To list all the files ending with 10 or 11 or 12 I have tried ls *[10-12] and ls *[10,11,12] but these are not working. I don't know why. Can anyone help me?
Arpit
  • 99
5
votes
2 answers

Meaning of "[--0]" in a glob pattern

I was reading about "Glob" and "Globbing Pathnames", and I found this strange (to me) part in man pages: "[--0]" matches the three characters '-', '.', '0', since '/' cannot be matched. I am confused! How do two dashes and a 0 match .? What is the…
4
votes
3 answers

What exactly did mv /tmp/folder/* /* do to my filesystem?

It's hard to search for special characters on google, which is why I'm posting this here. I recently ran (as root) a mv /tmp/folder/* /* when I meant to run mv /tmp/folder/* ./ Big mistake! Things broke! A lot of files got mixed up and placed into…
M L
  • 51
4
votes
2 answers

Is there a reason to use multiple question marks instead of an asterisk in filename expansion?

If I have a number of directories, named, for example 10001 through 10025 is there any reason to use ls 1*/foo vs. ls 100??/foo? I have a lot more than 25 of them, so I mostly curious if there's any differences in speed. I know the difference in use…
3
votes
2 answers

Wildcards: How to exclude a string? (Does not contain)

I was practicing the use of wildcards today .. that was a lot of fun. The most complex thing that worked out exactly as I was expecting was: ls [![:digit:]]*[a-z][0-9][0-9][0-9][aA-zZ]*[![:digit:]] But I didn't actually manage to exclude a…
Heiko
  • 261
  • 3
  • 9
3
votes
1 answer

Wildcard doesn't expand in for loop with variable

I'm trying to loop through several files with this naming structure: apple_123.txt, orange_456.txt, banana_789.txt I'm trying to use a wildcard for the numbers, but the wildcard is not expanded and the output looks like this: apple_*.txt I've tried…
nute11a
  • 33
2
votes
1 answer

Wildcards gobbling

Wildcards An asterisk (*) – matches one or more occurrences of any character, including no character. Can anyone explain what is this “ including no character” means?
2
votes
3 answers

How to list all files including an odd number in a specific number range?

I have a dataset with files named "file000.txt" to "file999.txt". Im aware that I can list all files from 0 to 500 using wildcards with ls file{0..500} And that I can find all files containing an odd number with ls file*[1,3,5,7,9].txt Im new to…
2
votes
2 answers

Is it possible to show how bash globbing works by doing?

I am teaching someone how bash globbing works. I would like to show (via some bash debugging feature if possible) how bash expands the patterns prior to invoking the command. For instance I would like to do the following: ls -l file*.txt Then I…
1
vote
1 answer

Wildcards in Vim not working as expected – how to remove binary column from example?

I've tried to removed the binary columns in my octal help function. First echo is in line 70, I wanted to delete |000 and the same pattern .. first | + three numerals for all echo lines. So I have tried…
Heiko
  • 261
  • 3
  • 9
1
vote
3 answers

Concatenate multiple files from different directories

I want to concatenate multiple files from different directories. Directory 1: Chr1 containing (in this example) four files: ABC.1 DEF.1 GHI.1 JKL.1 Directory 2: Chr2 ABC.2 DEF.2 GHI.2 JKL.2 There are 22 directories. Each file has 20 columns…
1
vote
0 answers

What does this wildcard mean

If ls [ab]* lists all files with names that start with a or b, Then ls [*a]* will list all files with names that start with * (everything) or a. So why does it only list file with names starting with a?
1
vote
0 answers

How to negate tmpwatch exclude-pattern

I want to negate --exclude-pattern option so that tmpwatch excludes all but files matching the pattern. For exemple , if I want to remove only *.gz files it would be something like that : tmpwatch 10d --exclude-pattern=!*.gz . I appreciate your…
storm
  • 133
0
votes
3 answers

How to find linux commands using wildcards ? and *

In my Linux machine I am able to find commands starting with ls by $ ls I get the results like this, ls lsb_release lscpu lshw lsipc lslogins lsmod lsof lspcmcia lss16toppm lsattr …
1
2