How do I change the "default working" directory of terminal applications in RHEL6 ?

Solution Unverified - Updated -

Environment

  • Red Hat Enterprise Linux 6
  • GNOME Desktop Environment
  • K Desktop Environment (KDE)

Issue

  • In GNOME Desktop, when user right-click on his desktop and select "Open in Terminal", a new gnome-terminal process starts default in ~/Desktop directory.

  • Similarly in KDE, when trying to launch Terminal Applications (eg: gnome-terminal, konsole or xterm) from Application --> System --> konsole/terminal menu, the default working directory is ~/Documents.

  • How to change the default working directory of Terminal Applications to ~/ instead of ~/Desktop or ~/Documents directory ?

Resolution

GNOME Desktop :-

  • Use gconftool-2 to make Open in Terminal start in ~/ or $HOME instead of ~/Desktop. This can be done per-user and the global default can also be changed.

    • As a user, run following command to change the behavior immediately:
    $ gconftool-2 --set --type=bool /apps/nautilus-open-terminal/desktop_opens_home_dir true
    
    • As root, run below command to set the default behavior, which will be source when new users first log in:
    # gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --set --type=bool /apps/nautilus-open-terminal/desktop_opens_home_dir true
    

KDE :-

  • It's a KDE feature that terminal applications launched from Menu items or from krunner default start into $HOME/Documents directory.

Workarounds

  • For konsole

    • Specify ~/ or $HOME as the default working directory in Konsole's profile for individual user:

      Open konsole > Settings > Edit current profile >  In General tab specify the default directory path  in "Initial directory" section. > Click Ok
      
    • Change the system wide setting for Konsole by specifying ~/ or $HOME as the startup working directory in konsole.desktop file.

      • Edit /usr/share/applications/kde4/konsole.desktop file and add "--workdir $HOME" option to "Exec=konsole":
      # vim /usr/share/applications/kde4/konsole.desktop
      
      <snip>
      [Desktop Entry]
      Type=Application
      Exec=konsole --workdir $HOME      <<---------
      Icon=utilities-terminal
      X-DocPath=konsole/index.html
      Terminal=false
      X-KDE-StartupNotify=true
      <snip/>
      
  • For gnome-terminal

    • Edit /usr/share/applications/gnome-terminal.desktop file and add "--working-directory=$HOME" option to "Exec=gnome-terminal":

      # vim /usr/share/applications/gnome-terminal.desktop
      
      <snip>
      Exec=gnome-terminal --working-directory=$HOME   <<------
      Icon=utilities-terminal
      Type=Application
      X-GNOME-DocPath=gnome-terminal/index.html
      X-GNOME-Bugzilla-Bugzilla=GNOME
      X-GNOME-Bugzilla-Product=gnome-terminal
      <snip/>
      
  • For xterm

    • xterm does not have such config variable to change default working directory in it's configuration file.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments