Solved

how to create a persistent alias?

Posted on 2004-04-18
6
718 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

863 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

26 Experts available now in Live!

Get 1:1 Help Now