PDA

View Full Version : alias(command) applications on linux


Ravix
03-02-2006, 12:24 AM
Hi im wonder what's the command line for alias an application on linux?

i been trying this

cat> .login
alias X 'application location'
cntl d


anyone know ?? why

UrbanFuturistic
03-02-2006, 01:16 AM
You need a symbolic link :)

ln -s target alias

if you miss out the -s you'll create a hard link which essentially means that the file now has two proper names and deleting one will still leave the other name which will also have to be deleted. A symbolic link, on the other hand, just points to the original filename.

Type man ln for more info.

86point5
03-02-2006, 01:41 AM
I'm I'm interpreting what you are saying correctly, you're looking for something like this:

alias mycommand='grep foo *.txt'

The syntax varies depending on what shell you are running. The most common shell (that I ever see in use) is bash. The example above works in bash.

If you just want the alias for your current session, just enter it on the command line. If you want to make it more permanent, you'll want to add it to your profile. If you are using bash, your profile is likely in your home directory with the name '.bash_profile'

Names that begin with dots don't usually show up in a directory listing, so you'll need to do an
ls -la
to see it.

Inside that file (if it exists) is usually a section for user specified aliases and functions.

That's where you should put all your persistent alias mappings.

You may see stuff in there like:
alias ll='ls -la'
alias rm='rm -i'

Just append yours below these. (If they're there)

--

If you use a different shell, the syntax (and filenames) will vary. Can't remember off my head what (if any) differences there are for other shells like csh, ksh, etc.

Ravix
03-02-2006, 02:41 AM
Agent 86.5 thanks! i guess cat>. .login just work on oSx
but this is my bash profile i dont know where to put it


# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME

KayosIII
03-02-2006, 03:40 AM
Reading this file it seams that the alias's are supposed to go in a seperate file called .bashrc if you don't have one just make a new one. You can of course put aliases anywhere in that file and they will work fine, the method they suggest is probably a little cleaner and upgrade safe.

86point5
03-02-2006, 12:52 PM
Looking at your original cat > .login
alias X 'application location'
cntl d
Here's what's happening.
'cat' is a command for concatinating (joining). It is normally used to join files, but if you don't give it files, it uses what comes from standard in (the terminal).
In this case, you're saying "take what I type next and put it into a file named .login"

Next you type your alias, then hit ctrl-d to signify to cat that you are done.

The problem I see with this is that this will overwrite .login every time.
If you want to append to a file, you'd want
cat >> .login
as the two angle brackets signify to append and not just to write to the file.

The other issue is that for bash, you'd want to format your alias command like I outlined above.

Looking at your profile, yes - you should just add your aliases to the .bashrc file as your profile includes it. This is usually the case, but not always, so I didn't mention it in my prior post, as I didn't want you to put things there and not have it included.

After changing your profile, the changes won't be effective until you either run your profile, or log back in again.

You could change your .bashrc file using the cat method, or just open it up in whatever text editor you are comfortable in (vi, emacs, pico, joe, ect.)

CGTalk Moderation
03-02-2006, 12:52 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.