2014-01-16 16 views
0

我有以下的目錄結構,我從github拉;遍歷subdirectores和符號鏈接某些文件(但不是全部)

dotfiles/bash 
    .bashrc 
    .bash_profile 
    .some_other 
    env 

dotfiles/tmux/ 
    .tmux.conf 
dotfiles/???/ 
    .whatever 

慶典/在我的bashcode(下)我想(在我的腳本symlink.sh)迭代槽的子文件夾和符號鏈接可以肯定的,不是所有的,點文件到我的〜家目錄。我怎樣才能動態地做到這一點?由於我不知道有多少個子文件夾,以及這些子文件夾中我不希望符號鏈接的文件必須動態完成。

我下面

!/bin/bash 
############################ 
# .make.sh 
# This script creates symlinks from the home directory to any desired dotfiles in ~/dotfiles 
############################ 
set -x 
trap read debug 
########## Variables 


dir=~/dotfiles     # dotfiles directory 
olddir=~/dotfiles_old    # old dotfiles backup directory 
files=".bashrc .bash_profile env .tmux.conf" # list of files/folders to symlink in homedir 

########## 

# create dotfiles_old in homedir 
echo "Creating $olddir for backup of any existing dotfiles in ~" 
mkdir -p $olddir 
echo "...done" 

# change to the dotfiles directory 
echo "Changing to the $dir directory" 
cd $dir 
echo "...done" 
paus -p ;clear 
# move any existing dotfiles in homedir to dotfiles_old directory, then create symlinks 
for file in $dir/*/*; do 
    echo $dir;ls -a 
     if [[ -f $dir/${files##*/} && ! -L $dir/${files##*/} ]]; then 
       $olddir=$(mktemp -d olddotfiles.XXXXXX) 
       #mv "~/${files##*/}" "$backupdir" 
       ls -a 
     ln -s "$files" ~/${files##*/} 
     fi 
done 
+0

你看了'find'命令? –

+0

你說「因爲我不知道有多少個子文件夾,以及那些子文件夾中我不想符號鏈接的文件」......如果你甚至不知道你想要什麼,其他人怎麼可能甚至有機會幫助你? – twalberg

+0

我的意思是我不知道會有多少個子文件夾,可能是2個,也可能更多。取決於我如何指定它們。 – b0red

回答

0

代碼只是使用find命令 - 更改此:

for file in $dir/*/*; do 

要這樣:

for file in $(find $dir); do 
相關問題