Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I open my non-login shell in Ubuntu, my present working directory is /home/user_name (my $HOME environment variable), but I want to change this such that when I start my terminal I am in some other directory.

I have read that when I start my terminal in Ubuntu a .bashrc file is sourced. So I added

export HOME=/home/user_name/Documents 

to my .bashrc file. Now, when I open my terminal I am still in /home/user_name directory.

How can I change this?

share|improve this question
    
Does this help? askubuntu.com/a/75223/212231 –  Mark Plotnick Jul 3 at 18:33
3  
It might also be worth considering not doing this. The design of UNIX wasn't handed down by the forefathers for nothing you know. –  Sean D Jul 3 at 23:30
add comment

2 Answers 2

First of all, remove that line from your .bashrc. The way to do this in not by playing with $HOME, that variable will always point to your home directory and you don't want to change that just so your shells start in a different place.

I'm sure there will be a more elegant way to do this but as a temporary workaround you can simply add this line to your .bashrc:

cd ~/Documents 

Since that file is read every time you start a new non-login shell (open a new terminal), the cd command will be executed and your terminals will start at ~/Documents as you desire.

share|improve this answer
    
Note that it will affect all the non-login interactive shells (and login ones if you source your bashrc from your bash_profile) and the non-interactive ones started by sshd. –  Stéphane Chazelas Jul 3 at 21:08
    
@StéphaneChazelas Are you sure? Usually there is a [[ -z "$PS1" ]] && exit guard at the top of the .bashrc which should prevent this for non-interactive sessions. –  queueoverflow Jul 4 at 10:48
1  
@queueoverflow usually? In what operating system? In which distribution? Not on Debian, SuSe or CentOS. In fact, I think I've only ever seen that on Ubuntu. –  terdon Jul 4 at 10:56
    
@terdon I have seen it on Ubuntu and thought that was the general case. –  queueoverflow Jul 5 at 13:58
add comment

The terminal will start in the working directory it inherits from its parent.

However, some allow to override it via configuration settings.

With gnome-terminal, you can edit your profile, tick run a custom command instead of my shell and make it:

sh -c 'cd ~/Documents; exec "${SHELL:-sh}"'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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