• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing Directory question  RSS feed

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a home dir like /home/satish
I have the following directories under /home/satish
user#ls /home/satish
Documents
Scripts
Help
Now I am in dir /var/tmp. When i type the command 'cd Scripts' i want to be in the directory /home/satish/Scripts.
How can this be achieved?
Thanks
Regards,
Satish
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy.
If you put the following in your .bashrc file you can get something similar to what you are asking.
alias ccd="cd && cd $1"
It will:
1) cd to your home directory and then
2) either change to the specified directory if it exists
or complain if the directory does not exist.
Example invocation: ccd Scripts
I don't know about changing the default behaviour of the cd command itself but it does not sound like a good idea to anyway.
 
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I first agreed to Carlos.
Since 'cd' is a build-in bash-command, I thought you have to modify the source of bash. (assuming you use bash as shell).

didn't work - It allways changed dir to
/home/satish
(ok - to be true: not satish in my case)
I first proved my assumtion, cd being a command and not an executable:
which cd
Then I proved cd not to be an alias for chdir or something using alias.
Then I looked at the man-page - generally a good idea: man bash
where I searched for cd. Surprise: I found a 'CDPATH'. (I never heard before). I told it

and made a cd Scripts from /var/tmp - and it worked.
I guess setting the CDPATH to /home/satish:. will be a better idea, and even better .:/home/satish.
Even command-completition works.
But perhaps you just don't know, that you may use cd ~/Scripts to change to the subdirectory in your home.
 
Satish Kulkarni
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies..
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!