As system administrators and command-line enthusiasts, we inevitably find ourselves using the same commands ad nauseam. If we are any good at our jobs, we should always strive to make our processes more efficient. The goal is to ultimately "do more with less."
One of the first articles I wrote for Enable Sysadmin, which you can find here, was about the AutoHotkey tool for Windows. This is a fantastic utility that allows you to set up a user-friendly script that lightens your workload. As I have yet to find a suitable substitute for this tool in Linux, I looked into setting up aliases for the commands that I use regularly. Since I am no longer working in the support sector, most of these are just quality of life changes. Once you understand how to configure an alias, this process can be applied to almost any situation.
Aliases
First things first: What is an alias, and why do I care? Well, an alias is a custom command created by the user to execute another, usually more complicated command or group of commands. The utility of aliases can be seen in 'https://www.861278361.xyz/sysadmin/decluttering-process-management', where I mention an alias I created for the following command:
$ ps xawf -eo pid,user,cgroup,args
Instead of typing this full command, I created an alias that allows me to use pscgroup
to execute the original, much longer command. Now that you can see the utility on offer, let's take a look at where and how to configure our aliases.
[Want to try out Red Hat Enterprise Linux? Download it now for free.]
Creating aliases
There are a few things to note when creating aliases. For the purpose of this article, aliases are built on a user-by-user basis. If I create an alias as user tcarrigan
and then change to the root
user, the created alias will not work. Here you can see I aliased ls
to use a program called EXA that displays additional information and adds color-coding. The same command, in the same directory as the root user, displays the standard output for ls
:

There are locations where you can create aliases to span all users. For more information on this topic, check out the bash shell documentation.
For now, we will create our alias under user testuser
. So, in my home directory, I enter my alias into .bashrc
. Keep in mind that this file is hidden by default. It can be seen by adding the -a
flag to your ls
command:

You can see that this user starts with no aliases. We will correct this situation soon. For now, we will look at the command syntax. The correct syntax is as follows:
alias shortname=<command you want carried out>
We will now alias the ls
command to ls -lra
so that you get a much better look at all of your files, both hidden and non-hidden:

Now, reload the .bashrc
file using the following command:
$ source ~/.bashrc
When you use the standard ls
command now, you can see that the alias is now active, giving you the output for ls -lra
:

Wrapping up
While this alias is a simple quality of life change, you can apply this same concept to long and complicated commands that you might have to use routinely during your daily work. Let us know what some of your favorite use cases are. We at Enable Sysadmin look forward to hearing from you.
저자 소개
Tyler is the Sr. Community Manager at Enable Sysadmin, a submarine veteran, and an all-round tech enthusiast! He was first introduced to Red Hat in 2012 by way of a Red Hat Enterprise Linux-based combat system inside the USS Georgia Missile Control Center. Now that he has surfaced, he lives with his wife and son near Raleigh, where he worked as a data storage engineer before finding his way to the Red Hat team. He has written numerous technical documents, from military procedures to knowledgebase articles and even some training curricula. In his free time, he blends a passion for hiking, climbing, and bushcraft with video games and computer building. He is loves to read and enjoy a scotch or bourbon. Find him on Twitter or on LinkedIn.
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
가상화
온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래