[英]How do I make a symbolic link to list of directories?
I must move my $HOME/.directories
because I have wrong partitioning. 我必须移动
$HOME/.directories
因为我的分区错误。
I moved to a another partition with much more free space. 我移动到另一个具有更多可用空间的分区。 But I wanna make a symbolic links, but I cant.
但我想做一个象征性的联系,但我不能。 Because when I try something like:
因为当我尝试类似的东西:
for file in `ls -la | awk '{print$09}'`; do sudo ln -sf "$PWD/$file" /home/inukaze/$file; done
usage: sudo [-D level] -h | -K | -k | -V
usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user name|#uid]
usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user name] [-u user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid] [VAR=value] [-i|-s]
[<command>]
usage: sudo -e [-AknS] [-C fd] [-D level] [-g groupname|#gid] [-p prompt] [-u user name|#uid] file ...
I need the full path for correct read of symbolic links. 我需要完整的路径来正确读取符号链接。 And I this is not working.
而我这不起作用。 How I can make a list of folders begins with “dot” (
.
), and make symbolic links inside my home directory? 如何创建文件夹列表以“点”(
.
)开头,并在我的主目录中创建符号链接?
Okey friends i have try with : 我尝试过的Okey朋友:
1 : 1:
for file in `ls -la "$PWD" | awk '{print$09}' | grep "^\."` ; do `sudo ln -sf $("$PWD/$file") $"("/home/inukaze/$file")"` ; done
2 : 2:
MYDIR="/media/Compartido/.linux/Home/Inukaze"
DIRS=`ls -la "$MYDIR" | egrep '^d' | awk '{print $9}'`
for DIR in $DIRS ; do sudo ln -sf "$PWD/$DIRS" "/home/inukaze/$DIRS" ; done
3 : 3:
find . -type d -maxdepth 1 |while read DIRNAME; do sudo ln -s "${DIRNAME}" /home/inukaze/"${DIRNAME}"; done
But with the Three Methods , i got the same result , much bad symbolic links and just 6 are right . 但是使用三种方法,我得到了相同的结果,很多不好的符号链接,只有6种是正确的。 i dont understand why.
我不明白为什么。
something are wrong , i start to think is in the 有些事情是错的,我开始认为是在
"sudo ln -s $Varible" $Destiny ;
“sudo ln -s $ Varible”$ Destiny; done"
完成”
well . 好 。 another ideas ???
另一个想法???
shopt -s dotglob
cp -s * ~inukaze
Hmmm. 嗯。 Not 100% clear what you are trying to achieve or what it's not working, but I wrote this to attempt to debug based on your sample code.
不是100%清楚你要实现的目标或者它无法正常工作,但我写了这个尝试根据你的示例代码进行调试。 Note I am using
echo
instead of ln -s
for now as well as changing file
to the uppercase FILE
and wrapping in brackets as well as double quotes: 注意我现在使用
echo
而不是ln -s
,以及将file
更改为大写FILE
并用括号括起来以及双引号:
for FILE in `ls -la | awk '{print$09}'`;
do
echo "${PWD}/${FILE}" /home/inukaze/"${FILE}"
done
And on my local system—Mac OS X 10.9—it outputs: 在我的本地系统 - Mac OS X 10.9上 - 它输出:
/Users/jake/.bash_history /home/inukaze/.bash_history
/Users/jake/.bashrc /home/inukaze/.bashrc
/Users/jake/.cache /home/inukaze/.cache
/Users/jake/.gitk /home/inukaze/.gitk
/Users/jake/.htoprc /home/inukaze/.htoprc
/Users/jake/.mysql_history /home/inukaze/.mysql_history
etc…
So unclear how your script is not working? 所以不清楚你的脚本是如何工作的? Do you only want directories?
你只想要目录吗? Or files?
还是文件?
EDIT: Original poster is looking to only symlink directories. 编辑:原始海报只寻找符号链接目录。 So try this using
find
instead: 所以尝试使用
find
代替:
find . -type d -maxdepth 1 |\
while read DIRNAME
do
echo "${DIRNAME}" /home/inukaze/"${DIRNAME}"
done
In my case, it finds all directories in my current home directory like this and echoes the /home/inukaze/"${DIRNAME}
right after that: 在我的例子中,它找到我当前主目录中的所有目录,并在此之后
/home/inukaze/"${DIRNAME}
:
./.ssh /home/inukaze/./.ssh
./.subversion /home/inukaze/./.subversion
./.Trash /home/inukaze/./.Trash
./.Xcode /home/inukaze/./.Xcode
./Applications /home/inukaze/./Applications
./Desktop /home/inukaze/./Desktop
./Documents /home/inukaze/./Documents
etc…
In this example I am just using echo
to test the overall logic. 在这个例子中,我只是使用
echo
来测试整体逻辑。 And that is using find
with the -type d
option which tells it to just find directories and -maxdepth 1
which is connected to the maximum depth find
should go. 那就是使用带有
-type d
选项的find
,它告诉它只找到目录,并且-maxdepth 1
连接到最大深度find
应该去。 Doing 1
deep will not explore any directory deeper than the directory you are in. 执行
1
深度不会探索比您所在目录更深的任何目录。
how i can make a list of folders begins with "dot" (.)
如何制作文件夹列表以“dot”(。)开头
shopt -s dotglob
echo .*/ # This glob matches only dot-directories; however that includes ./ and ../
and make symbolic links inside my home directory?
并在我的主目录中创建符号链接?
shopt -s dotglob
for d in "$PWD"/.*/; do
case "$d" in
*./|*../) :;; # do nothing for these two directories
*) ( cd && ln -s "$d" );;
esac
done
The above is more verbose than Ignacio Vazquez-Abrams' answer , but also links only dot directories other than .
上面比Ignacio Vazquez-Abrams的答案更冗长,但也只链接了除
.
点目录.
and ..
. 和
..
It also will work on BSD/OSX. 它也适用于BSD / OSX。
I think the problem is with 我认为问题在于
ls -la | awk '{print$09}'
Because with this all folder finish with "/" and the "ln -sf" not create a symbolic links if you add / in the finish 因为所有文件夹都以“/”结束,而“ln -sf”如果你在完成中添加/,则不会创建符号链接
i try with 我尝试着
ls -la | awk '{print$09}' | sed 's/\\/*$//
just for remove the last character in ls -la 只是为了删除ls -la中的最后一个字符
Okey i think i solved 哦,我想我解决了
i go to my backup folder , in this case /media/Compartido/.linux/Home/Inukaze 我转到我的备份文件夹,在本例中为/media/Compartido/.linux/Home/Inukaze
$ for file in $(ls -la | awk '{print$09}' | sed 's/\\/*$//') ; do sudo ln -sf "$PWD/$file" "/home/inukaze/$file" ; done
ln: <</home/inukaze/./.>> : cannot overwrite a directory
ln: <</home/inukaze/../..>> : cannot overwrite a directory
and ready all symbolic links are correctly created :=) 并准备好所有符号链接:=)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.