How to get language variables (Desktop folder name, Document folder name, etc..)

Solution 1:

There is a tool called xdg-user-dir that retrieves user directories paths

documents_path=$(xdg-user-dir DOCUMENTS)
echo $documents_path

From the docs:

xdg-user-dir looks up the current path for one of the special XDG user dirs.

This command expects the name of an XDG user dir as argument. The possible names are:

  • DESKTOP
  • DOWNLOAD
  • TEMPLATES
  • PUBLICSHARE
  • DOCUMENTS
  • MUSIC
  • PICTURES
  • VIDEOS

I'm using Ubuntu 16.04, I don't really know if this is available in previous releases.

Solution 2:

The common folder names are as follows. Just extracted from a file in home directory.

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/"
XDG_VIDEOS_DIR="$HOME/Videos"

Of course, you are only interested in the variable name. So there are XDG_DESKTOP_DIR, XDG_DOWNLOAD_DIR, .... etc.

Related question: How can I change the default location of content directories (eg Pictures, Templates, Music) in my home folder?

Hope this will help.