0

I have a script "fd.sh"
./fd.sh $1 never fails
Below is the script:

/~ 2 07:53 AM :> cat fd.sh
#!/bin/bash echo -e '\n'

find . -maxdepth 3 -iname "$1.*" -type f -exec wc -c "{}" ;

My alias in bash_aliases is

fdx='find . -maxdepth 3 -iname "$1.*" -type f -exec wc -c "{}" '

When I run the alias looking for all files from my home directory with the string "WORK", I get the message below:

/~ 1 07:51 AM :> fdx WORK
find: paths must precede expression: WORK
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
/~ 1 07:51 AM :>

It appears to me the two commands are identical, but only the script works, meaning I have to copy the script to parent directory of the folder I am searching. Cannot search in / as that would take days. Leaving my little find scripts all over the servers would also make the admins very unhappy
THX.

1 Answers1

1

aliases only adds your parameters after the aliased command. If you want to insert the parameters somewhere inside the command, you can create a function.

Example that invokes wc with a number of files at a time:

fdx() { find . -maxdepth 3 -iname "$1.*" -type f -exec wc -c {} + ; }

If you prefer to invoke wc one time per found file:

fdx() { find . -maxdepth 3 -iname "$1.*" -type f -exec wc -c {} \; ; }
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108