Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question (How can I remove gnome from a kubuntu 12.04 install?) have the commands with question markes:

sudo apt-get remove --purge ubuntu-desktop
sudo apt-get remove --purge unity?
sudo apt-get remove --purge gnome?

What do the question mark mean?

share|improve this question

2 Answers 2

up vote 14 down vote accepted

Those are called Wildcards (globbing patterns)

Standard wildcards (also known as globbing patterns) are used by various command-line utilities to work with multiple files.
Standard wildcards are used by nearly any command (including mv, cp, rm and many others).

  • (question mark)

    this can represent any single character. If you specified something at the command line like "hd?" GNU/Linux would look for hda, hdb, hdc and every other letter/number between a-z, 0-9.

  • *(asterisk)

    this can represent any number of characters (including zero, in other words, zero or more characters). If you specified a "cd*" it would use "cda", "cdrom", "cdrecord" and anything that starts with “cd” also including “cd” itself. "m*l" could by mill, mull, ml, and anything that starts with an m and ends with an l.

  • [ ] (square brackets)

    specifies a range. If you did m[a,o,u]m it can become: mam, mum, mom if you did: m[a-d]m it can become anything that starts and ends with m and has any character a to d inbetween. For example, these would work: mam, mbm, mcm, mdm. This kind of wildcard specifies an “or” relationship (you only need one to match).

  • { } (curly brackets)

    terms are separated by commas and each term must be the name of something or a wildcard. This wildcard will copy anything that matches either wildcard(s), or exact name(s) (an “or” relationship, one or the other).


For example, this would be valid:

  • cp {.doc,.pdf} ~

    This will copy anything ending with .doc or .pdf to the users home directory. Note that spaces are not allowed after the commas (or anywhere else).

  • [!]

    This construct is similar to the [ ] construct, except rather than matching any characters inside the brackets, it'll match any character, as long as it is not listed between the [ and ]. This is a logical NOT. For example rm myfile[!9] will remove all myfiles* (ie. myfiles1, myfiles2 etc) but won't remove a file with the number 9 anywhere within it's name.

  • \ (backslash)

    is used as an "escape" character, i.e. to protect a subsequent special character. Thus, "\” searches for a backslash. Note you may need to use quotation marks and backslash(es).

for more examples: visit this page

share|improve this answer
    
Thank you so much :D –  Ooker Mar 18 at 13:53
3  
It is worth mentioning that apt-get remove requires package names, not filenames, which makes wildcard expansion by the shell largely useless. If you want to remove a range of packages you need to use a full regular expression, quoted appropriately to prevent the shell from trying to interpret it as a glob (e.g. apt-get remove 'gnome.*'). –  OrbWeaver Mar 18 at 15:01
3  
Standard wildcards are used by nearly any command (including mv, cp, rm and many others). => FALSE. these wildcards are being expanded by the shell and what the command receives is the result of the expansion (ie the files that match the pattern) instead of the pattern. (if there isn't any file that matches the pattern then that pattern will be passed directly to the command, though) –  Carlos Campderrós Mar 19 at 9:48

Generally speaking, in Bash, a ? is a glob pattern that expands to an arbitrary character.

For example:

$ echo Hello1 > foo1
$ echo Hello2 > foo2
$ cat foo?
Hello1
Hello2

It is akin to a *, but a * expands to 0 or more characters, while a ? expands to exactly one (arbitrary) character.

In your special case though, the ? in the command was apparently a typo.

share|improve this answer
    
So it's is useless/needless in my case, right? –  Ooker Mar 18 at 13:14
    
Yes. In fact it was edited out of the answer you linked to when you asked your question. :) –  Malte Skoruppa Mar 18 at 13:14
    
Can't believe it :-o –  Ooker Mar 18 at 13:16
1  
Even if they were correct wildcards, this use should be avoided without quoting. apt-get understand REs, but if a file called gnome1 exists in the current directory, the shell will expand it before apt-get had any chance of seeing it. –  Rmano Mar 18 at 13:54
    
@Ooker You'll never forget it now! –  comrademike Mar 18 at 14:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.