I am not a root user & I don't have access to the global alias file which has all the aliases created, but I want to create some aliases which remain active only for the session I am logged in. I use the command alias x='cd /parent/child' to create an alias which will enable me to just type x on the console & I change dir to /Parent/Child .

However, I want to create multiple aliases & I don't want to type each alias I create every time.

I tried putting all the alias='do this' lines in a file (gave it 777 permission) hoping that on running the file all these aliases would be created every time I login. But that didn't happen.

ex :

alias x='cd /parent/child'
alias y='cd /a/b/c'
alias z='tail -0f some.log'

I also tried this in the file but in vain:

alias x='cd /parent/child';alias y='cd /a/b/c';alias z='tail -0f some.log'

None of the alias names I tried were already present in the global alias. (I typed alias & saw the output on the screen).

  • You can put all your aliases in .bashrc file. – cuonglm Aug 7 '14 at 9:36
  • @Web Nash: But if you want to pass different arguments to different commands then this won't work – Thushi Aug 7 '14 at 9:51

generate all you session alias in a file, for instance alias.txt

alias x='cd /parent/child'
alias y='cd /a/b/c'
alias z='tail -0f some.log'

then use

 . ./alias.txt

You sould have all you alias in alias list, for this single session.


Be sure to use

. ./alias.txt



In former case, content is read 'as if typed', while the latter case will define alias in a shell that will exit.

  • I did a similar thing initially before I posted this question. Instead of a text file I just put these lines in a file without any extension & that didn't work. But even when I tried it with a .txt extension it didnt work – Web Nash Aug 7 '14 at 10:59
  • That worked Perfectly. Thank You so much. I didn't understand the difference between using these three forms 1) alias.txt 2) ./alias.txt 3) . ./alias.txt – Web Nash Aug 7 '14 at 11:16
  • form 1) and 2) are equivalent if . is in your $PATH. thay will baiscally call a new shell, run the command. In most case this is OK, however if you want alias or function, definition will dissapear when shell exit. – Archemar Aug 7 '14 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.