So you've logged in to the Linux terminal, and you're staring at a command prompt. Now what? The first time I was presented with a command shell, I felt a little at home because I had extensive experience with Microsoft's DOS.
Today though, unless you're a PowerShell whiz or coming from macOS and already familiar with its terminal, the Linux prompt will feel pretty foreign. The prompt is an interface to Bash (Bourne Again SHell). Bash's features help you out a little, and using it is really not all that difficult.
What is Bash?
I won't give you a Bash history (if you're interested, you can get that from Command Line Heroes' Bash episode). The main thing you need to know is that Bash is the command-line interpreter on most modern Linux machines. You have other options, but on Red Hat Enterprise Linux (RHEL), Bash is the default. Some great graphical user interfaces (GUIs), tangible user interfaces (TUIs), and web console interfaces will let you manage your RHEL server, but nothing quite compares to the level of control and freedom that you get from the command line.
Bash is capable of more than just issuing commands and launching other programs. It has a pretty extensive scripting language associated with it called, well, Bash. However, scripting is also beyond the scope of this article; just know that it exists. Here are some tips to get you familiar with Bash.
[ Want to learn about scripting? Download the Bash shell scripting cheat sheet. ]
Understand the prompt
[tux@rhel8 ~]$
I'll begin with the prompt itself. By default, the command prompt might look odd or garbled, but it actually includes some pretty useful information. I'll break down the prompt above, which contains four very important values:
tux
is the current username.@rhel8
is the system's hostname.~
indicates the current directory.~
is shorthand for your home directory. If you were in/etc
, it would sayetc
; if you were in/usr/src/
, it would saysrc
.$
indicates whether you are privileged.$
indicates a standard user, and#
indicates a privileged superuser (also called root).
Because the prompt is highly customizable, I'll use the simplest common prompt for the rest of this article: a single $
character. Don't type the $
prompt when you enter commands. Its purpose, both in your terminal and in this article, is to help you keep track of the commands you're entering and the output your computer is providing back to you.
Change directories
If you grew up when I did, you had a CD collection. If you didn't, you probably at least know what CDs are (compact discs). In Linux, the cd
command has nothing to do with music. Instead, cd
means change directory in Bash. You change to a new directory by entering cd /path/to/new/directory
. But there are also some shortcuts to know.
.
is the current directory (you will seldomcd
to.
but it's very useful for other things)...
is the directory above the current working directory.-
is the last directory you were in.~
is your home directory./
is the root of the filesystem, or the delimiter between directories in a full path.
The command pwd
(which stands for "present working directory") tells you the absolute path to the current working directory. Try it out and practice using cd
to navigate to the directories listed above by using the examples below.
$ pwd
/home/tux
My username is tux
, so the pwd
output tells me I'm in my home directory. In your terminal, you will see your username.
Here's an example session with some cd
and pwd
commands (I've created some test directories and subdirectories to demonstrate, so those folders don't exist on your computer):
$ cd test1/
$ cd testsub1/
$ pwd
/home/tux/test1/testsub1
$ cd ..
$ cd /etc/
$ cd ~/test2/
$ pwd
/home/tux/test2
$ cd -
/etc
$ pwd
/etc
$ cd ~
$ pwd
/home/tux
$
Use command auto-completion
Auto-completion is a tool that I abuse the heck out of. It saves you a ton of time if you know the first few letters of a command. You use it by entering a few characters and then pressing the Tab key. Bash then types the rest of the command for you. Pressing Tab once completes the command if there is only one command that matches the letters you entered. Pressing Tab twice displays all of the possibilities that match. Here is an example:
$ rsyn<tab>
$ rsync
$ rsy<tab><tab>
rsync rsyslogd rsyslog-recover-qi.pl
[ Download the Bash cheat sheet to become more efficient at the command line. ]
Some commands even have auto-complete built-in for their command-line options.
Auto-completion will also warn you if there are a lot of results.
$ l<tab><tab>
Display all 128 possibilities? (y or n)n
Learn more
I hope these explanations have helped your understanding of the Bash command prompt. There is so much more you can learn and explore, but these are the basics, and I hope this article eases some of the anxiety associated with that blinking cursor.
Sobre el autor
Nate is a Technical Account Manager with Red Hat and an experienced sysadmin with 20 years in the industry. He first encountered Linux (Red Hat 5.0) as a teenager, after deciding that software licensing was too expensive for a kid with no income, in the late 90’s. Since then he’s run everything from BBS’s (remember those?) to derby hat’s containing raspberry pi’s, to Linux systems in his basement, or in enterprise-class data-centers.
He runs his own blog at undrground.org, hosts the Iron Sysadmin Podcast, and when he’s not at a command line, he’s probably in the garage tinkering on his Jeep, or out on the trails.
Navegar por canal
Automatización
Las últimas novedades en la automatización de la TI para los equipos, la tecnología y los entornos
Inteligencia artificial
Descubra las actualizaciones en las plataformas que permiten a los clientes ejecutar cargas de trabajo de inteligecia artificial en cualquier lugar
Nube híbrida abierta
Vea como construimos un futuro flexible con la nube híbrida
Seguridad
Vea las últimas novedades sobre cómo reducimos los riesgos en entornos y tecnologías
Edge computing
Conozca las actualizaciones en las plataformas que simplifican las operaciones en el edge
Infraestructura
Vea las últimas novedades sobre la plataforma Linux empresarial líder en el mundo
Aplicaciones
Conozca nuestras soluciones para abordar los desafíos más complejos de las aplicaciones
Programas originales
Vea historias divertidas de creadores y líderes en tecnología empresarial
Productos
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Servicios de nube
- Ver todos los productos
Herramientas
- Training y Certificación
- Mi cuenta
- Soporte al cliente
- Recursos para desarrolladores
- Busque un partner
- Red Hat Ecosystem Catalog
- Calculador de valor Red Hat
- Documentación
Realice pruebas, compras y ventas
Comunicarse
- Comuníquese con la oficina de ventas
- Comuníquese con el servicio al cliente
- Comuníquese con Red Hat Training
- Redes sociales
Acerca de Red Hat
Somos el proveedor líder a nivel mundial de soluciones empresariales de código abierto, incluyendo Linux, cloud, contenedores y Kubernetes. Ofrecemos soluciones reforzadas, las cuales permiten que las empresas trabajen en distintas plataformas y entornos con facilidad, desde el centro de datos principal hasta el extremo de la red.
Seleccionar idioma
Red Hat legal and privacy links
- Acerca de Red Hat
- Oportunidades de empleo
- Eventos
- Sedes
- Póngase en contacto con Red Hat
- Blog de Red Hat
- Diversidad, igualdad e inclusión
- Cool Stuff Store
- Red Hat Summit