TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Use the XDG Base Directory Specification

275 点作者 hyperupcall大约 2 年前

43 条评论

jenadine大约 2 年前
Somebody should tell that to the Rust people. They have a .cargo and a .rustup folder in ~, plus an extra heavy target folder for every project. Would be much nicer if they put the cache one .cache<p>But they don&#x27;t seem to care <a href="https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;cargo&#x2F;issues&#x2F;1734">https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;cargo&#x2F;issues&#x2F;1734</a> <a href="https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rfcs&#x2F;pull&#x2F;1615">https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rfcs&#x2F;pull&#x2F;1615</a> <a href="https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;cargo&#x2F;pull&#x2F;9178">https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;cargo&#x2F;pull&#x2F;9178</a>
评论 #35287056 未加载
评论 #35290539 未加载
评论 #35286904 未加载
评论 #35287661 未加载
评论 #35285992 未加载
BiteCode_dev大约 2 年前
It&#x27;s important on any system, not just XDG. The OS will assume you do, and offer features based on it, such as cleaning cache dirs, emptying temp dirs, etc.<p>It&#x27;s not just about being tidy, although it&#x27;s important.<p>But remembering all that stuff is annoying.<p>If you use Python, the wonderful &quot;appdirs&quot; package will make using the best dir for the job on Windows, Mac and Linux, easy and transparent: <a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;appdirs&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;appdirs&#x2F;</a><p>I wish it was part of the stdlib.<p>Another thing that grind my gears is people putting files inside their code project folder for development.<p>It should be something configurable, that by default use the OS dir for prod, and &quot;..&#x2F;var&quot; dir with everything on it in dev.<p>Less gitignore trouble, let&#x27;s watcher overhead, less indexing for nothing, less clutter in file explorers, less possibility for errors.<p>But you need to provide an easy way to locate those files, such as a cmd line entrypoints, otherwise it&#x27;s painful.
评论 #35289599 未加载
评论 #35289868 未加载
rektide大约 2 年前
One of the things that changed my life recently, that I hadn&#x27;t seen before: NeoVim has a NVIM_APPNAME variable that lets you change the app name.<p>So when I wanted to try AstroVim, I just set NVIM_APPNAME=astrovim, and dropped the files in ~&#x2F;.config&#x2F;astrovim instead of blowing up my existing (shitty) ~&#x2F;.config&#x2F;nvim.<p>I really wish the idea of configurable appnames was a part of the spec! (or a well-known extension!)
评论 #35286278 未加载
评论 #35289521 未加载
评论 #35287669 未加载
quicklime大约 2 年前
Does it really help that much in practice?<p>&gt; Easier to share configuration settings<p>I want to share my nvim config between both my home Linux machine and my Mac at work, but I don’t want to share my config for gnome and its apps. So now I’ve got to maintain a script to go one more subdirectory deep to pick which dotfiles to sync and which to ignore...<p>&gt; Easier to temporarily ignore the config &gt; It is easiest to set XDG_CONFIG_HOME=&#x2F;tmp&#x2F;dir<p>This is such an unreliable way to do it, even within the xdg world. What about stuff in ~&#x2F;.local&#x2F;share? It’s a lot easier and more reliable to just set HOME=$(mktemp -d)<p>Personally when I’m trying to start from a clean profile, I find it much easier to just go and blow away ~&#x2F;.mozilla than to go and surgically remove .config&#x2F;epiphany, .local&#x2F;share&#x2F;epiphany, .cache&#x2F;epiphany, and whatever gconf (or gsettings or whatever windows registry clone we’ve got now) settings it’s got.
评论 #35287558 未加载
评论 #35287536 未加载
agnos大约 2 年前
How did OP manage to get rid of ~&#x2F;.mozilla? It&#x27;s the only offending dotfile left in my $HOME and the stickiest. Until Mozilla fixes their 19-year-old feature request to support XDG [1], I couldn&#x27;t find a workaround that wasn&#x27;t a total hack.<p>[1] <a href="https:&#x2F;&#x2F;bugzilla.mozilla.org&#x2F;show_bug.cgi?id=259356" rel="nofollow">https:&#x2F;&#x2F;bugzilla.mozilla.org&#x2F;show_bug.cgi?id=259356</a>
评论 #35285962 未加载
sam_lowry_大约 2 年前
XDG sucks for the only reason that it is really difficult to configure user directories to one&#x27;s taste.<p>For instance, to get rid of Download, Templates, Desktop, Public Share, Documents, Music, Pictures, Videos directories I not only have to point them to somewhere else, I also have to make sure Desktop and Download do not point to the same directory, otherwise my config will not be used.<p>Here, after literally hours of researching, I figured the config that works:<p><pre><code> cat ~&#x2F;.config&#x2F;user-dirs.dirs XDG_DESKTOP_DIR=&quot;$HOME&#x2F;.Desktop&quot; XDG_DOWNLOAD_DIR=&quot;$HOME&#x2F;tmp&quot; XDG_TEMPLATES_DIR=&quot;$HOME&#x2F;tmp&quot; XDG_PUBLICSHARE_DIR=&quot;$HOME&#x2F;tmp&quot; XDG_DOCUMENTS_DIR=&quot;$HOME&#x2F;tmp&quot; XDG_MUSIC_DIR=&quot;$HOME&#x2F;tmp&quot; XDG_PICTURES_DIR=&quot;$HOME&#x2F;tmp&quot; XDG_VIDEOS_DIR=&quot;$HOME&#x2F;tmp&quot;</code></pre>
评论 #35289234 未加载
upofadown大约 2 年前
Yeah, we have a straightforward and widely established standard. Just put the related files in .programname .<p>Now let&#x27;s bikeshed and scatter them randomly across several places. To make it more fun let&#x27;s make those locations programmable with environment variables so you won&#x27;t even know where to start looking for a particular related file. Add lots of categories to create ambiguity. Make some of the default locations single level and others multiple level directories for no apparent reason for extra fun.
评论 #35289223 未加载
评论 #35289315 未加载
评论 #35299575 未加载
PrayagS大约 2 年前
<a href="https:&#x2F;&#x2F;github.com&#x2F;b3nj5m1n&#x2F;xdg-ninja">https:&#x2F;&#x2F;github.com&#x2F;b3nj5m1n&#x2F;xdg-ninja</a><p>This utility has been a lifesaver to clean up my home directory.
zamubafoo大约 2 年前
I completely agree with the article that more people should use the spec. I already do this for all my personal projects and nothing drives me up the wall more than seeing random config files strewn about.<p>It also provides an easy target for freeing disk space if you do run into issues (just `rm -r $XDG_CACHE_HOME`).<p>That said, I do think the spec would be improved by defining what constitutes a &quot;user-specific data file&quot; and how that is different from a &quot;user-specific state file&quot;. Wouldn&#x27;t &quot;user-specific data files&quot; just be &quot;files&quot; from a users perspective? I like the idea they have for this, but it&#x27;s kind of under defined.<p>Though that&#x27;s probably a good thing because no one wants a ontological tome to wade through when working on a bash script or the like.
000ooo000大约 2 年前
In what world is simply dumping config items for your app in the user&#x27;s home directory sensible? Why stop at config items? Do cache or temp crap too. The thought process of persisting with this baffles me. Microsoft would be absolutely ridiculed if one day your msword preferences appeared on your desktop as an XML file, and no matter what, it kept reappearing.
评论 #35285243 未加载
评论 #35287993 未加载
kitsunesoba大约 2 年前
The second example is a nice start, but I&#x27;d really like to see invisible files&#x2F;folders in ~&#x2F; done away with altogether.<p>So starting with that example, I might add a visible ~&#x2F;Library&#x2F; folder, then move ~&#x2F;.config&#x2F; and ~&#x2F;.local&#x2F; in there as ~&#x2F;Library&#x2F;Config&#x2F; and ~&#x2F;Library&#x2F;Local&#x2F; as normal visible folders. Same for .bashrc, .profile, etc; put them in ~&#x2F;Library&#x2F;Config&#x2F; without the dots.
评论 #35285152 未加载
评论 #35284549 未加载
评论 #35285046 未加载
评论 #35285106 未加载
评论 #35284999 未加载
eliaspro大约 2 年前
To clean up your home-dir from .dotfiles, theres xdg-ninja [1] which assists you to make all your applications to follow the XDG specs.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;b3nj5m1n&#x2F;xdg-ninja">https:&#x2F;&#x2F;github.com&#x2F;b3nj5m1n&#x2F;xdg-ninja</a>
ploum大约 2 年前
I was trying to lobby for those exactly… 14 years ago!<p><a href="https:&#x2F;&#x2F;ploum.net&#x2F;207-modify-your-application-to-use-xdg-folders&#x2F;index.html" rel="nofollow">https:&#x2F;&#x2F;ploum.net&#x2F;207-modify-your-application-to-use-xdg-fol...</a><p>Some things never change…
olalonde大约 2 年前
In case anyone else was wondering, XDG stands for X Desktop Group, an older name for freedesktop.org[0].<p>[0] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Freedesktop.org" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Freedesktop.org</a>
评论 #35286055 未加载
hamdouni大约 2 年前
I see some comments about users having a hard time cleaning their home directory and advices to use tools (boxxy?). But I read this post as an advice for developers not for users. A long crusade for standardisation may I say ;-)
WiSaGaN大约 2 年前
If you are using Rust, you can easily conform to this by using `directories` crate: <a href="https:&#x2F;&#x2F;docs.rs&#x2F;directories&#x2F;latest&#x2F;directories&#x2F;struct.BaseDirs.html" rel="nofollow">https:&#x2F;&#x2F;docs.rs&#x2F;directories&#x2F;latest&#x2F;directories&#x2F;struct.BaseDi...</a>
评论 #35294374 未加载
评论 #35286686 未加载
评论 #35285478 未加载
jbaber大约 2 年前
I have finally realized why so many people suddenly care about dotfiles in $HOME. I bet they&#x27;re all using GUI file managers.<p>So where I never see these things without an `ls -a`, modern linux users are double clicking a folder and have to scroll past hundreds of dotfiles.<p>Also explains the X in XDG.
评论 #35287444 未加载
Eduard大约 2 年前
&gt; ... State :... if the data is unique for a given machine, the file belongs [to $XDG_STATE_HOME &#x2F; $HOME&#x2F;.local&#x2F;state]<p>This statement is misleading&#x2F;wrong. Like all other XDG stuff, it&#x27;s not about the machine, it&#x27;s about the particular user.<p>Also, why does the author consider the given positive example clean and tidy, when it has files .profile and .bashrc placed directly in the user&#x27;s home directory? Following the rules, these files should be within the .config&#x2F; directory as well.
评论 #35284801 未加载
评论 #35286097 未加载
评论 #35284681 未加载
评论 #35285108 未加载
评论 #35284745 未加载
fiddlerwoaroof大约 2 年前
I strongly disagree: the dot files cause very little inconvenience because they’re typically hidden and they’re easier to type and list than the XDG spec stuff
评论 #35284330 未加载
评论 #35285233 未加载
评论 #35284399 未加载
评论 #35284989 未加载
评论 #35285595 未加载
评论 #35284996 未加载
评论 #35284493 未加载
shmerl大约 2 年前
Yes!<p>Some projects are stuck for years trying to implement this. Firefox for example.<p>&gt; .audacity-data<p>Recent Audacity already fixed this.
评论 #35285456 未加载
goombacloud大约 2 年前
There is a changed version that includes drop-in config files, masking, and loading defaults from &#x2F;usr&#x2F; instead of requiring full config files to live under &#x2F;etc: <a href="https:&#x2F;&#x2F;uapi-group.org&#x2F;specifications&#x2F;specs&#x2F;base_directory_specification&#x2F;" rel="nofollow">https:&#x2F;&#x2F;uapi-group.org&#x2F;specifications&#x2F;specs&#x2F;base_directory_s...</a>
评论 #35286285 未加载
评论 #35290236 未加载
throw7大约 2 年前
How about you stay out of my damn house?<p>I&#x27;m pretty sure I popped a vessel the day these freakin&#x27; directories spammed my home directory.
PhilipRoman大约 2 年前
I just wish they didn&#x27;t needlessly introduce asymmetry with new names like .config. What&#x27;s wrong with .local&#x2F;etc?
okasaki大约 2 年前
A couple of years ago I wanted to use xdg dirs in a Python app I was writing. There are seemingly two packages for this, neither of which I could get to work.<p>Overall I don&#x27;t think xdg dirs on Linux are really as amazing as some people think. For example it is said that one can just back up the config dir to carry all the configuration over to the next install, but apps often dump the default configuration into the config dir, which you don&#x27;t want to carry to the next install (which will have different versions, so probably a different default config) because that might break stuff. In the end you have to carefully look over all the configuration to see what&#x27;s worthwhile to take with you, and it doesn&#x27;t really matter if that&#x27;s in ~&#x2F;.appname or ~&#x2F;.config&#x2F;appname
评论 #35289990 未加载
评论 #35287581 未加载
johnchristopher大约 2 年前
Oh yeah, I used to do that and diligently configured vim and others apps to use $XDG_{DATA_HOME,CONFIG_HOME}. Lots of razor cuts and more maintenance annoyances, not worth the time. I reverted to using the defaults on each new machine I configure these days.
larusso大约 2 年前
Oh I‘m fighting the battle for a clean home directory for years. I even use a setup on macOS to set specific environment variables via systemd during login so I can link them into the .config directory.<p>Only issue with my setup in general is that I can‘t just replicate it for other people. I moved .aws directory in .config&#x2F;aws and I sometimes forget what the default for most tools is or where I helped the tool out to „find the right path“.<p>I also make sure when writing scripts&#x2F;cli tools to use the XDG spec. In rust I use the dirs crate for example. I even go so far to never hardcode it for my own config scripts&#x2F;files just in case I think about going from ~&#x2F;.config to ~&#x2F;.my_configurations or whatever.
评论 #35286478 未加载
tooltower大约 2 年前
I have a very dumb question: why does the article use `find` with `printf` and depth specification, as opposed to the simpler `ls -a`? I&#x27;m assuming it has something to do with portability, but `ls -a` is already in POSIX. I&#x27;m a bit confused.
评论 #35286703 未加载
评论 #35308867 未加载
评论 #35286309 未加载
moasda大约 2 年前
Lazarus (<a href="https:&#x2F;&#x2F;www.lazarus-ide.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.lazarus-ide.org&#x2F;</a>) has built-in support for the configuration folder ($XDG_CONFIG_HOME) in the user context and in the global context:<p>GetAppConfigDir() and GetAppConfigFile()<p>For more details see <a href="https:&#x2F;&#x2F;wiki.lazarus.freepascal.org&#x2F;Multiplatform_Programming_Guide#Configuration_files" rel="nofollow">https:&#x2F;&#x2F;wiki.lazarus.freepascal.org&#x2F;Multiplatform_Programmin...</a>
cassepipe大约 2 年前
Once upon a time, there was a distribution called GoboLinux <a href="https:&#x2F;&#x2F;gobolinux.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;gobolinux.org&#x2F;</a>
kkfx大约 2 年前
A small note I do not have seen so far in comments here: the article told about &quot;easier backup&quot;, actually I strongly disagree. I do keep <i>some</i> configs I&#x27;ve write myself&#x2F;edited myself. Most of the rest are automatically made stuff useless to be backed up and sometimes also inopportune to restore since a version to another some (cr)applications do badly digest their own automatic config.
fweimer大约 2 年前
My one gripe is that many systems do not provide a writable XDG_RUNTIME_DIR in all cases because the requirements in the specification are impossible to meet at the same time (the specification does not acknowledge the existence of “su --login”). This means that applications still need fallback code, which historically has been buggy (e.g., using shared &#x2F;tmp without safeguards).
transfire大约 2 年前
I have been a staunch supporter of XDG basedir standard for many years. Unfortunately it has become clear to me that it is simply not enough. So instead I have started to abandon home as the place to store <i>my</i> files. I use a subdirectory in home instead, the name of which is purposefully non-specific.
rtontic大约 2 年前
I actually just make my personal home directory in the root of the filesystem. So &#x2F;me. If &#x2F;root can have it, why can&#x27;t I? It is my machine after all.
评论 #35287614 未加载
评论 #35288036 未加载
prussian大约 2 年前
I&#x27;d say for windows, you&#x27;d probably want to define them as well since a lot of ports will use HOME, XDG_* and other non-windowsy environment variables anyhow.
评论 #35286694 未加载
mugr大约 2 年前
I also find it very daunting having lying around all sorts of history files I never use like bash, wget and even less.
rapiz大约 2 年前
I have been long expecting a daemon that picks up scattered config files and make soft links to ~&#x2F;.config
butz大约 2 年前
Does Flatpak solve this issue to some point, at least when using fully sandboxed apps?
AnIdiotOnTheNet大约 2 年前
Considered opinion from decades of desktop computer usage:<p>Trying to use paths to meaningfully separate data by type is a fool&#x27;s errand and no one will ever get it &quot;right&quot;. It is the primary thing UNIX systems got extremely wrong that not only holds them back in the personal desktop space, but through cultural cross pollination has been ruining other desktop OSs too.<p>Original single-user desktop OSs had the best solution: keep everything related to the application functionality with the application. The application (in AppDir&#x2F;file with resource fork&#x2F;whatever form) itself can be wherever the user feels like putting it, and saved documents go wherever the hell the user feels like putting them. The only exception should be cache and temp data, which should go somewhere global.<p>This has the benefit of being clear and obvious to the user.<p>The obvious objections:<p>&gt; but multiuser!<p>Is a use case that basically doesn&#x27;t exist in personal desktop space. To the extent it was ever a useful concept it was during a time when a desktop computer was the only way to access the internet and they were too expensive and bulky to justify more than one in a home. Even then, we managed fine without OS level multiuser support.<p>To the extent that anything like a multiuser desktop exists it is certainly a niche, and therefore we should handle its problems with virtualization, containerization, filesystem overlay hackery, etc.<p>&gt; but ease of backup!<p>Depends entirely on what cross section of things you care about backing up. As it is you already have to search dozens of places for including what you want and have rules for excluding what you don&#x27;t and no standard is ever going to fix that. Applying those same things to the &quot;everything with the application&quot; model is, at worst, not any worse than things already are.<p>&gt; but if I copy the application, it also copies the config.<p>That&#x27;s a decent point, but I would argue this is the obvious thing and also perhaps what is intended. Solution is to have a standardized mechanism of clearing out the config and other state from the application directory, such that it can be done with a right-click context menu. A factory reset of the application if you will.<p>&gt; but I never use a mouse and only use the GUI as a really fancy tmux<p>That&#x27;s fine, nothing about this model makes your life conceptually any harder. Keep all the applications in directories in your PATH. Factory reset of the application can be just as easily done with a command as a context menu entry. You can still put applications in repos and even overengineer a package manager for them if you really want to.
fs111大约 2 年前
Back in the old days I could delete `.&lt;whatever&gt;` and reset a program to its defaults. Now I have to navigate through `.config` and try to find where stuff is. How is this better?
评论 #35289637 未加载
评论 #35289517 未加载
jannes大约 2 年前
On macOS there is also this standard:<p>~&#x2F;Library&#x2F;Application Support&#x2F;AppName<p>With 3 competing standards it&#x27;s unlikely that this will ever be resolved.
eviks大约 2 年前
Weird how this promotional article is weak re advice for the most popular OS (and personal experience isn&#x27;t the only source of insight)
评论 #35285817 未加载
jojo14大约 2 年前
XDG specs are crap. Sure one single ~&#x2F;.config folder is a very good idea. But I want it clearly visible such as ~&#x2F;config. But I don&#x27;t want an additional and confusing ~&#x2F;.local.<p>Plus I don&#x27;t want ~&#x2F;Videos or ~&#x2F;Pictures folders. I am not dumb. Let me organize my folders according to my needs and my will.<p>The first thing I do when I setup a user account is removing those useless XDG folders.<p>XDG pretend to remove folder clusterfuck then why do they add their crappy folders?
评论 #35285758 未加载
alphazard大约 2 年前
I&#x27;ll take the other side of this. We have this concept of applications being &quot;well behaved&quot; if they only read and write from parts of the filesystem that users expect. The XDG directories are what most linux and macOS users expect, even if they don&#x27;t know about the standard. This well-behavedness feeds into the larger idea of high quality software. Hiqh quality means users are more likely to recommend it, engineers are more likely to respect the application&#x27;s authors, etc.<p>The problem with this is that it&#x27;s all socially enforced, but it&#x27;s not a social problem, it&#x27;s a technical problem. The issue isn&#x27;t that we haven&#x27;t put enough pressure on developers to read the correct environment variables. It&#x27;s that we have such a poor isolation story on UNIX that we have to care about where applications read and write from, rather than letting them do whatever they want in a sandbox.<p>Many of the open source docker images are on the right track here. Where does the persistent state go? &#x2F;data. Where does the configuration go? &#x2F;config. Where does the cached data go? &#x2F;cache. All in the most obvious places right at the filesystem root. Those applications would be considered &quot;badly behaved&quot; outside the container, but inside, it&#x27;s much easier to predict what they will do.
评论 #35289391 未加载
评论 #35288338 未加载