Solved

how to create a persistent alias?

Posted on 2004-04-18
6
712 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:karlwilbur
Comment Utility
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
Comment Utility
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
Comment Utility
khkremer,

Thank you for clarifying that.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now