Redirect one directory to another path in Linux

3.8k Views Asked by At

For one user(say User1) , it has default home directory as /home/User1 . When we give command just cd , it goes to this home directory. But we have another directory called /proj/User1 , which should be the expected directory it should go with just cd command instead of /home/User1.

I suppose , modifying cd command is not good way. Is there any other like softlinking , to go to dir2 whenever we cd to dir1? Please help.

2

There are 2 best solutions below

0
BrandoN On

This is the original link where i got the information. https://superuser.com/questions/167221/can-i-add-a-shortcut-to-replace-a-path-in-linux

Using Aliases

alias somedir='cd /home/john/www/something/'

Then you can type "somedir" to go to that directory. Add these to your .bashrc.

0
Scala On

Using aliases you can accomplish what you want. You can set them in bashrc. This way, the change will be kept after you reboot your computer.

echo 'alias cdx="cd /proj/User1"' >> ~/.bashrc
source ~/.bashrc
cdx