Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Linux Shell Scripting Essentials

You're reading from   Linux Shell Scripting Essentials Learn shell scripting to solve complex shell-related problems and to efficiently automate your day-to-day tasks

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher
ISBN-13 9781785284441
Length 282 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Sinny Kumari Sinny Kumari
Author Profile Icon Sinny Kumari
Sinny Kumari
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Linux Shell Scripting Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. The Beginning of the Scripting Journey FREE CHAPTER 2. Getting Hands-on with I/O, Redirection Pipes, and Filters 3. Effective Script Writing 4. Modularizing and Debugging 5. Customizing the Environment 6. Working with Files 7. Welcome to the Processes 8. Scheduling Tasks and Embedding Languages in Scripts Index

Alias


Alias in shell refers to giving another name to a command or group of commands. It is very useful when a name of a command is long. With the help of alias, we can avoid typing a bigger name and invoke a command by a name as per your convenience.

To create an alias, alias shell builtin command is used. The syntax is as follows:

alias alias_name="Commands to be aliased"

Creating alias

To print a disk space in a human-readable format, we use the df command with the -h option. By making alias of df -h to df, we can avoid typing again and again df -h.

The output of the df command before aliasing it to df -h is shown in the following screenshot:

$ df

Now, to create alias for df -h to df, we will execute the following command:

$ alias df="df -h"	# Creating alias
$ df

The output obtained is as follows:

We see that after creating alias of df -h to df, a default disk space is printed in a human-readable format.

Another useful example can be aliasing the rm command to rm -i. Using rm with the -i option...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images