Guide · Open source
How to use Bash-Oneliner: shortcuts, history tricks and recipes
Updated · written with AI from the project's own documentation and checked against our catalogue data
Bash-Oneliner is a free, MIT-licensed collection of short Bash commands and terminal tricks, grouped by topic such as grep, sed, awk, xargs, variables and system maintenance. It is a notes-style reference rather than a program you install. This guide shows how to get a copy, how to read its entries, and which parts are most useful for everyday shell work.
Quick start
- 1Clone the repository. Run git clone on the GitHub repository to get a local copy of the notes. Open the README and the topic sections from there.
- 2Practise the Ctrl shortcuts. Spend a few minutes using Ctrl + a, Ctrl + e, Ctrl + r and Ctrl + u at your prompt until they feel natural.
- 3Try history expansion. Run !! and sudo !! on a harmless command, then try caret substitution to change one word in the last command.
- 4Test globbing on a safe folder. Use ls with *, ?, [] and {} patterns in a folder you can afford to lose track of, and confirm what matches before using them elsewhere.
- 5Check variable behaviour. Set a variable, then compare echo with double quotes, single quotes and ${#var} to see how each one expands.
- 6Adapt a recipe carefully. Copy a recipe from the topic you need, read it, and run it on a test system first, since the commands may not work on your distribution.
Get a copy of Bash-Oneliner
The project is read online, and the README gives one way to get a local copy: clone the repository with git. The source lists no other prerequisites, so you only need git and a Bash shell to follow along.
The project homepage is also available at http://onceupon.github.io/Bash-Oneliner/ if you prefer to browse in a browser.
git clone https://github.com/onceupon/Bash-OnelinerLearn the Ctrl and Esc shortcuts first
The Terminal Tricks section is the best place to start. It lists keyboard shortcuts for moving and editing the command line, such as jumping to the start or end of a line and searching history.
Start with a small set you will use daily, then add more as you need them. Ctrl + r for reverse history search and Ctrl + u followed by Ctrl + y for cut and paste are common examples from the list.
- Ctrl + a moves to the beginning of the line; Ctrl + e moves to the end.
- Ctrl + r begins a backward search through command history; keep pressing it to go further back.
- Ctrl + u cuts the line before the cursor, and Ctrl + y pastes it back.
- Ctrl + z stops the current process; use fg or bg to resume it in the foreground or background.
- Ctrl + x then Ctrl + e opens your $EDITOR so you can write a multi-line command.
Reuse history with !! and caret substitution
Bash lets you rerun earlier commands without retyping them. !! repeats the previous command, and sudo !! reruns it with sudo, which is handy after a permission error.
Caret substitution changes one part of the last command. The source notes that only the first match is replaced, and that ^:& or !!:gs/old/new/ replaces every match.
!!
sudo !!
^aaa^bbb
^aaa^bbb^:&Use globbing and brace patterns to match filenames
Globbing lets the shell expand patterns into filenames before a command runs. The source covers four forms: * for any run of characters, ? for a single character, [] for a range, and {} for alternatives.
Check a pattern with ls before using it with rm or mv, because the shell expands it first and you will see exactly which files match.
- * matches any run of characters, e.g. /etc/pa*wd matches /etc/passwd.
- ? matches one character, e.g. /b?n/?at matches /bin/cat.
- [a-z] matches one character from a range.
- {sh,py} matches alternatives, e.g. ls *.{sh,py} lists .sh and .py files.
ls *.{sh,py}Read Bash variables and special parameters
The Variable section explains how quoting changes expansion. Double quotes still expand variables, while single quotes stop expansion, so echo '$foo' prints the literal text.
The section also lists special parameters such as $? for the exit status of the last foreground command, and environment variables such as $PATH, $PWD and $USER. The string recipes show how to get a length with ${#var} and a substring with ${var:2}.
- $? holds the exit status of the most recent foreground pipeline.
- $$ is the PID of the current shell; $! is the PID of the most recent background command.
- $PATH lists the directories searched for programs.
- ${#var} returns the length of a variable.
foo=bar
echo $foo
echo "$foo"
echo '$foo'
var="some string"
echo ${#var}Explore recipes for text processing and system tasks
Beyond the shortcuts, the file is organised into topic sections such as Grep, Sed, Awk, Xargs, Find, Time, System, Hardware, Networking and Data Wrangling. These contain short recipes you can copy into a terminal and adapt.
Terminal multiplexers are also covered. The tmux and screen entries list commands for creating, attaching, detaching and killing sessions. Test any recipe on a non-critical machine first, because the author says commands may not work on every system.
- tmux: create and detach sessions, then reattach with tmux attach -t foo.
- screen: create a named session with screen -S test, detach with ^a^d, reattach with screen -r.
tmux new -s foo -d
tmux attach -t foo
tmux ls
tmux kill-session -t fooWhat people use it for
- Recalling a shell shortcut or history trick while working at the prompt.
- Learning how Bash globbing and variable expansion behave before writing scripts.
- Finding a short text-processing recipe with grep, sed, awk or xargs.
- Looking up tmux or screen commands for managing terminal sessions.
- Reviewing Linux certification topics such as variables and shell basics.
Frequently asked questions
Is Bash-Oneliner free to use?
Yes. The repository is licensed under MIT, which the project lists in its details. The source does not mention any paid tier.
How do I install Bash-Oneliner?
The project is read online rather than installed. The README's only command is git clone https://github.com/onceupon/Bash-Oneliner, which makes a local copy of the notes.
What do I need to use Bash-Oneliner?
The source lists no prerequisites. You need a Bash shell to try the commands, and the author says the examples target Linux and macOS, so Windows users need a Bash environment first.
Do the commands work on every system?
No. The author says they mainly used Ubuntu, Amazon Linux, RedHat, Linux Mint, Mac and CentOS, and that commands may not work on your system. Test them before relying on them.
Is Bash-Oneliner good for learning Bash?
It suits quick reminders and beginners who want to see short examples of variables, globbing and history expansion. It is not a full course, and the author notes that most commands lack detailed citations or explanations.
How does it compare to tldr-pages or explainshell?
Bash-Oneliner is a personal notes collection organised by topic. The source lists tldr-pages, explainshell, awesome-shell and bashhub as comparable projects, but it does not say how they differ in detail, so check each one for the features you need.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Bash-Oneliner suits Linux and macOS users who want quick reminders of shell shortcuts, history tricks and short recipes, and beginners who like seeing small examples. Skip it if you need detailed explanations, cited sources, Windows support without a Bash environment, or scripts tested for production use.
Install options & downloads