In this video I go over 5 command line tips that I don’t think many know about that will increase your productivity. Specifically bash.
Like if you enjoyed the video, comment if you have any questions! Subscribe if you want to see more content like this.
Find me elsewhere:
Instagram: https://www.instagram.com/kamiyaa91/
Github: https://github.com/kamiyaa/
pushd/popd
You’re probably familiar with the cd command to change directories, and cd - to switch between 2 directories very quickly. Pushd/popd work very similar to that. It behaves similar to the back and forward feature in a web browser. Using pushd {destination}, we go to that path or destination. Using popd, we go back to our previous destination. This is really useful when you want to navigate around multiple different directories very quickly
Keyboard Shortcuts
Many of you probably know that bash has keyboard shortcuts. I’ll be honest though, many of them aren’t very useful. But there are 2 that I found to be very useful.
The first one is Ctrl+r (and Ctrl+s), which allows you to reverse search through your command history. I found this to be very useful when I need to ssh into a machine on a daily basis or scp the same file over and over.
The second one is Ctrl+u (and Ctrl+k), which clears all characters before the cursor. At first this might not sound very useful, but it can actually clear the input buffer for password prompt. Command line password prompts don’t show how many characters you’ve typed so when you mistype something, you have to hold down backspace until you think you’ve cleared everything. By using Ctrl+u, you save yourself the hassle of holding down backspace. A nice bonus is that this keyboard shortcut works in the browser as well. You can learn more about bash shortcuts here: https://www.ostechnix.com/list-useful-bash-keyboard-shortcuts/
stdout/stderr redirection
When a program is ran, the shell opens 2 files for the program to output to: stdout and stderr. stdout is usually where normal output goes and stderr is usually where errors go. This is really useful when you are debugging a command line tool. If you were to output to stdout, it would mess up the program’s UI. But if you were to redirect stdout to a file, the program’s UI would be gone. The solution to this is to output log messages or errors to stderr, then redirect stderr to a file so its outputs does not mess up the program’s UI.
Quotations
Unlike Python, single quotes ’ and double quotes " are different in the command line. Double quoted strings are parsed and evaluated whereas single quotes are not. So things like wildcards, variable expansion, command evaluation still work inside double quotes. This may not be what you want if you have files or urls with special characters in them. So use single quotes if you want to guarantee the shell does not do anything with the string.
The man command and its categories
The man command is a great tool to learn how a system works. It provides manuals on command, library functions, configuration files and many more. The most popular ones are category 1: commands and category 2/3: library functions. Another useful category is #5: Configuration files. It tells you exactly how a configuration file is formatted and where to place them. To specify the category you want simply add a number to the man command: man 3 printf
Music:
Imagine by lukrembo
Michikusa by PeriTune (Licensed under https://creativecommons.org/licenses/by/4.0/)
#productivity #command line #bash