I've long used the find command for finding files and directories in the current directory and all subdirectories that match a pattern:
find . -name "*.txt" -print
find . -name "Bill*" -print
But what I'd really like is an alias or function that will properly pass the wildcard. (I used to be able to do this in csh, but now I'm using bash.) If an alias or function named "fn" were set properly, I could save some time by just typing:
fn "*.txt"
fn "Bill*"
Ideally, I'd like to lose the quotation marks too, but I'm guessing that might not be possible because the shell will expand them before calling "fn".
Any advice would be greatly appreciated and will postpone carpal tunnel syndrome.... :)
SOLVED: After the discussion below, I put this in my .bashrc file:
fn () {
find . -name "$1" -print
}
Note the quotes around the argument: "$1". This can then be called with more quotes around the filename expression:
fn "*.txt"
EDIT: must have spaces between the function name and the parentheses, so fn () { ... [works] fn() { ... [doesn't work]
The Bash find Command 101 The find command allows you to define those criteria to narrow down the exact file(s) you'd like to find. The find command finds or searches also for symbolic links (symlink). A symbolic link is a Linux shortcut file that points to another file or a folder on your computer.
A wildcard is a character that can be used as a substitute for any of a class of characters in a search, thereby greatly increasing the flexibility and efficiency of searches. Wildcards are commonly used in shell commands in Linux and other Unix-like operating systems.
find ./ -name "*pbs.e*" -type f -size +10c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With