首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bash脚本以存储不处理主文件夹或现有文件夹根目录中的文件的Linux配置文件

Bash脚本以存储不处理主文件夹或现有文件夹根目录中的文件的Linux配置文件
EN

Stack Overflow用户
提问于 2017-08-20 15:41:55
回答 2查看 4.4K关注 0票数 2

基本上,我试图使用GNU Stow轻松地将dotfiles / config文件同步到我的主目录。每个配置都存储在相对于我的主目录的命名文件夹中。例如,vim/.vimrci3/.config/i3/config。其中一些文件夹有多个文件。

脚本

代码语言:javascript
复制
#!/usr/bin/env bash

# This script will Stow all the dotfiles located in the ~/dotfiles folder.
# The -R flag is used to force a 'restow' which will remove any existing symlinks before attempting to Stow.

echo "Stowing Dotfiles...";

cd ~/.dotfiles
for file in ~/dotfiles/*; do
  # Only run Stow on the directories in the dotfiles folder and not the individual files.
  # Using 'basename' strips the filepath from the directory name. 
  if [ -d ${file} ]; then
    stow -R $(basename $file)
    echo "$(basename $file) stowed."; 
  fi
done

# Return back to the your PWD from before you ran the script
cd ~- 

echo 'All stowed';

当我运行此程序时,~/.config文件夹中的某些文件或目录将被存储。但是,如果文件存在,它似乎不会被存放。此外,我的主目录根目录中的文件似乎没有被存储,比如bash/.bashrc和所述dir中的其他文件。

输出

代码语言:javascript
复制
Stowing Dotfiles...
stow_all.sh: line 8: cd: /home/devon/.dotfiles: No such file or directory
WARNING! unstowing bash would cause conflicts:
  * existing target is neither a link nor a directory: .bash_aliases
  * existing target is neither a link nor a directory: .bashrc
WARNING! stowing bash would cause conflicts:
  * existing target is neither a link nor a directory: .bash_aliases
  * existing target is neither a link nor a directory: .bashrc
All operations aborted.
bash stowed.
bin stowed.
compton stowed.
WARNING! unstowing fonts would cause conflicts:
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Bold Italic for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Bold for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Italic for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Light Italic for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Light for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Medium Italic for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Medium for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Thin Italic for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Thin for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Bold.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-BoldItalic.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Italic.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Light.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-LightItalic.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Medium.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-MediumItalic.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Regular.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Thin.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-ThinItalic.ttf
WARNING! stowing fonts would cause conflicts:
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Bold Italic for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Bold for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Italic for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Light Italic for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Light for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Medium Italic for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Medium for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Thin Italic for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono Thin for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/Roboto Mono for Powerline.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Bold.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-BoldItalic.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Italic.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Light.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-LightItalic.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Medium.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-MediumItalic.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Regular.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-Thin.ttf
  * existing target is neither a link nor a directory: .local/share/fonts/RobotoMono-ThinItalic.ttf
All operations aborted.
fonts stowed.
WARNING! unstowing git would cause conflicts:
  * existing target is neither a link nor a directory: .gitconfig
WARNING! stowing git would cause conflicts:
  * existing target is neither a link nor a directory: .gitconfig
All operations aborted.
git stowed.
gtk stowed.
i3 stowed.
WARNING! unstowing ncmpcpp would cause conflicts:
  * existing target is neither a link nor a directory: .config/ncmpcpp/config
WARNING! stowing ncmpcpp would cause conflicts:
  * existing target is neither a link nor a directory: .config/ncmpcpp/config
All operations aborted.
ncmpcpp stowed.
WARNING! unstowing polybar would cause conflicts:
  * existing target is neither a link nor a directory: .config/polybar/config
  * existing target is neither a link nor a directory: .config/polybar/launch.sh
  * existing target is neither a link nor a directory: .config/polybar/updates.sh
  * existing target is neither a link nor a directory: .config/polybar/weather.py
WARNING! stowing polybar would cause conflicts:
  * existing target is neither a link nor a directory: .config/polybar/config
  * existing target is neither a link nor a directory: .config/polybar/launch.sh
  * existing target is neither a link nor a directory: .config/polybar/updates.sh
  * existing target is neither a link nor a directory: .config/polybar/weather.py
All operations aborted.
polybar stowed.
ranger stowed.
sound stowed.
WARNING! unstowing termite would cause conflicts:
  * existing target is neither a link nor a directory: .config/termite/config
WARNING! stowing termite would cause conflicts:
  * existing target is neither a link nor a directory: .config/termite/config
All operations aborted.
termite stowed.
WARNING! unstowing tmux would cause conflicts:
  * existing target is neither a link nor a directory: .tmux.conf
WARNING! stowing tmux would cause conflicts:
  * existing target is neither a link nor a directory: .tmux.conf
All operations aborted.
tmux stowed.
WARNING! unstowing vim would cause conflicts:
  * existing target is neither a link nor a directory: .tern-config
  * existing target is neither a link nor a directory: .vimrc
WARNING! stowing vim would cause conflicts:
  * existing target is neither a link nor a directory: .tern-config
  * existing target is neither a link nor a directory: .vimrc
All operations aborted.
vim stowed.
WARNING! unstowing xorg would cause conflicts:
  * existing target is neither a link nor a directory: .Xresources
  * existing target is neither a link nor a directory: .xinitrc
WARNING! stowing xorg would cause conflicts:
  * existing target is neither a link nor a directory: .Xresources
  * existing target is neither a link nor a directory: .xinitrc
All operations aborted.
xorg stowed.
All stowed
EN

回答 2

Stack Overflow用户

发布于 2018-01-17 10:48:34

您从哪个目录调用此脚本?您的cd似乎无法工作,因为您正试图转换为.dotfiles,但是for循环使用的是一个名为dotfiles的目录(没有领先的.)。

警告的含义

您的主目录中似乎有您希望由stow管理(链接)的普通文件。

来自stow手册页面:

-采取警告措施!此行为专门用于更改stow目录的内容。如果你不想那样做,这个选项不适合你。当装载时,如果遇到一个已经存在但是一个普通文件(因此不属于任何现有的stow包)的目标,那么Stow通常会将其注册为冲突,并拒绝继续。此选项更改该行为,以便将文件移动到存储目录中包的安装映像中的相同相对位置,然后继续存储。因此,有效地使文件被stow包采用,而不改变其内容。

请注意:

当装载时,如果遇到一个已经存在但是一个普通文件(因此不属于任何现有的stow包)的目标,那么Stow通常会将其注册为冲突,并拒绝继续。

TLDR

  • 修复您的脚本,将cdfor循环指向同一个目录:~/.dotfiles/~/dotfiles/
  • 如果您想要将现有的配置文件(在~中)移动到您的dotfiles,那么首先使用stow --adopt (事先检查手册)
  • 如果要将配置文件从dotfiles移动到~,则移动或删除(备份)主文件夹中已有的文件。
票数 1
EN

Stack Overflow用户

发布于 2020-01-18 23:15:51

我试过和你一样的方法。这是我的尝试。

cd不适用于脚本。相反,您需要告诉stow从哪里存放,而不是当前目录。

我在自己的dotfile中有一堆包,因此我循环遍历它们,并将其储存起来:

代码语言:javascript
复制
for PACKAGE in shell emacs # ...
do
  stow -R -v -d path/to/dotfiles -t ~ $PACKAGE
done
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45783937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档