As a solutions engineer, most of my work happens on the Linux terminal. As you continue to use the CLI, you'll begin to notice that most of the commands that you use on a daily basis are usually a repetitive subset of the general commands, to make our lives simple, as a thumb rule we need to keep these commands as easy to use as possible. We already have shortlisted CLI commands like ps
, ls
, sed
, grep
, etc, using even these can be made simple and fun by using keystroke aliases.
This was all very well thought about and we are fortunate that bash provides us with the option of using keystroke aliases to be used. Let’s see what we can accomplish by simply saving our day-to-day commands as aliases/shorthand commands in Bash. Ready?
How to save keystroke aliases
This is very simple and straight forward, Let’s say you want to list all the contents of a folder instead of typing ls -latr,
you want to use just ls
by using the alias
command:
$ alias ls='ls -latr'
You can save your keystrokes, but this will only be saved until you exit the shell. Also, please pay attention to the spacing in the above command.
What if I want to temporarily mask this above-declared alias: Just use \ls
and you will get just the default functionality.
Tips:
- What if you want to remove the alias in the present shell?
- Just type
unalias ls
Now, we have an idea on how to make our own short-hand commands in Bash, but we also need this to be saved when we re-login to our bash shell. To do that you need to save the alias command in a special file called ~/.bashrc
where you can save all your keystroke aliases which will persist even after you re-login to your shell. Don't forget to source your .bashrc
file when you're finished adding your aliases to it, so that your aliases become active without logout/login.
$ source ~/.bashrc
Here are some cool examples which I use in my .bashrc
file and you can incorporate them if you find them beneficial.
Windows-like experience in Linux
alias copy="cp"
alias rename="mv"
alias md="mkdir"
alias rd="rmdir"
alias del="rm -i"
Directory changes made easy
alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
Update commands
alias update='yum update'
alias updatey='yum -y update'
Subscription manager aliases
alias sml=`subscription-manager list --available --all`
alias smr=`subscription-manager remove --all`
A random list of useful commands
alias root='sudo -i'
alias su='sudo -i'
alias reapache='systemctl restart httpd'
alias cpuinfo=’lscpu’
alias tcpdump=’tcpdump -i eth0`
alias ping=’ping 8.8.8.8 -c 5’
#browser selection
alias chrome='/opt/google/chrome/chrome'
alias opera='/opt/opera/opera'
alias firefox=’/opt/firefox/firefox’
alias df='df -khT'
alias du='du -h'
alias top='atop'
Wrap-up
You can go on adding various aliases, but the goal of this article is to make your life easy by saving the regularly used commands into the .bashrc
file and using a shortcut alias to call the command with options.
Want to try out Red Hat Enterprise Linux? Download it now for free.
Sobre el autor
I work as a Solutions Engineer at Red Hat and my day-to-day work involves OpenShift and Ansible. I'm highly passionate about open source software, cloud, security, and networking technologies.
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