Solved

how to create a persistent alias?

Posted on 2004-04-18
6
723 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
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.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

825 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