I have a bunch of aliases and shell functions defined in my ~/.bashrc
alias ll='ls -lh'
alias li='ls -lhi'
alias lll='ls -lhL'
alias l='ll'
complete -F _longopt l ll lll li # this doesn't actually work
psg(){ ps aux | grep ${*:-$USER} | grep -v grep; }
psgw(){ ps auxww | grep ${*:-$USER} | grep -v grep; }
# expand aliases for sudo
alias sudo='sudo '
alias imv='imv -i'
alias mv='mv -i'
alias cp='cp -i'
alias rm='rm -i'
alias prealloc-mv='rsync --remove-source-files --sparse --preallocate -aH'
alias m=less
export LESS=iMRj5
alias j='jobs -l'
alias dr='disown -r'
cmpll() { ll "$@"; cmp "$@" && echo identical; }
findll() { find "$@" -exec ls -dlh --color=auto {} +; }
findinamell() {
local i args=()
for i in "$@";do
args+=( '-iname' )
args+=( "*$i*" )
done
findll "${args[@]}";
}
As others have pointed out, ~/bin
is in your $PATH
by default, if it exists, so you can put things that are too big for an alias or shell function there. I actually have several really small scripts in my ~/bin
, IDK why I decided to make them files instead of aliases. Search for "COMMAND EXECUTION" in the bash man page for more details about how commands are interpreted. man bash
.
If I'm cooking up some commands that are only applicable to something I'm working on in a certain directory, I might well put the commands in a file there, and run it with ./do-stuff.sh. Your fingers will get used to typing ./
pretty quickly. You might also keep a text file of useful commands you've used, along with a description of what they do. I do this sometimes when I don't think it's worth the time to turn it into a function or script that takes parameters, but instead just paste it in and edit it as appropriate. e.g. for playing back audiobooks, I often use:
mpl() { t=2200; mplayer -ss $(($t * ($1%2))) -endpos $(($t+5)) disc$(printf '%02d' $((1 + $1/2)))-38.mp3; date; }; mpl 4
(this plays 2200 seconds of audio, starting at either the beginning ($1 odd), or 2200sec in, to one of many numbered tracks. Basically map a linear index into a set of audio files that are each two listening-chunks long.)
I can up-arrow and edit the very end of the command line with my monitor off, while I'm falling asleep. I use a shell function so the part I need to edit is right at the very end. Aliases only work if all the arguments can go right at the end of the fixed part of the command.
I'm sure there's a ton of good stuff out there if you google, but there's probably a ton of outdated and less-useful stuff too, and I don't want to take time to evaluate a guide right now.