Closed stottj closed 1 year ago
The is a wildcard which is designed to to take all files that end with whatever the was attached to. For example *.lua would mean take any file, no matter the name, that ended with .lua and perform an action with them.
The ? can represent any single character, a-z and 0-9. So if you did hd? it would like for hda, hdb, etc.
The [] specifies a range, so if you did d[a,i,u]d it would look for dad, did, dud. If you wanted range you would use the [-] reflecting start and stopping ranges for example d[a-d]d would would result in looking for dad, dbd, dcd, ddd.
The [!] is a logical NOT, it will match any character as long as it is not listed between the [ ]. For example rm filename[!9] will remove all files that do not have a 9 anywhere in the name (filename8, filename85, filename1 would all be removed).
the \ is used as an escape character to protect subsequent special character for example \ searches for a backslash.
One most becareful on how to use wildcards. If one was to use rm "*.txt" in a directory all text files would be removed. But maybe you have a lot of different type of files and would only want to see txt files. ls "*.txt" would be help weed out everything else. You could also be like me where you make your next save the first unused number. What if you wanted to move all your previous saves, which we'll say is 5, but didnt want to delete them? You could do a mv file[1-5].txt dir2. This would leave your latest file6 in the current location.
Ex 1 ls *.txt (will show all .txt files)
Ex 2 ls test?.txt (will show all files that have any character after test i.e. testA, testB, test1)
Ex 3 ls test[1-5].txt (will show all files that are named test1 through test5)
Ex 4 ls ?est[1-5].* (will show any file that has est with an ending of 1-5 i.e best5.whatever would show up.
Common issues are files not showing up if you use the wrong wild card or you placed the wildcard in a different area. .txt and chicken. are two major different searches. Also know that [ ] will have start/end points you put in so having generic info on what you are looking for is crucial.
👍🏻
Ticket: Utilize Wildcards in Commands
Summary
Learn how to utilize wildcards (
*,
?
,[...]
) in command-line commands for more flexible and efficient operations in a Unix-like operating system.Description
Objective: Understand the concept of wildcards in the command line and learn how to use them to perform various tasks more efficiently.
Scope:
*
,?
,[...]
)ls,
cp,
rm,
and moreLearning Tasks
Introduction to Wildcards:
*,
?
,[...]
).Using Wildcards in Commands:
ls,
cp,
mv,
andrm.
Best Practices:
Pitfalls to Avoid:
Hands-on Practice:
*
wildcard to list all.txt
files in a directory.?
to match single characters in file names.[...]
to list files that match specific character ranges.Troubleshooting:
Learning Goals
Priority