Shell tricks will make you more productive. Look into pathname expansions such as tilde, dot and double dots. Learn about command line completion and command history.
- [Narrator] It helps to know some tips and tricks when using the Linux shell. Let's talk about some pathname shortcut locations, or pathname expansions. To verify where we are in the file system, type in pwd into a terminal. This shows that we're in our home directory. Now type in cd .. and type in pwd again to verify. Typing in cd .. takes us to our parent directory which is one higher in the directory tree than where we were. Another shortcut is cd . Type in cd . and hit Enter.
Now type in pwd to verify, and we can see that we are in the same location. The single dot is a shortcut to our current directory. The dot isn't very useful for the cd command, but often we want to copy files to our current directory. Instead of typing in the whole path, we could just use dot. Now type in cd ~ and hit Enter, and then type in pwd to verify our path. The tilde takes us to our home directory. Now type in cd - and hit Enter. We don't have to type pwd after cd - as it tells us where we are.
Type in cd - again, and you can see that it takes us back to our home directory. cd - just takes you to the previous directory or the last one you were in. Using pathname expansion can be a great time-saver for Linux users. If you want to clear the screen, type in clear. Another productivity trick for Bash is command line completion. To set this up, let's go back to our home directory by typing in cd ~ and then typing in ls to get a directory listing. To use command line completion, we'll use our Tab key.
The purpose of the Tab key is to complete the line for us so we don't have to type it in again. Type in cd M and then hit the Tab key, and you'll see that the line is completed for us. If we have one directory starting with a capital m, Bash will complete the line for us. However, if there's more than one possible choice Bash will give us an option, but only after we've pressed Tab twice. Let's backspace our line all the way to the beginning. And then type in cd D and hit your Tab key twice.
You see that we have three different choices. Desktop, Documents and Downloads. Bash wants us to type in a unique character, so type in the e and hit your Tab key again. And now it can complete the line. To quickly move between the beginning and end of the line, just use the Home and End keys. So, press the Home key, and you can see that your cursor moves to the beginning. End key takes you to the end. If you just want to move one word at a time, you can press alt + b to go backwards and alt + f to go forwards.
- Topics include:
- Shell tips and tricks
- Pattern matching with globs
- Pattern matching with extended globs
- Using the Bash shell
- Monitoring processes using ps
- Monitoring processes graphically
- Managing processes
- Job scheduling
- Limiting access to AT and cron jobs
- Managing system services