Linux Basics (tutorial) #7

Discuss everything about Linux here!

Moderator: Community Moderator

Post Reply
User avatar
MrNiitriiX
Premium Uploader
Premium Uploader
Posts: 2197
Joined: 19 Apr 2010, 14:52
Location: between space and time
Has thanked: 24 times
Been thanked: 164 times

Linux Basics (tutorial) #7

Post by MrNiitriiX »

Can I Use Wildcards with Linux?
Wildcards

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!

LINKS TO THE OTHER TUTORIALS


Leason 1: Living in a shell
Leason 2: Root and Other Users
Leason 3: Virtual Consoles
Leason 4: Logoff and Shutdown
Leason 5: Choosing a Shell
Leason 6: The Command Prompt
Leason 7: Wildcards
Leason 8: Command History and Editing
Leason 9: Aliases
Leason 10: Redirection
Leason 11: Pipelines
Leason 12: Processes
Leason 13: Stopping a Program
Leason 14: Environment Variables
Leason 15: Help!
Last edited by MrNiitriiX on 31 Jul 2010, 13:04, edited 1 time in total.
"Injustice anywhere is a threat to justice everywhere." - Martin Luther King
Image
Upload List
Post Reply

Return to “Everything Linux”