Solved

how to create a persistent alias?

Posted on 2004-04-18
6
730 Views
Last Modified: 2013-12-15
i would like to create an alias for example "reboot" = 'shutdown -r now'
or "halt" = 'shutdown -h now'

whenever i create an alias i find that it is destroyed on reboot. surely there is a way to make them persistent?
0
Comment
Question by:alpha_dk
  • 3
  • 2
6 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10852731
Put these commands in your .profile file (or, if you use a different shell, into one of the configuration files for your shell).
0
 

Author Comment

by:alpha_dk
ID: 10852899
thanks kremer i assume you mean .bash_profile?

what exactly would i write in there?
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 50 total points
ID: 10852928
Bash uses different profile files: /etc/profile, ~/.bash_profile, ~/.profile and ~/.bash_login, ~/.bashrc, you can use either of these (as long as you know that /etc/profile will change this for every user on your system). If you already have .bash_profile, just use that.
You could go even one step further and create a .alias file in your home directory. In order to use this file, you need to ad this to your profile file:

test -s ~/.alias && . ~/.alias

This will first check if a file named ~/.alias exists, and if it does, it will source (include) it.

Regardless of which way you chose, you need to put something like this into your configuration file:

alias reboot="shutdown -r now"
alias halt="shutdown -h now"

0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 6

Expert Comment

by:karlwilbur
ID: 10853657
There is a standard sequence that bash loads config files, and each file is supposed to contain specific information.  User specific Alias commands belong in ~/.bashrc.

-Karl
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10853848
Karl,
most people don't know (and don't care) about the differences, but if you want to direct somebody to a specific file, you should provide some background information about why this is the correct file :-)

An alias will work in all the files that I've listed, however there is one file that will have one small advantage over other's: The .bashrc file will be read only for interactive shells, which means that you don't slow down the loading of a shell that's used for e.g. a shell script by defining aliases.
0
 
LVL 6

Expert Comment

by:karlwilbur
ID: 10855113
khkremer,

Thank you for clarifying that.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question