如何设置Gnome使用自定义文件夹作为桌面文件夹

问题介绍

重装系统后发现系统使用的是home作为桌面文件夹,这也太危险了,这可不是软连接,删掉了可真删掉了!所以查询如何处理。

造成原因

一个桌面环境的配置文件被改动了。

解决方案

Short answer:

  1. vim ~/.config/user-dirs.dirs

打开这个文件时可以看到,这里实际上被修改到了$HOME,你改到你想要的文件夹就可以了

Long answer:

How to disable/relocate the User Directories (Desktop, Pictures, Documents etc) ?

On a freedesktop compliant DE this is done via the XDG user directories configuration file, namely $(XDG_CONFIG_HOME)/user-dirs.dirs:

$(XDG_CONFIG_HOME)/user-dirs.dirs specifies the current set of directories for the user.

If not set or empty, XDG_CONFIG_HOME defaults to ~/.config so, for most users, the file in question is ~/.config/user-dirs.dirs.

Applications read this file to find those directories. The file consists of key=value pairs, one per line.

The default locations are:

XDG_DESKTOP_DIR="$HOME/Desktop"
XDG_DOCUMENTS_DIR="$HOME/Documents"
XDG_DOWNLOAD_DIR="$HOME/Downloads"
XDG_MUSIC_DIR="$HOME/Music"
XDG_PICTURES_DIR="$HOME/Pictures"
XDG_PUBLICSHARE_DIR="$HOME/Public"
XDG_TEMPLATES_DIR="$HOME/.Templates"
XDG_VIDEOS_DIR="$HOME/Videos"

To relocate a certain directory edit the config file and replace the current value with the location of your choice, e.g.

XDG_DOCUMENTS_DIR="/run/media/mybackupdrive/documents"

To disable a certain directory point it to the home directory:

XDG_DESKTOP_DIR="$HOME"

For those who prefer a CLI tool, XDG provides xdg-user-dirs:

Relocate VIDEOS:

xdg-user-dirs-update --set VIDEOS /media/bkdrive/myvideos

Query current location for VIDEOS:

xdg-user-dir VIDEOS

/media/bkdrive/myvideos

Note:

After configuring user-dirs.dirs, if some User Dirs are on drives that are not accessible at startup you might want to disable /etc/xdg/user-dirs.conf (if present on your system), i.e. edit the enabled line to read:

enabled=False

see this discussion for more details.


个人设置:

$ cat ~/.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/Share"
XDG_DOCUMENTS_DIR="$HOME/Documents"
XDG_MUSIC_DIR="$HOME/Music"
XDG_PICTURES_DIR="$HOME/Pictures"
XDG_VIDEOS_DIR="$HOME/Video"

参考链接