INTRO
Today we’ll end with a bang - with a quick introduction to five different topics. Mastery isn’t required today - you’ll be getting plenty of practice with all these in the sessions to come!
Don’t be misled by how simplistic some of these commands may seem - they all have hidden depths and many sysadmins will be using several of these every day.
YOUR TASKS TODAY
- Use tab completion
- Search in the command history
- Read a dot file using more and less
- Change / customize your prompt
Use the links in the Resources section to complete these tasks:
-
Get familiar with using
more
andless
for viewing files, including being able to get to the top or bottom of a file inless
, and searching for some text -
Test how “tab completion” works - this is a handy feature that helps you enter commands correctly. It helps find both the command and also file name parameters (so typing
les
then hitting “Tab” will complete the commandless
, but also typingless /etc/serv
and pressing “Tab” will complete toless /etc/services
. Try typingless /etc/s
then pressing “Tab”, and again, to see how the feature handles ambiguity. -
Now that you’ve typed in quite a few commands, try pressing the “Up arrow” to scroll back through them. What you should notice is that not only can you see your most recent commands - but even those from the last time you logged in. Now try the
history
command - this lists out the whole of your cached command history - often 100 or more entries. There are number of clever things that can be done with this. The simplest is to repeat a command - pick one line to repeat (say number 20) and repeat it by typing !20 and pressing “Enter”. Later when you’ll be typing long, complex, commands this can be very handy. You can also pressCtrl + r
, then start typing any part of the command that you are looking for. You’ll see an autocomplete of a past command at your prompt. If you keep typing, you’ll get more specific options appear. You can either run it by pressing return, or editing it first by pressing arrows or other movement keys. You can also keep pressingCtrl + r
to see other instances of the same command you used with different options. -
Look for “hidden” files in your home directory. In Linux the convention is simply that any file starting with a “.” character is hidden. So, type
cd
to return to your “home directory” thenls -l
to show what files are there. Now typels -la
orls -ltra
(the “a” is for “all”) to show all the files - including those starting with a dot. By far the most common use of “dot files” is to keep personal settings in a home directory. So use your new skills withless
to look at the contents of.bashrc
,.bash_history
and others. -
Finally, use the
nano
editor to create a file in your home directory and type up a summary of how the last five days have worked for you.
EXTENSION
We’re using bash
as our terminal shell for now (it is standard in many distros) but it is not the only one out there. If you want to test out zsh, fish or oh-my-zsh, you will see that there are a few differences and the features are usually the main differentiator. Try that, poke around.
After that, you can go up a notch and try to have several shell sessions open at the same time in the same terminal window with a terminal multiplexer. Try screen - that’s a little simpler and maybe too terse in the beginning - or tmux, that have many features and colors. There are so much material out there on “how to customize your tmux”, have fun.
RESOURCES
- Unix Less Command: 10 Tips for Effective Navigation
- How To Use Bash History Commands and Expansions…
- BASH Shell commands less
- Tab completion
- What are dotfiles?
- Nano editor tutorials
- Bash Shell: Take Control of PS1, PS2, PS3, PS4 and PROMPT_COMMAND
- Bash Shell PS1: 10 Examples to Make Your Linux Prompt like Angelina Jolie
Some rights reserved. Check the license terms here