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]
fn() { find . -name "$1" -print; }
fn "*.c"
, for example. You can't avoid quoting the wildcard expression in the invocation offn
.fn() { find . -iname "*$1*" -print}
I can just typefn word
and I find all files with word, Word, WORD, WoRd or similar anywhere in the filename. That's what I was after, maybe you were after something different.