Stranger in the Q
Stranger in the Q

Reputation: 3898

How to get desktop folder of specified user in red hat Linux shell script

For installation purposes I need to locate desktop folders of all Linux with Qvwm users on current machine.

I have the following script:

HOMES=`getent passwd | cut -d: -f6`
SHORTCUT=/path/to/shortcut.desktop
find $HOMES -maxdepth 3 -name "Desktop" -exec cp $SHORTCUT {} \;

But I understood that user desktop folder may differ from "Desktop".

The question is: how I can determine the correct path to desktop folder of all/specified user in system.

Thanks for you suggestions..

Upvotes: 0

Views: 651

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295472

For any desktop environment following the XDG Base Directory Specification and compatible with the xdg-user-dirs reference implementation, this might look as follows:

sudo -u "$user" -i bash -l <<'EOF'
  user_dirs_file=${XDG_CONFIG_HOME:-$HOME/.config}/user-dirs.dirs
  [[ -s $user_dirs_file ]] && . "$user_dirs_file"
  printf '%s\n' "${XDG_DESKTOP_DIR:-$HOME/Desktop}"
EOF
  • If XDG_CONFIG_HOME is set by the user's dotfiles, the configuration file specifying the location of their home directory will be set in the directory thus named; otherwise, the file exists in ~user/.config.
  • If $XDG_CONFIG_HOME/user-dirs.dirs exists and contains an assignment to XDG_DESKTOP_DIR, the result of that assignment shall be used as the user's desktop directory.
  • If no such file exists, or no such assignment exists, the desktop directory shall be $HOME/Desktop.

Upvotes: 2

Related Questions