This question already has an answer here:

Suppose I have command like cd abc/def, So I want to create own command like 'a'.

If I run 'a' command it ,should run command cd abc/def

optiplex-3020:~$ a

So could it be possible and I want to use python as scripting language

marked as duplicate by Rui F Ribeiro, RalfFriedl, Jeff Schaller, JigglyNaga, schily Nov 3 '18 at 17:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Do you want to change the working dir in the parent process (the shell) from within your program? That's (generally) not possible. – mosvy Nov 3 '18 at 10:15
  • 1
    @mrc02_kr this question may be a duplicate, but not of the one you're pointing to. – mosvy Nov 3 '18 at 10:17

cd is a built-in command and cannot be run by an external program, so you must use your shell:

alias a='cd abc/def'

If you want this to be permanent, put it in your ~/.bashrc or ~/.zshrc depending on your shell.

  • It is giving me the error,$ bash: alias: a: not found $bash: alias: =: not found $bash: alias: cd abc/def/ab: not found – user9862376 Nov 3 '18 at 7:45
  • I removed spaces it works for me thank you – user9862376 Nov 3 '18 at 7:48

You can just use aliases in linux it does exactly what you want. Other option is to create alias that points to the python script, but i see no point using python when you have it integrated in linux.

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