I want to create an alias for this command开发者_JS百科 "rmi" so that if I execute
rmi File.txt
it will actually execute
ls * | grep -v File.txt | xargs rm -rf
Basically I want to reorder arguments.
Script:
#!/usr/bin/env bash
ls * | grep -v $1 | xargs rm -rf
-Save this as rmi.
-do: chmod a+x rmi
-Then add to path.
You can't do that with an alias. You'll need to write a script.
You don't need a script. Instead of alias, you can write a shell function:
myfunc() {
ls * | grep -v $1 | xargs rm -rf
}
# usage: myfunc <filename>
store it in ~/.bashrc or ~/.zshrc, or a separate aliases file, eg. using the idiom
test -f ~/.zaliases && source ~/.zaliases
in your dotrc file.
thanks for clarifying this. In tcsh it's easy:
alias rmi 'ls * | grep -v \! | xargs rm -rf'
this should do it...
\!
expands all arguments following "rmi"
you could also use "find" to do this..
find . -type f | grep -v \! | xargs rm -rf'
... be careful with that axe! (rm -rf)
精彩评论