I am very new to linux and am going through and learning all the basics. While I was doing so I realized how odd it was that the OS treats certain files differently--namingly by displaying them on the GUI desktop enviroment if they happen to be the desktop file associated with the currently logged in user. How does the OS know the path variable to the current user's desktop directory? For hacker amusment can it be changed such that any arbitrary directory will be displayed on the GUI desktop?

  • Typically ~/Desktop
    – ivanivan
    Sep 13, 2017 at 2:55

5 Answers 5


The default path for the desktop directory varies between different languages. Hence a better guess than $HOME/Desktop could be obtained from xdg-user-dir in case that exists on your system:

$ xdg-user-dir DESKTOP

(Note that the package name is xdg-user-dirs, while the executable name is xdg-user-dir. Thank @theDrake for pointing this out.)

There's also another way described on the xdg-user-dirs home page, which unfortunately does not work on my system:

Here is a shellscript example of how to find the desktop and the download directory:

test -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs && source ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs
echo ${XDG_DESKTOP_DIR:-$HOME/Desktop}

For application code the hope is that the various desktops will integrate this and have a nice API to find these directories.

  • On my Arch Linux system, the command is xdg-user-dir (no "s" at the end).
    – theDrake
    Nov 19, 2021 at 7:16
  • @theDrake Well spotted. Now I've updated the command name in this answer.
    – Arnie97
    Nov 24, 2021 at 6:11

Generally, in GNU/Linux (as in Unix), the user's Desktop directory can be specified with ~/Desktop. The shorthand ~/ will expand to whatever the home directory is, such as /path/to/home/username.

I should clarify that most shells (e.g. bash, ksh, csh, etc.) will expand ~ to the home directory, but not all of them (e.g. rc). The tilde is a literal character, so you can have a file ~filename; therefore, the shell must be designed to expand the tilde under certain conditions.


The path for most distributions (I say most and not all because Linux (or GNU/Linux), is nothing if not mutable, for good or ill), is going to be /home/<user name>/Desktop You can go to it through the command line like this: cd /home/<username>/Desktop Viewing files is a simple as using the command "ls" without the quotation marks.

  • This is not true as it varies between languages.
    – phil294
    Jul 17, 2023 at 6:46

The desktop directory is different according to language of system. Adding to options given for other person, you can find the file ~/.config/users-dirs.dirs

Example you can read the content:

cat ~/.config/users-dirs.dirs

In my machine shows this:

# 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.

How you can see my desktop directory is: "$HOME/Escritorio" where $HOME is an environment variable that refers to your home folder. In practice:

cd ~/Escritorio 
# is the same 
cd "$HOME/Escritorio"

If you are interested in getting desktop dir by programming, you can read the file and parse the content. For example look my javascript code for get desktop directory:

async getLinuxDesktop(){
    let file = Path.join(Os.homedir(), ".config", "user-dirs.dirs")
    let data = {}
        let content = await fs.readFileAsync(file,"utf8")
        let lines = content.split(/\r?\n/g).filter((a)=> !a.startsWith("#"))
        for(let line of lines){
            let i = line.indexOf("=")
            if(i >= 0){
                    data[line.substring(0,i)] = JSON.parse(line.substring(i + 1))
        let desktop = data["XDG_DESKTOP_DIR"]
        desktop = desktop.replace(/\$([A-Za-z\-\_]+)|\$\{([^\{^\}]+)\}/g, (_, a, b) => (process.env[a || b] || ""))
        return desktop
        return Path.join(Os.homedir(),"Desktop")

This depends on your Desktop Environment:

If you use a Window Manager, you can use different tools to display stuff on your desktop, e.g. PCmanFM desktop.

Most tools and Desktop Environments do respects your xdg-user-dir DESKTOP settings.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .