I am starting this thread with the goal of gathering all the useful shell tips in a single place. We have a very diverse crowd here, and it would be really great to have some knowledge trickle from the shell ninjas to people who’re only starting their shell journey.
Below is the set of tips that I have originally prepared for the DevCamp 7 in summer 2020, specifically for the Bash shell (which I use).
Please feel free to post here tips for the shell of your preference, and don’t forget to say which shell this is!
Performs reverse search in bash history that is stored at
~/.bash_history . Reverse search means that it will be performed from the latest commands going back in time.
Press it and start typing part of command that you’ve already used before. Once the command appears in the line, you can press Enter to execute it.
For example, instead of typing
nix-shell https://holochain.love every time you want to launch Holochain shell (after doing it for the first time), you can just do Ctrl + R and then type
.love : chances are, your bash history only contains a single command with this substring.
Clears the currently displayed shell screen. Use it instead of typing Enter several times to visually separate your next command from previous ones.
Most shells implement the autocomplete that is triggered by pressing Tab button. Use it to avoid typing the entire thing you wanted to type.
Things autocomplete works for:
- shell commands
- contents of the directory you’re in
For example, if I want to run command
cat on a file
really-unnecessary-long-filename.txt that is located in the same directory I’m running my shell in, I can do the following:
cat(using autocomplete on a short command like that usually gives more options to choose from than needed, so I prefer typing it manually)
- continue typing start of the filename:
cat rand then press Tab
- either autocomplete will instantly complete the entire filename or I’ll get suggestions on all contents of the current directory whose name starts with
- if there are multiple suggestions, I need to type few more letters so that there’s only a single option
You can use curly braces to mention multiple things in the same command and avoid running this command multiple times.
For example, if I want to create empty files
validation.rs in the directory
course/ I can do it like this: