[英]Linux bash script symlink with spaces
I am trying to make a script which will find all the folders and files within a given hard drive. 我正在尝试制作一个脚本,该脚本将查找给定硬盘中的所有文件夹和文件。 then i want to make the symlinks to another folder. 然后我想使符号链接到另一个文件夹。 However the ln command fails if the folder or file contains space, can someone help me to modify the ln -sf $MOVIE_FILE_LINKS -t $MOVIES_LIB command to make the folders with spaces work? 但是,如果文件夹或文件包含空格,则ln命令失败,有人可以帮助我修改ln -sf $ MOVIE_FILE_LINKS -t $ MOVIES_LIB命令以使带有空格的文件夹正常工作吗? Thanks 谢谢
#! /bin/bash
# Version: 2017.02.21
SRC="/mnt/hdd_1.5T
/mnt/hdd_4T"
MOVIES_TEXT="Movies.*"
MOVIES_LIB="/mnt/Library.Movies/"
rm -rf $MOVIES_LIB #need more elegant solution
mkdir -p $MOVIES_LIB
clear
MOVIE_DIRS=$(find $SRC -maxdepth 1 -type d -name "$MOVIES_TEXT")
MOVIE_DIR_LINKS=$(find $MOVIE_DIRS -maxdepth 1 -type d | sort | awk '$0 !~ last "/" {print last} {last=$0} END {print last}')
MOVIE_FILE_LINKS=$(find $MOVIE_DIRS -maxdepth 1 -type f -name "*.*")
echo "$MOVIE_DIR_LINKS"
#ln -sf $MOVIE_LINKS $MOVIES_LIB;
echo "$MOVIE_FILE_LINKS"
#ln -sf $MOVIE_FILE_LINKS -t $MOVIES_LIB;
You can try to use find
's -exec
action: 您可以尝试使用find
的-exec
操作:
find $MOVIE_DIRS -maxdepth 1 -type d -exec ln -sf -t $MOVIES_LIB {} +
find $MOVIE_DIRS -maxdepth 1 -type f -name "*.*" -exec ln -sf -t $MOVIES_LIB {} +
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.