LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 08-22-2011, 08:18 AM   #1
hitmen
Member
 
Registered: Jun 2011
Distribution: Kubuntu 10.04
Posts: 158

Rep: Reputation: Disabled
Create Default Path When Terminal Is opened


My terminal goes to /home/$USER when I click on terminal.

However, I am doing BASH scripting and I want the terminal to automatically go to /home/$USER/bash_folder whenever I double click on the terminal.

So how is this done?
 
Old 08-22-2011, 08:32 AM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,974

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
Hi hitmen,

you can simply add a line to your .bashrc
Code:
cd bash_folder
provided the .bashrc is sourced when you open a terminal. If not, you'll have to find out which file is sourced (it depends on the distribution), read the manpage for bash.

Markus
 
Old 08-22-2011, 08:51 AM   #3
hitmen
Member
 
Registered: Jun 2011
Distribution: Kubuntu 10.04
Posts: 158

Original Poster
Rep: Reputation: Disabled
This is seriosly a noob question but there are so many bashrc files, so which one am I supposed to edit?

c@c-laptop:~/Desktop$ locate .bashrc
/etc/bash.bashrc
/etc/skel/.bashrc
/home/c/.bashrc
/home/c/.bashrc.swo
/home/c/.bashrc.swp
/root/.bashrc
/usr/share/base-files/dot.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/bash.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/skel/dot.bashrc

Last edited by hitmen; 08-22-2011 at 08:52 AM. Reason: post
 
Old 08-22-2011, 08:58 AM   #4
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,974

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
Well, this is not newbie question because it depends.

here the appropriate text from the bash-manpage
Quote:
When bash is invoked as an interactive login shell, or as a non-interactive shell with
the --login option, it first reads and executes commands from the file /etc/profile, if
that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login,
and ~/.profile, in that order, and reads and executes commands from the first one that
exists and is readable. The --noprofile option may be used when the shell is started to
inhibit this behavior.

When a login shell exits, bash reads and executes commands from the file ~/.bash_logout,
if it exists.

When an interactive shell that is not a login shell is started, bash reads and executes
commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc
option. The --rcfile file option will force bash to read and execute commands from file
instead of ~/.bashrc.
you should check if such a file (.bashrc or .profile and so on) is in your home-directory, if not create one.

When you open a terminal in X, bash isn't invoked as a login-shell, therefore a .bashrc file should be sourced. You'll have to try it out.

