Linux desktop files directory

Where is the path to the current user’s desktop directory stored?

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?

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 /home/arnie97/桌面 

(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 $/user-dirs.dirs && source $/user-dirs.dirs echo $ echo $

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

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 .

Читайте также:  Linux utf8 to utf16

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//Desktop You can go to it through the command line like this: cd /home//Desktop Viewing files is a simple as using the command «ls» without the quotation marks.

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:

# 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/Escritorio" XDG_DOWNLOAD_DIR="$HOME/Descargas" XDG_TEMPLATES_DIR="$HOME/Plantillas" XDG_PUBLICSHARE_DIR="$HOME/Público" XDG_DOCUMENTS_DIR="$HOME/Documentos" XDG_MUSIC_DIR="$HOME/Música" XDG_PICTURES_DIR="$HOME/Imágenes" XDG_VIDEOS_DIR="$HOME/Vídeos" 

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 = <>if(fs.existsSync(file)) < 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)< try< data[line.substring(0,i)] = JSON.parse(line.substring(i + 1)) >catch(e)<> > > > if(data["XDG_DESKTOP_DIR"])< let desktop = data["XDG_DESKTOP_DIR"] desktop = desktop.replace(/\$([A-Za-z\-\_]+)|\$\<([^\<^\>]+)\>/g, (_, a, b) => (process.env[a || b] || "")) return desktop >else < return Path.join(Os.homedir(),"Desktop") >> 

Источник

Why do we have .desktop files?

I wonder why do we have .desktop files, I downloaded a trivial .jpg picture from internet (yes, I’m a newbie, currently learning command line), and saw that when I list the file, I saw .desktop extension even if I move that file to the documents etc. How necessary are they? What functionality do they constitute? How to remove them?

Burak, I’d be interested to see the output of ls Desktop and if possible a desktop screenshot! It would be nice to see if there is an issue and something odd downloaded.

What probably happened is actually that you created a .desktop format shortcut on your Desktop, to that picture’s original URL online.

@Tim Here, I took a screenshot of what you might probably wanted(i58.tinypic.com/epg66x.png). In the original form, instead of rabbit.jpg, its format was, .jpg.desktop, however, before asking the question I removed it unconsciously because I didn’t know what was that 🙂

4 Answers 4

.desktop files are very important. When you search the Dash for programs, or click a program in the Launcher at the side, you are using a .desktop file.

In Ubuntu, most programs can be launched with a command from terminal — for example firefox can be opened with the command firefox in terminal, and Chrome is google-chrome .

A .desktop launcher does this for you. When you click, it runs the command — so you don’t have to interact with the terminal at all.

This is a basic .desktop file. The # signs are comments that I’ve added.

[Desktop Entry] # Tell the computer what file this is (a launcher) Encoding=UTF-8 Version=1.0 Type=Application # Specifies what to do when clicked (there is also Link and Directory). Terminal=false # Whether to open a terminal and run the command, or just run without Exec=firefox # The command to run Name=Firefox # A name to display Icon=/usr/share/icons/firefox.png # Location of the icon 

These files are clearly important — and you can create them yourself to run custom commands.

You can put one of these files (from /usr/share/applications ) onto the «Desktop» and then use that to launch the program. It sounds like what you did was the following:

  1. There is already a .desktop file, unrelated to the following download.
  2. You download a file — and then list the files and see something like this:
firefox.desktop trivial.jpg My Document.odt 

Источник

Оцените статью
Adblock
detector