Can I Use Wildcards with Linux?
Wildcards come in handy when you want to perform an operation on a group of files. As with DOS or Windows, if you want to delete all your files that start with "jan" and end with "txt," you can use the asterisk (*) wildcard character, as in rm j an*txt, to delete all such files (rm is the command you use to delete files). The * character tells the shell to find any files that begin with "jan" and end with "txt" regardless of the number of characters between. It will even find files with no characters between, like jantxt. Thus, a file named jan-9 6.txt would be deleted, as would jantxt.
A more restrictive wildcard is the question mark, which matches any single character. Here are some examples of its use:
rm jan-8?.txt deletes jan-81.txt and jan-82.txt, but not jan-89b.txt
rm jan-95.??? deletes jan-95.txt and jan-95.dat, but not jan-95.db
When you use wildcards, the shell finds all matching files and expands the command you entered, so the rm jan-95.* command would be the same as typing
rm jan-95.txt jan-95.dat jan-95.db
Programmers take note: In Linux, the shell performs wildcard interpretation, and the actual commands (programs) never see the wildcard characters. This provides a convenient and common way for all Linux programs to handle wildcards. In DOS, the program (not the shell) must have the intelligence to handle wildcards. The unhappy result there is that you never know which DOS commands will accept wildcards, and each program may interpret them differently--yuck!
Previous Lesson: The Command Prompt
Next Lesson: Command History
Comments - most recent first
(Please feel free to answer questions posted by others!)
I am trying to clean up some archives and I have literally thousands of directories I need to remove html (some of them .htm) and .php documents from.
Using Fedora 17/64, 8 gig ram with Sata 2 hard drives for what its worth.
Id prefer not to have to confirm every file deletion too. I don't have days to watch over it.
No scripts please.
Suggestions appreciated.
Thank you.
Peter
To remove every kind of file and not just text files, use the below command.
rm jan*
A file names three letter extension is also part of the file name in Unix. (File name extensions/suffixes have no meaning on Unix. They are simply part of the file name)
My understanding is a shell is a program mainly concerned with interpreting command strings, and a
terminal or tty or getty is a program mainly concerned with emulating a particular hardware combination, namely a keyboard and its display device be it a line printer or video display.
If I'm right about this, what do we need to know about the choices we have?
Thanx Bob !
rm jan*
rm jan*.*
dont u think this would b useful in removin all files that start with jan & irrespective of their formats(.txt, .db, .doc)
I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But
don't ask me to send what you already have. :-) NO SPAM! If you post garbage, it will be deleted, and you will be banned.
Copyright © by -
All rights reserved - Redistribution is allowed only with permission.

