Create symbolic link from find

前端 未结 2 1103
野性不改
野性不改 2021-02-04 18:51

I\'m trying to create a symbolic link (soft link) from the results of a find command. I\'m using sed to remove the ./ that precedes the file name. I\'m doing this so I can paste

2条回答
  •  我寻月下人不归
    2021-02-04 19:21

    Execute your for loop like this:

    (IFS=$'\n'; for t in `find -type f -name "*txt*" | sed 's|.*/||'`; do ln -s $t ../folder2/$t; done)
    

    By setting the IFS to only a newline, you should be able to read the entire filename without getting splitted at space.

    The brackets are to make sure the loop is executed in a sub-shell and the IFS of the current shell does not get changed.

提交回复
热议问题