Bash aliases are great ways to increase productivity by bundling commands behind a single alias. What are your favorites? Share in the comments!
For further actions, you may consider blocking this person and/or reporting abuse
Bash aliases are great ways to increase productivity by bundling commands behind a single alias. What are your favorites? Share in the comments!
For further actions, you may consider blocking this person and/or reporting abuse
Manthan Bhatt -
Tung Leo -
Debajyati Dey -
Divya A -
Top comments (45)
Oh no I don't have favorites, but if I did it would be these.
Now on the subject of functions I recently added these two.
That duckduckgo has
?
as an alias, so I can search from the terminal like this.If anyone is curious I have those things in my dotfile repo.
I really love the duckduckgo one
I'm curious how you set up the
?
as an alias for theduckduckgo
?I couldn't get it working when I tried and can't find that from your dotfiles either. I'm pretty new with these aliases.
I believe this is what you are looking for.
It's not on the dotfiles because I don't know if I'm going to keep it.
Thanks! I did not have the single quotes on the
?
, TIL :)You're welcome.
This also seems to work.
Nice! I literally spend all my time in my shell and am not sure why I hadn’t thought of this or employ Alfred (macOS). May try this and see if it sticks
I am stealing the duckduckgo one 🔥
Thanks
I've noted down all the aliases I use here: link
My favorite ones are:
really like 'lazygit' I may steal that one :)
Sure :D
One alias that I use many many times every day:
‘’’
alias cdtemp='cd $(mktemp -d)'
‘’’
It creates a new temporary directory and switch to that directory.
interesting! is that just for experimenting with files you might not keep? I'm always curious how others use filesystems, I make a lot of temp files but don't ever make a temp directory to put them in!
I don't either, but it's a cool idea because you can create a bunch of files for something and delete them all when you're done just by deleting the directory they're in. Also makes it so you don't have to worry about file name collisions between tasks.
Yes thats exactly how I use this alias. Another benefit is that in most of linux distros the ‘/tmp’ directory is cleared upon each reboot.
Whaaaaat I did not know this.
I pretty much skip aliases and only make functions most of the time. I do have exceptions, but for the most part I have a "master" .bash_funcs config that I use on most of my machines that I have been building/editing/refactoring for MANY years that has all my favorite stuff in it.
Even for non-args stuff.
It's really hard to pick; so much of it saves time or keystrokes and I find most of them essential.
If you consider small one liner or simple functions as aliases then a few I love are:
Alternate touch
Use null to zero/create a file.
Get cursor coordinates with xdotool
Use realpath with Fuzzy Finder to get the a full path (alternate method)
I have a much smaller alias file (< 10 old aliases that plan to functionize at some point lol)
Always force make parent directories if they don't exist
'ls' with no color for various reasons
I usually either have 'ls' aliased to default list with colors (I think it's preset in some envs) and this overrides it when I need output without color
And one for fun :D Show time in the console but in alternating colors.
I have plans to rewrite this using '\r' instead of clear
I have so many functions I love I could just keep going, but my main function file is around 8500 lines so I won't do that to you lol.
Do you have these functions in a public repository? I'd love to check them out.
I've a handful of functions that I rarely use anymore like one that took an argument like
docs mdn
that would open my browser to Mozilla's documentation anddocs til
that would open my TIL (today I learned) repository on GitHub with rendered markdown.I've only a handful of aliases as well allowing me to jump around (change dirs) into personal or work, and my dotfiles along with a couple more just masking other commands, like
alias vim=nvim
since I use Neovim andalias make=mmake
(Modern Make)I keep a long history and much prefer using
reverse-i-search
to dig up a command that I use somewhat frequentlyI do actually plan on a Shell section on my main misc programming GitHub IO site that has lots of it organized, but it's still "under construction" lol. In the next couple of days I'll make a copy and clean lots of crap and redundancy out of it and put it up in a temp repo and post it back here.
I use history/fzf, but I have extra laptops that I'm always testing distros on and so I always just import my dots, but yeah I'm constantly doing Ctrl+r; FZF is just amazing.
Don’t have to mention fzf twice. It’s a must have both in my shell and Vim coupled with ripgrep. Ah! You’re a distro junkie! Haven’t settled on Arch or Gentoo?
I try anything out, but stick to Debian based. Ubuntu on main/family member machines usually. I do have a soft spot for Bodhi with Enlightenment.
I'd do
:> foo
to do this (well, I use:>| foo
because I havenoclobber
set, but...)As for needing to output
ls
without colour, I thinkcolor=auto
works for most colour-aware commands in that you get colours, but they're suppressed if the output's to a pipe. That should cover most cases?The reason why I originally created that alias is because at some point, for whatever glitched reason, I couldn't force colors off and that was the only way I could force it off. Don't remember exactly what it was; it's been a few years and my memory has been slipping lately.
I think that my 2 favortites and the 2 I use more are, no doubt:
Wait, what is that first one foist?
I didn't know what it was doing until you asked. I've had it copy/pasted around my dot-files many times. I've just realized now that it does not work on BASH, only on ZSH, sorry :(
EDIT: I mean... I know I always use
e
to open my editor. What I didn't know was why was I using such a complex alias to do it.TL;DR:
It uses
$VISUAL
or$EDITOR
and makes sure that it properly handles any extra parameter given to it. So somehting linevim -a -b -c
works.Detailed explanation
Got it from here github.com/sorin-ionescu/prezto/bl...
What it does If I'm not mistaken is to alias
e
to either the value of$VISUAL
or$EDITOR
. But to only do that it would be enough with:There's also this
(z)
that I just learned on ZSH is an expansion flag. Looking into ZSH manual it says:but I still didn't know what it means... so I tried to do:
If I then I've tried
That doesn't happen if I try with
(z)
flag on the expansionalias e='${(z)VISUAL:-${(z)EDITOR}}'
.PS: Thanks a lot for making me look it up :)
Please write this up into an article or I will, it’s great! And since OS X switched from Bash to zsh I Can actually use it!
Done! dev.to/nflamel/til-how-my-complica...
I'll try to see if I have more things like that around my dot-files to see which ones are worthy of some more articles.
I use this function to quickly (shallow) clone a github repo and open it with my favorite editor.
Not really a bash alias, but
is quite useful :D
oh, also this one
One of my favorite aliases is to get a quick answer from StackOverflow
using
howdoi
packageThe cross-platform solution to open current directory form terminal
more of my settings can be found here: github.com/victory-sokolov/dotfiles
If you like
howdoi
, check outtldr
. It works likeman
, but only shows usage examples. It's in the regular Ubuntu repos.Definitely going to use this.
I like to make my
~/.bash_profile
able to be re-sourced multiple times. Because I'll change it, and then re-source it. But I don't want my PATH to become super long with duplicates. So I check PATH before appending or prepending a path.I use SCOWL to look up words frequently. So I like to be able to grep words no matter where I am.
I'm often on a Macintosh using Terminal.app, and I like to be able to clear the screen and clear the scrollback buffer in one command.
I'm always making little C++ toy programs to test out a thought. I like to compile in a specific way, so a handy alias to the rescue.
I often want to go up directory levels or to HOME quickly.
When I do
mkdir
I often follow it withcd
to that directory. So I've combined the operations. (Sometime I tweak it to be lazy and cd into the directory if it already exists. Sometimes I don't like that behavior, and take it out.)Sometimes I'm editing an HTML file (and possibly associated CSS and JavaScript files), and I want Chrome to reload my local page for me when it changes. (I think I got fswatch through brew.)
I'm always a fan of:
That is, rerun the last typed command, but prepend it with 'sudo' this time.
The usuals:
A shortcut:
c
to be able to quickly jump to any of my local project directories inside my~/Code
directory.Fish shell function:
Full source (including tab completion) installable using Fisher.
Also,
vpn
to connect to or disconnect from corporate (Cisco AnyConnect) VPN (source).So my favorite is a git alias. When I have PR request open and I get comments on it and need to address them and then commit and rebase them.
The need for rebasing the last commit is to squash the
fixing comments
commit into the one that the PR is actually for, ie.Add some feature
I do this all the time and with git when you rebase it opens up your text editor so you can edit the commits you are rebasing to tell git whether you want to squash, drop, edit the commit messages.
I found it annoying that you have to manually type go down and change
pick
tos
every time I had to address PR comments. So I found a Stack Overflow answer and turned that into this alias.This improved my life a lot. Try it for yourself if you want and if anything gets messed up remember
git reflog
andgit reset HEAD@{#}
are your friends...
iscd ..
e
is$EDITOR
(gvim on Linux, mvim on Mac)e.
ise .
to open $EDITOR on the current folderg
is git and I use git aliasesci
co
pus
pul
for sub-commandsdk
is docker anddc
is docker-composeAnd we have a rich
bin
folder on each project with specific scripts likebin/qa_deploy_branch
etcHere are a few of mine:
Make log times human readable
Remove editor backup files
And a couple of functions (in ~/.bashrc)
Change to my ~/bin directory
Quick calculation
I have several aliases that just cd to directories I use a lot.
I have a simple activity log program I wrote in bash that writes to a text file. It has eleven aliases to invoke its features and to create entries for my most common activities that I can just tack details on the end of.