This is because time
is a bash builtin command - and the builtin doesn't support the options you're trying to use.
Try this, use the full path of time to skip the built-in and use the real one:
/usr/bin/time -f "%E" ls -l
Your bash alias is not well written (the single quotes are not well used). Instead it should be:
alias rm~='find . -name "*~" -print0 | xargs -0 /bin/rm -f'
Now, I personally don't like useless uses of pipes and xargs
, so your alias would be better written as:
alias rm~='find . -name "*~" -type f -exec /bin/rm -fv -- {} +'
The -type f
option so as to find only files (not directories, links, etc.), the -v
option to rm
so as to be verbose (prints out what it's deleting). The +
at the end so that find
runs rm
with all the found files (spawns only one instance of rm
, instead of one per file).
Now from man bash
:
For almost every purpose, aliases are superseded by shell functions.
Instead of an alias, it's better to use a function: comment your alias in the .bash_aliases
file (i.e., put a #
in front of that line), and in the file .bashrc
, put this function (anywhere in the file, at the end is fine):
rm~() {
find . -name "*~" -type f -exec /bin/rm -fv -- {} +
}
Also, as the other answer mentions, you can use the -delete
command to find. In this case, your rm~
function will be:
rm~() {
find . -name "*~" -type f -printf "Removing file %p\n" -delete
}
In fact, you can make a cool function that will take an argument, say --dry-run
, that will only output what it will delete:
rm~() {
case "$1" in
"--dry-run")
find . -name "*~" -type f -printf "[dry-run] Removing file %p\n"
;;
"")
find . -name "*~" -type f -printf "Removing file %p\n" -delete
;;
*)
echo "Unsupported option \`$1'. Did you mean --dry-run?"
;;
esac
}
Then use as:
rm~ --dry-run
to only show the files that will be deleted (but not delete them) and then
rm~
when you're happy with this.
Adapt and extend to your needs!
Note. You'll have to open a new terminal for the changes to take effect.
Best Answer
Well, even if you don't like it, I will put you to read again with more attention
man time
. At the end ofEXAMPLES
section you will find:So, I'm assuming that you use bash shell which uses an internal version of
time
, provided as a shell keyword. You can check this using the following command:and the output will probably be:
If this is the case, then is clear, to use the real
time
command, you must to use its explicit path:/usr/bin/time
.Further, if you don't want to use anymore the shell keyword
time
, you can create a permanent alias as follow:This will overwrite the shell keyword
time
because the command:will give the following output now: