Viewed 30k times. Improve this question. Gilles 'SO- stop being evil' k gold badges silver badges bronze badges. Adrian Petrescu Adrian Petrescu 1, 1 1 gold badge 9 9 silver badges 10 10 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. This is something very useful to add to my bag of tricks.
I think I'll alias which to type : — Adrian Petrescu. To answer my question, type works on zsh too on Debian. Why don't the distributions get rid of what and which if they aren't standardized and don't have extra functionality?
Nope, not even remotely. Faheem: re documentation, I'd start with info bash 'Bash builtins' on Linux, although you can also get it form the zsh reference manual. More officially, pubs. Show 15 more comments. Mikel Mikel Last one is cool. We can have an alias to do this. In bash on redhat I have to use type -P, and not which, if i want the correct answer. No aliases or functions are concerned. Dr Eval, which "which"? Which Red Hat? More about me. Recommended reading 7 Linux commands to use just for fun.
How I build command-line apps in JavaScript. Use the Linux cowsay command for a colorful holiday greeting. How I dynamically generate Jekyll config files.
How to kill a zombie process on Linux. Marco Bravo on 31 Jul Permalink. Great article. Thanks for this recap. Seth Kenlon on 31 Jul Permalink. As always, thanks for reading and commenting, Marco! Stanowczo on 31 Jul Permalink. Marcin Pohl on 31 Jul Permalink. Great points, thanks. I'm surprised at myself for not double-quoting my variables! Greg Pittman on 31 Jul Permalink. ACG on 31 Jul Permalink. It goes something like! That's pretty slick! I like it.
ACG on 01 Aug Permalink. Seth Kenlon on 02 Aug Permalink. Michael Davies on 05 Aug Permalink. Seth Kenlon on 06 Aug Permalink.
Thanks for catching that. I've corrected it in the article. Greg Bell on 11 Aug Permalink. Seth Kenlon on 12 Aug Permalink. I love this! I might try it and see if I can make it a thing for myself. Another way is to just use an absolute path to the command.
Zied on 13 Aug Permalink. Seth Kenlon on 13 Aug Permalink. Nice, thanks! For instance, a lot of people don't like the name of the grep command, and wish they could change it to search. With the alias command you can do exactly that:. Now you can just type search instead of grep at your Linux command line:. In another simple alias example, instead of always typing this ls command to get a directory listing:. Whenever I use this alias, it's exactly the same as if I had typed out the longer ls -al Linux command.
Each alias consists of one word or even one letter that you can use instead of a longer command line. For example, you may find yourself using the command ls -F a lot. You can easily make a shortcut for that command: lf , for example. So when you use lf where the shell expects a command, then the shell will substitute ls -F. The alias command with no arguments displays all your current aliases.
The first item on each line is the alias which must always be a single string, with no spaces , and the rest of the line is the full command for which the alias is a shortcut. Figure 7. You can see that the alias l is a shortcut for the command ls -lg. The first word on each line is the name of the alias; the rest of the line is what gets executed when the alias is used. Several of the aliases are more complicated. The aliases in Figure 7. For example, the alias in Figure 7.
Shown are the default aliases for the tcsh shell. If you want an alias to always be available, you must put it in a con-figuration file. This will create an alias called lf , which the shell will translate into ls -F whenever you use lf as a command.
Make sure to enclose the last argument in quotes, either single or double, so that everything after the alias name is treated as a single entity. If you want to have an alias use arguments from the command line inside the alias definition, you can use!
But you must escape the! The shell shows all your current aliases, including the one you just created. As with the tcsh shell, bash aliases created at the command line will disappear when you exit the shell. Unlike aliases in the tcsh shell, aliases in bash cannot have command-line arguments included in them. However, bash allows you to create shell functions, which can make use of their arguments. The term shell function applies to series of shell command lines. The entire function you will be entering is shown in Figure 7.
This sample function looks up a word in two different files that make up a dictionary. Enter the first line of the new function. In this example you are creating a function called " word ":. The parentheses tell bash that this is a function definition. Double-check that what you entered looks like Figure 7.
0コメント