Friday, March 09, 2007

Filename Completion Wild Card Characters

Here are a few common uses for completing filenames with wild cards. I will demonstrate the "*", "?", and "[]" wild card options.

The asterisk, "*", represents any sequence of characters.

Prints all files that end with "2007.txt" eg. file12007.txt, file22007.txt, etc.
#lp *2007.txt
Prints all files that end with "txt" in the current directory
#lp *txt

Removes everything in the current directory (BE CAREFUL!)
#rm *
#rm -i * (interactive)

List all files that have "Feb" in its filename
#ls -l *Feb*

The question mark, "?", represents one character.
Print all documents in the current directory that contains report.1(any single character).txt eg. report.2a.txt, report.20.txt, report.21.txt, etc.
#lp report.2?.txt
#cp -p report1?.txt archive

The brackets, "[]", represent one character within a range.
Print all documents in the current directory that contains report.1[any character in a range].txt eg. report.20.txt, report.21.txt, report.29.txt.

#lp report.2[0-9].txt
#cp -p report1[0-9].txt archive
#rm report1[0-9].txt

1 comment:

Giacomo said...

Unix Geeks Represent on Stanford Campus in "nerdcore 4 life" .