Phase 3: Learn to Talk to Your Machine. Lesson 1 of 7. About 15 minutes.
Plain entry
The terminalThe window or screen where you type text commands and read their output, connected to a shell that runs those commands. Read more → is a window where you type instead of click. Clicking is fine until you need to do the same thing on fifty servers, or on a server that has no screen at all. Typing scales. Every lesson from here on is mostly typing.
Terms
- Terminal: the window that shows text and takes your keystrokes.
- Shell: the program inside the terminal that reads your command and runs it. Ubuntu’s is Bash.
- Prompt: the text before your cursor, like
you@bnlc-ubuntu:~$. It shows user, machine, and current folder.$means normal user;#means root. - Command, argument, option: in
ls -l /etc,lsis the command,-lis an option,/etcis an argument. - Root: the all-powerful admin account. You borrow its power with
sudo.
Depth
whoami
echo $SHELL
echo "hello from $(hostname)"
Expected output:
yourname
/bin/bash
hello from bnlc-ubuntu
$SHELL is an environment variable. $(...) runs a command and drops its output in place.
Keys that save hours:
- Tab completes names. Press twice to see options.
- Up arrow recalls the last command. Ctrl+R searches history.
- Ctrl+C stops the running command. Ctrl+L clears the screen.
history | tailshows your recent commands.
Reading help, the professional way:
man ls # full manual, q to quit, /word to search
ls --help # short summary
Going further
type ls shows whether a command is a program, an alias, or built into Bash. type cd reports cd is a shell builtin: it has to be, because a separate program cannot change your shell’s current folder.
Why it works this way
The shell reads your whole line, expands things like $SHELL and $(...), and only then runs the program. That is why echo "hello from $(hostname)" prints your machine name: echo never sees the $(...), it sees the result. Keep this in mind when a command does something odd. Ask what the shell turned your line into before blaming the program. type and echo let you check.
Self-check
- What is the difference between the terminal and the shell?
- What does
#at the end of the prompt mean? - How do you stop a command that is running forever?
Answers: (1) The terminal displays; the shell interprets. (2) You are root. (3) Ctrl+C.
Sources
- Ubuntu tutorial, The Linux command line for beginners: https://ubuntu.com/tutorials/command-line-for-beginners
- GNU Bash manual: https://www.gnu.org/software/bash/manual/
manman page: https://man7.org/linux/man-pages/man1/man.1.html