![]() |
|
Aliases: DIY Shell Commands - Printable Version +- Sick Gaming (https://sickgaming.net) +-- Forum: Computers (https://sickgaming.net/forum-86.html) +--- Forum: Linux, BSD & Unix (https://sickgaming.net/forum-88.html) +--- Thread: Aliases: DIY Shell Commands (/thread-87729.html) |
Aliases: DIY Shell Commands - xSicKxBot - 12-12-2018 Aliases: DIY Shell Commands Aliases, in the context of the Linux shell, are commands you build yourself by packing them with combinations of other instructions that are too long or too hard to remember. You create an alias by using the word Code: aliasCode: =Code: lsCode: alias lc='ls --color=auto'where Code: lcCode: lcCode: =Code: lcCode: lsCode: --colorAfter defining your alias, every time you type Code: lcBut, you may think, “my Code: lsAliases you (probably) already have Indeed, you can use the Code: alias
There may be more (or less, or even none), but regardless of what your distribution comes with, you can always use the base form (vs. the aliased form) of a command with the Code: \Code: \freewill execute Code: freeCode: -mCode: \lswill execute Code: lsCode: --color=autoIf you want to get rid or modify the preset aliases forever, note that they live in the global .bashrc file which hangs out in our old haunt, the /etc/skel directory. Aliases for muscle memory Distro designers try their best to predict which aliases are going to be useful for you. But every user is different and comes from a different background. If you are new to GNU+Linux, it may be because you are coming from another system, and the basic commands vary from shell to shell. If you come from a Windows/MS-DOS background, you may want to define an alias like Code: alias dir='ls'to list files or directories. Likewise, Code: alias copy='cp'
alias move='mv'may also come in handy, at least until you get used to Linux’s new lexicon. The other problem occurs when mistakes become ingrained in your muscle memory, so you always mistype some words the same way. I, for instance, have great difficulty typing admnis-… adminsi-… A-D-M-I-N-I-S-T-R-A-T-I-ON (phew!) at speed. That is why some users create aliases like Code: alias sl='ls'and Code: alias gerp='echo "You did it *again*!"; grep'Although we haven’t formally introduced Code: grepAnother thing to note in the Code: gerpCode: echo "You did it *again*!"Code: ;Code: grepUsing Code: gerpCode: $ gerp -R alias /etc/skel/.bashrc
You did it *again*! alias ls='ls --color=auto' alias grep='grep --colour=auto' alias egrep='egrep --colour=auto' alias fgrep='fgrep --colour=auto' alias cp="cp -i"
alias df='df -h'
alias free='free -m'
alias np='nano -w PKGBUILD' alias more=less shopt -s expand_aliasesRunning commands sequentially as part of an alias, or, even better, chaining commands so that one command can use the results coughed up by another, is getting us perilously close to Bash scripting. This has been in the making of this series for quite some time, and we’ll start covering it in the very next article. For the time being, if you want to get rid of an alias you temporarily set up in a running terminal, use the Code: unaliasCode: unalias gerpIf you want to make your aliases permanent, you can drop them into the .bashrc file you have in your home directory. This is the same thing we did with custom environment variables in last week’s article. See you next time! |