Link to home
Start Free TrialLog in
Avatar of atwork2003
atwork2003

asked on

How to create shortcuts for commands in UNIX Solaris

I created in one of the file shortcuts for most used commands before on UNIX but after 3 years I kind of forgot how to do this. I have a local.cshr file in my home directory. Can i use it enter shortcuts for commands, or do I need to create a file that I can use for that reason. Please let me know. Thank you in advance:)
SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

As Tintin mentioned, you may use command aliases for ksh, csh and bash.

For sh, you may have your own commands that run specific commands with specific args. e.g.

in sh, you can:

1- have your own commands in $HOME/bin dir. This is the local bin dir where you put all your binaries / scripts. You need to include this dir in PATH:

PATH=$PATH:$HOME/bin

Put this in your $HOME/.profile file

2- add your own commands to $HOME/bin:

e.g.
l
were l is a shell script that contains the line:

ls -l $*

this shell script should be executable:

chmod +x $HOME/bin/l

The command can be used as:

l myfile
or
l

3- If you are the system admin (root), then you may add such commands to /usr/bin and make them available to all users

Avatar of atwork2003
atwork2003

ASKER

Guys this is not working for me. Can you please simplify it further, I have following in my home:

 ./
../
 .bash_history
 .profile
 .sh_history
 local.cshrc
 local.login
 local.profile
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
atwork - please describe what you tried and exactly what isn't working.

If you put your aliases/functions in .profile, then they will be all recognised the next time you invoke .profile or the next time you login.
Thank you for such detailed answer. i am looking into this right now. Will update very soon. Thank you so much:)
None of the above worked. I have following in my home directory. Sorry for delayed response, got stuck with a deadline. But I am having a lot of problems, typing the paths again and again and not being able to use shortcuts:)


 ./
../
 .bash_history
 .profile
 .sh_history
 local.cshrc
 local.login
 local.profile

Please give us details as to exactly what you tried.

As a simple test, try typing in the following from the command prompt and tell us what result you get

echo $0
alias l='ls -lt'
l
Hi,

If you can tell us what is your shell. Please login and  run the following command and port results

echo $SHELL

echo $HOME

ls -l .[pl]*
echo $SHELL

/bin/ksh

echo $HOME

/
--------------
What do you mean by port results?

ls -l .[pl]*

Can you please specify, so I can complete this part of your question as well. Thank you so much by the way for keeping interest in my question:)
Hi,

The shell you are using is ksh and what was recommended so far  about aliases should work.

ls -l .[pl]*

will do long listing for files that their names starts with . and then p or l e.g. .profile .login, etc.

.lsof_simn-101
.profile

I tried all the steps but none works
Which specific steps have you tried?  It would be useful if you copy/pasted the results, so we can see if you have mistyped anything.

Did you try doing

alias l='ls -lt'
l

Please post the *exact* output you get from typing those two lines.
Hi,

The output you posted is not as it should be. This is because the ls -l  command given will do a long listing of all files that either start with .p or .l (e.g. .profile & .login).

Please run:

ls -l .profile since it is clear that you are using ksh. Also a dump of .profile will help. Please use cat .profile and post results.

Guys I am so greatful for your continued interest in my question and for your patience while I tried the options. Thank you so much for all the great help, can not appreciate your help enough:)
Is there a way I can re-open this case. I realized that the alias doesnt work if I am using bash or sudo to root. Do I need to open a new question?
aliases work the same in bash as they do in ksh.

If you do

sudo su -

then if you want your aliases/functions, you'll need to add them to the root .profile
Hi,

atwork2003:

If you want the shortcuts to be available to all users, please add them to /etc/profile if they are aliases or to /usr/bin dir if they are scripts.

As suggested by Tintin, you may do su - to read the .profile of root as well.

Oh Thank you so much. I was just thinking if I can use my .profile while I am logged in as root. which of course not possible:) I don't want to change anything on root level. Thank you so much for all the help:)