101 Bash Commands and Tips for Beginners to Experts

Andrew on January 13, 2019

Update 8 July 2019: I recently found this very similar article posted to a French-language message board about two years ago. If you're interested... [Read Full]
markdown guide

My Markdown editor started choking near the end of writing this. RIP Simplenote.


this is an awesome post but I've no idea how could anyone use a shell that looks like a pipe operator all the time ... some command with pipe reads very badly, why not removing all the starting parts of your snippets, adding a classic $ like any other shell, instead of 17:40 | andrew@pc01 ~ | ?


Fabulous readable reference, thanks Andrew!

Minor niggle - almost all of these are not bash commands, but command line tools that work the same from any shell - it would be nice to know what are bash built-ins that might go pop in another shell, and what aren't :)

Long-running advanced voodoo:

  • disown (bash built-in): disconnects background processes from your terminal such that they stay running after you log off.
  • screen (cli tool): opens a new terminal (tty/pty), such that anything you run in that terminal stays running when you disconnect from it / log off. You can also reconnect (screen -r) when you log back in.

I prefer screen over using disown, because of the reconnection ability.


I'd like to add tmux to this list of helpful tools. Does similar thing as screen.


Thanks, Phil! I'll have to do some more research.

Watch out for the "unabridged" version of this in the future.


Yes, I was missing those on the SSH section, @andrew really awesome post


FWIW, most of these aren't actually bash commands (only the builtins are); they're Unix/Posix/whatever commands.
Also, the prompt you use confuses me: it looks like there's an extra command (such as the ex command) at the start of the pipeline.


Cool article but there are few things I need to disagree.

Environment variable creation

Using format foo=bar stores environment variable only current command. To keep environment variable loaded in your running bash process you need to export it with export foo=bar. This behaviour can be checked with commands env, printenv or by echoing environment variable.

source vs sh

Results of source and sh commands might look identical but they are not. Source command executes script in running bash and all exported envirenment variables are part of the running bash shell. sh invokes a new shell and exported variables are not usable in the calling shell. Also working directory of calling bash shell might be changed when using source command.

Please note that sh usually is linked to posh or some other lightweight shell which does not have all bash features.


More about source

In some systems source and . are interchangeable command. (POSIX compatibility is swamp)

Anyway source command is good if you need (temporary) setup your environment: e.g. load environment variables, aliases and even request passwords from user with read -s <variable_name> or to load functions from external libraries.

Usually source is used in scripts(1) but I'm sure that users can find use cases when to use source to setup environment for running shell.


Great list!! I would have added "type" and "tmux" to the list :)

For folks interested in useful Unix tricks, Unix Power Tools book is a great source.


Impressive post! I remember when I found ncdu it was an amazing day. It's by far my favorite tool to find what's taking up my disk space! I really hope more people use it as a result of your excellent post!


ncdu is great, it's what du should have been. Writing this post, I found a few other commands and flags that I forgot about / never learned about. One of my favourite ones is the -p flag to mkdir, which will create all missing intermediate directories! Small things like that can save you lots of time.


Great reference, I would suggest changing the format of your prompt. Having the | symbol dividing the time and username is confusing on first look.


Good post! Do not run kill -9, but rather use just plain kill, or kill -15 if that doesn't work.
Kill and kill -15 end a process somewhat gracefully, so that the os is at least notified that the process is killed. -9 just causes it to vanish with no notice. It's akin to just hitting the power button, on a process level, without doing any sort of shutdown routine.
Also, ag (Silversurfer) is my team's grep replacement, give it a look.


rm -rf is commonly referred to as "rimraf" or "rimraf-ing".

Looking back it seems intutuitive but I didn't make that connection for the longest time.

Great article :)


I think it's really awesome that you tought of the reader and added a "Back to TOC" after each topic for easy navigation!
And of course the content is very well explained with just enough words but much information in it :)


Thank you for your impressive post!
And for mac users: If you want to use the very convenient ncdu command, there's a version available for Homebrew:

brew install ncdu


Great post!

BTW, A similarly "for beginners" tutorial that I enjoyed, in book form, is M.G. Venkateshmurthy's "Introduction to Unix and Shell Programming," if anyone is still looking for additional material. (It gives fun "why" context to all of its "how" -- for example, it points out that the commands/flags of command-line interfaces are short and hard to remember because back when the only way to interact with your computer was a command line interface and only specialists used computers, the last thing programmers wanted to do was type a lot, so they just made up a bunch of cryptic short commands.)


Thanks for the firehouse, but an excellent article for newbies or those, like me, who are a little rusty.


Bonus tip for date command: date +%s prints unix time (in seconds)


Very useful article. Thanks Andrew for this article.


the picture associated with the xdg-open command appears to be from a Windows machine! how would it be possible?


Hi Amr,

Because I'm sshing into an Ubuntu machine from Windows using MobaXTerm. xdg-open (at least in this case) is using the default window styling from Windows.


This is so good. I can use many of these.
Thanks for sharing!!


Good article. Should have mentioned ipython and trash-cli though. (Also probably in most contexts, for the Python 3 version to run, one has to enter in "python3", "ipython3", "pip3" etc.)


Hi everyone!

Thanks for the amazing response to this article! I've updated the command prompt so it's a bit less confusing. I hope to post an updated / revised / expanded version of this in the future, where I'll take everyone's suggestions below into consideration.

Thanks again!


Really remarkable article!

But it seems that top uses the capital -U for the username. At least on Mac OS and FreeBSD.


Thank you, Andrew.

A great article written at the perfect time (I started using Ubuntu recently) ๐Ÿ‘


A great resource, thanks.

If the file you're looking for is not found with locate, you can run updatedb to update the list of files for locate.


I will use this, thanks! Now, if posts a similar article for PowerShell, I'll be done. lol


Awesome stuff Andrew! Funnily enough I missed the title (and the URL ...) and was pleasantly suprised by how many different commands you listed. Nice work


Great. But that Pipe operator as prompt in the command snippet seems very confusing.


Exactly what I need right now...

Actually, more than I need, but in the best way, haha. Thx! ๐Ÿ˜„


Sweet Jesus, this is awesome!
I took note of some of these, can't wait to show off in front of my peeps back at the office.


This is an awesome list - but it should be noted that most of these are not bash commands. They are just common programs. Many of them are therefore usable in any shell, not just bash.

code of conduct - report abuse