订阅 RSS 源
Linux 

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

user based alias

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:

.bashrc w/o alias

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:

.bashrc with alias

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:

alias in action

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.

Read full bio
UI_Icon-Red_Hat-Close-A-Black-RGB

按频道浏览

automation icon

自动化

有关技术、团队和环境 IT 自动化的最新信息

AI icon

人工智能

平台更新使客户可以在任何地方运行人工智能工作负载

open hybrid cloud icon

开放混合云

了解我们如何利用混合云构建更灵活的未来

security icon

安全防护

有关我们如何跨环境和技术减少风险的最新信息

edge icon

边缘计算

简化边缘运维的平台更新

Infrastructure icon

基础架构

全球领先企业 Linux 平台的最新动态

application development icon

应用领域

我们针对最严峻的应用挑战的解决方案

Virtualization icon

虚拟化

适用于您的本地或跨云工作负载的企业虚拟化的未来