相比於Windows的顯示中文,但實際路徑是英文,Ubuntu的中文目錄的實際路徑也是中文,這樣一來在終端輸入路徑的實際還要切換輸入法,相當麻煩,為什么會產生這樣的結果?
原來這是freedesktop.org為了方便群眾搞的xgd-users-dirs ,在不同的語言下自動創建一些經常用到的目錄。xdg-user-dirs-update 這個工具會在系統登錄階段運行,它讀取配置文件和用戶目錄信息,並創建用戶本地語言版本的常用目錄。設置 到$(XDG_CONFIG_HOME)/user-dirs.dirs (XDG_CONFIG_HOME defaults to ~/.config),以便應用程序讀取和使用這些目錄。
本文旨在將Ubuntu的目錄的顯示方式改為類似Windows。
1. 我們可以先將目錄都改成英文的。
export LANG=en_US
執行
xdg-user-dirs-gtk-update
這時會彈出一個配置界面,將所有中文的用戶目錄切換到英文。選中不再提示,確定。
這時,會刪除沒有內容的用戶目錄,但有內容的用戶目錄會保持。並創建相應的英文目錄:
Desktop/Download/Templates/Public/Documents/Music/Pictures/Videos
此時,在位置里看到的常用中文目錄已經換成英文目錄。只需將原中文目錄的內容拷貝到相應英文目錄,並刪除中文目錄即可。
然后再執行
export LANG=zh_CN.UTF-8
以顯示中文。
如果記不住該命令,很簡單。注銷。在登錄界面選英語,進來后該對話框就會彈出來提示你是否切換用戶目錄了。切換完了注銷,再切換成中文界面,但這時 不要切換用戶目錄了。
2.顯示中文,但實際是英文目錄
這時,桌面也對應/home/zhouhh/Desktop,但“位置”里面,“主文件夾”,“桌面”點開都對應英文目錄。
理想化的解決方案,是看到的目錄是中文,但打開的目錄是英文。和Windows操作系統一致。這樣免得中英夾雜,影響視覺和心情。
其實這也是可以辦到的。
點“位置”->"主文件夾",打開文件瀏覽器(Nautilus),
在書簽菜單,選編輯書簽
這時,可以將各英文用戶目錄的顯示改成中文對應的“桌面”,“文檔”,圖片 、公共的 、下載、 音樂、 視頻等。
這樣,書簽里顯示的都是中文目錄了。
3.相關配置 cd /etc/xdg
zhouhh@zhh64:/etc/xdg$ ls user*
user-dirs.conf user-dirs.defaults
zhouhh@zhh64:/etc/xdg$ vi user-dirs.defaults
# Default settings for user directories
#
# The values are relative pathnames from the home directory and
# will be translated on a per-path-element basis into the users locale
DESKTOP=Desktop
DOWNLOAD=Downloads
TEMPLATES=Templates
PUBLICSHARE=Public
DOCUMENTS=Documents
MUSIC=Music
PICTURES=Pictures
VIDEOS=Videos
# Another alternative is:
#MUSIC=Documents/Music
#PICTURES=Documents/Pictures
#VIDEOS=Documents/Videos
該文件是xdg-user-dirs-update工具在用戶登錄時需要讀取的目錄配置。並根據user-dirs.conf決定如何翻譯。
zhouhh@zhh64:/etc/xdg$ vi user-dirs.conf
# This controls the behaviour of xdg-user-dirs-update which is run on user login
# You can also have per-user config in ~/.config/user-dirs.conf, or specify
# the XDG_CONFIG_HOME and/or XDG_CONFIG_DIRS to override this
#
enabled=True
# This sets the filename encoding to use. You can specify an explicit
# encoding, or "locale" which means the encoding of the users locale
# will be used
filename_encoding=UTF-8
這是系統的缺省編碼設置和是否啟用設置。用戶的在/home/zhouhh/.config下面。
可以由XDG_CONFIG_HOME XDG_CONFIG_DIRS 指定路徑來讀取配置。
zhouhh@zhh64:~$ vi .config/user-dirs.dirs
# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
#
XDG_DESKTOP_DIR="$HOME/Desktop"
XDG_DOWNLOAD_DIR="$HOME/Downloads"
XDG_TEMPLATES_DIR="$HOME/Templates"
XDG_PUBLICSHARE_DIR="$HOME/Public"
XDG_DOCUMENTS_DIR="$HOME/Documents"
XDG_MUSIC_DIR="$HOME/Music"
XDG_PICTURES_DIR="$HOME/Pictures"
XDG_VIDEOS_DIR="$HOME/Videos"
可以看到我的配置都已經是英文了。
參考:http://www.cnblogs.com/xiaofengkang/archive/2011/11/08/2240637.html
http://blogs.gnome.org/simos/2007/11/11/localisation-issues-in-home-directory-folders-xdg-user-dirs/