?
Solved

how to create a persistent alias?

Posted on 2004-04-18
6
Medium Priority
?
737 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 150 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Fine Tune your automatic Updates for Ubuntu / Debian
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…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

800 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