Create symbolic link from find

前端 未结 2 1060
野性不改
野性不改 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.

    0 讨论(0)
  • 2021-02-04 19:35

    Easier:

    Go to the folder where you want to have the files in and do:

    find /path/with/files -type f -name "*txt*" -exec ln -s {} . ';'
    
    0 讨论(0)
提交回复
热议问题