However when I set up the following alias in .bash_aliases:
alias lf="ls -l | grep ^- | awk '{print $NF}'"
it only partially works. I get just the files listed but the -l longlisting too (permissions, owner, size, date, filename) and not just the filename on its own.
I'm guessing this is to do with the " and ' formatting but I can't seem to format it correctly. All the variations I've tried either fail with an awk error because the 'print' section isn't right, or do the same thing as already stated.
However I've descovered a problem with my original command. It does not work with filenames with spaces in them. Printing everything after the final space only.
However one thing I didn't mention before is that I was doing a second ls alias called lfq which added the ls switch -Q to wrap "" around the filenames so that files with spaces would be conveniently enclosed in "".
My attempts to modify your function to achieve this have failed dismally. Can it be done, if so, how?
I also like functions, but they can cause clutter and complexity. One way to address that is to use an autoload-like facility. Such a feature allows the functions to be placed in a separate directory, say ~/.functions, one function (or group of related functions) to a file. I think these ideas were first found in ksh.
Regrettably, autoload is not built into bash. However, you may have access to a set of functions that perform that task. In my main workstation system (Debian 5, lenny), these functions are in:
/usr/share/doc/bash/examples/functions
in the filenames containing the string autoload.
I have used them with (most recently) GNU bash 3.2.39 and they seem to work correctly.
So whenever you create a new function, or you find something interesting on the 'net, you can just drop the file in .functions, and you'll be set.
Looking briefly over my examples, the functions in .functions can be made to work with ksh (and probably zsh, but I have not tried that), assuming no bashisms are present.