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

AI (人工知能)

お客様が AI ワークロードをどこでも自由に実行することを可能にするプラットフォームについてのアップデート

open hybrid cloud icon

オープン・ハイブリッドクラウド

ハイブリッドクラウドで柔軟に未来を築く方法をご確認ください。

security icon

セキュリティ

環境やテクノロジー全体に及ぶリスクを軽減する方法に関する最新情報

edge icon

エッジコンピューティング

エッジでの運用を単純化するプラットフォームのアップデート

Infrastructure icon

インフラストラクチャ

世界有数のエンタープライズ向け Linux プラットフォームの最新情報

application development icon

アプリケーション

アプリケーションの最も困難な課題に対する Red Hat ソリューションの詳細

Virtualization icon

仮想化

オンプレミスまたは複数クラウドでのワークロードに対応するエンタープライズ仮想化の将来についてご覧ください