如何在不破坏程序的情况下将大量点文件移动到/home?

huangapple go评论85阅读模式
英文:

How to move lots of dotfiles staying at /home without breaking programs?

问题

以下是您要翻译的内容:

"With more and more programs installed on my computer, I am tired of seeing lots of dotfiles while I have to access them often. For some reason I won't hide dotfiles when browsing files. Is there a way to move them to a better place I want them to stay (e.g. ~/.config/$PROGCONF) without affecting programs while running?

Symlinks still leave file symbols, which is far from my expectation. I expect that operations like listdirs() won't show the files while opening them uses a redirection."

英文:

With more and more programs installed on my computer, I am tired of seeing lots of dotfiles while I have to access them often. For some reason I won't hide dotfiles when browsing files. Is there a way to move them to a better place I want them to stay (e.g. ~/.config/$PROGCONF) without affecting programs while running?

Symlinks still leave file symbols, which is far from my expectation. I expect that operations like listdirs() won't show the files while opening them uses a redirection.

答案1

得分: 0

"For some reason it won't hide dotfiles when browsing files.":

这取决于您使用的文件管理器。nautilus 默认隐藏它,大多数文件管理器都有一个“显示/隐藏隐藏文件”的选项。ls 命令默认情况下排除隐藏文件(以点开头的文件)。它会列出所有文件的选项是 -a

"Is there a way to move them to a better place":

支持“XDG用户目录”的程序可以将其配置文件存储在 ~/.config/$PROGRAM_NAME/ 中。如果程序不支持此功能并且希望配置文件位于主目录中,那么您几乎无法做任何事情(也许您可以告诉我们想要移动哪些程序的配置文件)。每个程序的处理方式都不同。

让我以 vim 为例。它的配置文件是 ~/.vimrc。假设您将文件移动到 ~/.config/vim/.vimrc。您可以通过使用以下命令启动 vim 来使 vim 读取该文件。
vim -u ~/.config/vim/.vimrc
您可以修改.desktop条目或创建一个新的 shell 脚本,以使用上述命令启动 vim,并将其放在/usr/local/bin/中,或者创建 shell 函数/别名。您可以在此SO问题中了解有关更改 vim 配置文件位置的更多信息。

arch wiki文章提供了应用程序特定的信息。

"without affecting programs while running":

这取决于一些因素,主要是所使用的文件系统、所处理的程序等。

通常,删除/移动文件只会取消链接文件名与索引节点,程序使用索引节点读取/写入文件。在程序启动时,它们很少再次读取配置文件。因此,如果您在程序运行时移动配置文件(假设程序支持两个位置的配置),您不会在重新启动程序之前看到任何变化。

"I expect that operations like listdirs() won't show the files":

我假设您在谈论 Python 中的 os.listdir()。如果文件存在,os.listdir() 将列出它们,对此您几乎无法进行更改。但您可以编写自定义函数来排除要列出的隐藏文件。此SO问题可以帮助您实现这一点。

英文:

>"For some reason it won't hide dotfiles when browsing files.":

That depends on the file manager you use. nautilus hides it by default and most file managers have an option to "show/hide hidden files". The ls command by default omits out hidden files (files starting with a dot). It lists all files with the option -a.

>"Is there a way to move them to a better place":

Programs which have support for "XDG user directories" can store their config files in `~/.config/$PROGRAM_NAME/. If the program doesn't support that and expects the config file to be present in the home directory, there is little you can do (Maybe you can give us a list of what programs' config files you want to move). The process differs for each program.

Let me give an example with vim. Its config file is ~/.vimrc. Lets say you move the file to ~/.config/vim/.vimrc. You can make vim read the file by launching vim using the following command.

vim -u ~/.config/vim/.vimrc

You can modify the .desktop entry or create a new shell script to launch vim using the above command and put it inside /usr/local/bin/ or create shell functions / aliases. You can read more about changing vim's config file location in this SO question.

This arch wiki article has application specific information.

>"without affecting programs while running":

It depends on a few factors namely the file system used, the program we are dealing with and so on.

Generally, deleting / moving files only unlinks the file name from an inode and programs read / write files using inodes. Read more here. And most programs read the config file at the start, load the values into memory. They rarely read the config files again. So, if you move your config file while the program is running (assuming the program supports config in both places), you won't see a difference until the program is restarted.

> "I expect that operations like listdirs() won't show the files"

I am assuming you are talking about os.listdir() in python. If files are present, os.listdir() will list them, there is little you can change about that. But you can write custom functions to omit out the hidden files from being listed.
This SO question can help with that.

huangapple
  • 本文由 发表于 2023年2月8日 17:29:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75383674.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定