• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Changing Directory question

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your replies..
 
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic