Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can i get the path to the given users desktop?

I used this:

echo $(awk "NR==$(awk 'BEGIN {FS=":"} {print $3}' /etc/passwd | awk "/^$(id -u USERSNAMEHERE)$/ {print NR}")" /etc/passwd | awk 'BEGIN {FS=":"} {print $6}')/Desktop

are there any better ones?

What if the users Desktop's name isn't "Desktop"?

Thank you!

p.s.: using Fedora 14 but are there any "general" methods to find out the given users desktop?

share|improve this question

Try xdg-user-dirs.

That page has an example that should work for the current user:

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

Also, if you have to read /etc/passwd, it's better to use the output of getent passwd, because some user data might be stored in NIS, LDAP, or some other database.

Combining that so it works for a user called USERSNAMEHERE:

USERDIR=$(getent passwd $USER | cut -f 6 -d :)
echo "${XDG_DESKTOP_DIR:-$USERDIR/Desktop}"
share|improve this answer

Your command is impossibly complex.

Here is a simplified version:

getent passwd USERNAME | awk -F: '{print $6 "/Desktop"}'

Here is an untangled version of your original:

awk -v "id=$(id -u USERNAME)" -F: '{if ($3 == id) print $6 "/Desktop"}' /etc/passwd


awk -v "name=USERNAME" -F: '{if ($1 == name) print $6 "/Desktop"}' /etc/passwd
share|improve this answer
What if the users Desktop's name isn't "Desktop"? – quanta Oct 14 '11 at 0:40

the path is $HOME/Desktop

test by echo hello > $HOME/Desktop/testing.txt

share|improve this answer

You're making it way more complex than it has to be. ~UserName is an alias for UserName's home directory.

Use ~UserName/Desktop.

share|improve this answer
They specifically asked for a general and correct way, which also handles the case where the directory is not called "Desktop". – Mikel Jan 19 '11 at 14:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.