Accessing the Command Line
CIS126RH · Red Hat System Administration I
The bash shell · Command syntax · Getting help
Goal: log in to RHEL's graphical and command-line environments and run simple commands correctly.
CIS126RH · Red Hat System Administration I
The bash shell · Command syntax · Getting help
Goal: log in to RHEL's graphical and command-line environments and run simple commands correctly.
Key commands: bash, pwd, echo, history, man, apropos, which
The shell is a command interpreter.
On RHEL, the default shell is bash — the Bourne Again SHell.
The GUI is optional; the command line is not.
Most production RHEL servers are headless: they run without a graphical desktop.
[student@server1 ~]$
The prompt ends in $.
[root@server1 ~]#
The prompt ends in #.
Always check the prompt. A # means you are root and a mistyped command can damage the system.
| Method | Where / Use |
|---|---|
| GNOME Terminal | Graphical desktop; local workstation |
| Virtual console | Ctrl+Alt+F3–F6; direct login |
| SSH | Remote network login |
| Text-mode boot target | Servers without a GUI |
RHEL provides multiple virtual consoles.
Virtual consoles provide direct text-mode access without requiring a GUI.
command [options] [arguments]
| Part | Purpose |
|---|---|
| command | The program to run |
| options | Modify behavior; usually - or -- |
| arguments | Files, directories, or values the command acts on |
pwd ls -l ls --all ls -la ls -l /etc
pwd: no option or argument-l: short option--all: long option-la: combined short options/etc: argumentThe shell treats spaces, quotes, and characters such as *, $, and > specially.
echo Hello World echo "Hello World" echo '$HOME stays literal here' echo "$HOME expands here"
Exam note: Single quotes are fully literal; double quotes still allow variable expansion and command substitution.
| Shortcut | Action |
|---|---|
| Ctrl+A | Move to start of line |
| Ctrl+E | Move to end |
| Ctrl+U | Delete from cursor to start |
| Ctrl+K | Delete from cursor to end |
| Ctrl+R | Search command history |
| Ctrl+C | Cancel current command |
| ↑ / ↓ | Move through history |
history !482 !!
history displays recent commands.!482 re-runs command 482.!! re-runs the most recent command.Ctrl+R is your friend: search backward through command history instead of pressing ↑ repeatedly.
Commands can use absolute or relative paths.
Starts from the root directory /.
cd /etc/ssh
Starts from the current directory.
cd ../ssh
| Command | Meaning |
|---|---|
pwd | Show current working directory |
cd ~ | Go to your home directory |
cd - | Go to the previous directory |
cd .. | Go to the parent directory |
Press Tab while typing a command, file name, or path.
cd /etc/ss[Tab] # becomes: cd /etc/ssh/
Press Tab twice to list all possible matches when more than one exists.
Tab completion reduces typing, prevents path typos, and helps confirm that a file or directory exists.
| Tool | Purpose |
|---|---|
man | Full manual page for a command, file, or system call |
--help | Quick summary of command options |
apropos | Search man-page descriptions by keyword |
which | Show the path to a command's executable |
man ssh ssh --help apropos partition which ssh
man for detailed documentation.--help for a quick reference.apropos when you know the topic but not the command.which to locate the executable.| Key | Action |
|---|---|
| Space | Scroll forward one page |
| b | Scroll backward one page |
| /pattern | Search forward |
| n | Repeat the last search |
| q | Quit the man page |
Man pages have sections. For the file-format version of passwd, use man 5 passwd.
$ or #./.$ prompt and a # prompt?$HOME differently?passwd man page?$ vs. #.The goal is not to memorize every command. Learn how to work effectively at the shell and how to find the information you need.