Note that it is possible (but I don't know) that you can change the path in the properties of the terminal-button in the menu (or wherever you click). In KDE this is possible, but I suppose you're using Gnome.

Markus
 
Old 08-22-2011, 08:23 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Normally that'd be the one in your home dir...
 
Old 08-23-2011, 07:03 PM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by hitmen View Post
My terminal goes to /home/$USER when I click on terminal.
It actually goes to $HOME, not /home/$USER. It's possible for a user to have a home directory not named /home/$USER.

Quote:
Originally Posted by hitmen View Post
This is seriosly a noob question but there are so many bashrc files, so which one am I supposed to edit?
"~/.bashrc", since it's the only one that's not system-wide.

The "*.swp" and "*.swo" files are files used by the Vim editor. If there's a swap file called ".example.swp", it means that either there is an instance of Vim running that has the file "example" opened in it, or that an instance of Vim that was editing "example" wasn't closed properly.
 
Old 08-23-2011, 08:37 PM   #7
verzonnen
Member
 
Registered: Aug 2003
Posts: 31

Rep: Reputation: 15
To add this to your bashrc in the terminal enter the following command;
echo "cd /where/ever/you/want/to/go" >> ~/.bashrc

Remember to make a copy of the .bashrc file and to test it after before logging out (you can test by reading the .bashrc back into the current shell by entering ". .bashrc" this time without the quotes)

Good luck.
 
Old 08-26-2011, 01:23 AM   #8
hitmen
Member
 
Registered: Jun 2011
Distribution: Kubuntu 10.04
Posts: 158

Original Poster
Rep: Reputation: Disabled
Got A few questions.

Ok here is the relevant output in my home folder:

c@c-laptop:~$ ls -la
total 60220

drwxr-xr-x 2 c c 4096 2011-08-22 21:05 bash_folder
-rw------- 1 c c 7530 2011-08-22 21:15 .bash_history
-rw-r--r-- 1 c c 220 2011-01-08 00:43 .bash_logout
-rw-r--r-- 1 c c 115 2011-08-22 21:04 .bash_profile
-rw-r--r-- 1 c c 3007 2011-07-12 21:56 .bashrc
-rw-r--r-- 1 c c 12288 2011-07-12 21:18 .bashrc.swo
-rw-r--r-- 1 c c 12288 2011-07-12 21:15 .bashrc.swp

I have already edited .bash_profile but it doesnt work

c@c-laptop:~$ cat ./.bash_profile
alias ll="ls -l"
alias today='date +"%A, %B %-d, %Y"'

# open bash_folder automatically in terminal
cd bash_folder

HOME/$USER/bash_folder doesnt open when I double click on the terminal.

In addition, the alias 'll' and 'today' doesnt work even though the file is edited. Can anyone explain why?

Last edited by hitmen; 08-26-2011 at 01:40 AM.
 
Old 08-26-2011, 08:41 AM   #9
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by hitmen View Post
Ok here is the relevant output in my home folder:

c@c-laptop:~$ ls -la
total 60220

drwxr-xr-x 2 c c 4096 2011-08-22 21:05 bash_folder
-rw------- 1 c c 7530 2011-08-22 21:15 .bash_history
-rw-r--r-- 1 c c 220 2011-01-08 00:43 .bash_logout
-rw-r--r-- 1 c c 115 2011-08-22 21:04 .bash_profile
-rw-r--r-- 1 c c 3007 2011-07-12 21:56 .bashrc
-rw-r--r-- 1 c c 12288 2011-07-12 21:18 .bashrc.swo
-rw-r--r-- 1 c c 12288 2011-07-12 21:15 .bashrc.swp

I have already edited .bash_profile but it doesnt work

c@c-laptop:~$ cat ./.bash_profile
alias ll="ls -l"
alias today='date +"%A, %B %-d, %Y"'
Did you completely ignore or misread the last two posts? They say that you should put it in .bashrc, NOT in .bash_profile.

bash_profile is executed when you log in, and its purpose is to set up the environment for all the programs and scripts you will be running. bashrc is a script that's run only when you open an interactive terminal, to set up things like your prompt, convenience aliases, etc. that you only want in interactive terminals. You wouldn't want them in scripts since they can change the way the script behaves.

Quote:
HOME/$USER/bash_folder doesnt open when I double click on the terminal.
The terminal is keyboard-only. Either open a GUI file manager and navigate to that directory, or run:

Code:
cd HOME/$USER/bash_folder
to go to it in the terminal.

Last edited by MTK358; 08-26-2011 at 08:49 AM.
 
Old 08-31-2011, 12:31 AM   #10
hitmen
Member
 
Registered: Jun 2011
Distribution: Kubuntu 10.04
Posts: 158

Original Poster
Rep: Reputation: Disabled
Can you elaborate more on this? :


bash_profile is executed when you log in, and its purpose is to set up the environment for all the programs and scripts you will be running.
 
Old 08-31-2011, 03:06 AM   #11
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,698

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
Try re-reading post #4 and having a look at man bash as all the information you are requesting is there.
 
  


Reply

Tags
bash scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xclients-default can not be opened thornton Fedora 2 10-08-2011 10:20 AM
[SOLVED] Move a file to some path and create that path when it doesn't exist WhisperiN Linux - Newbie 6 10-09-2010 12:47 PM
gnome terminal will be opened ram_rajavarapu Linux - Desktop 1 10-23-2008 07:33 AM
Resizing a terminal opened with CTRL-T in Konqueror SylvainP Linux - General 0 03-02-2004 09:20 PM
newly opened terminal shows bash-2.05$ instead of path jang Linux - General 6 01-18-2004 06:21 PM


All times are GMT -5. The time now is 01:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration