I ran this command that a user on reddit wrote for me:
dest=final_dir
files=$(find dir1 dir2 dir3 -type f)
for file_path in $files; do
IFS='/' read -r -a tokens <<< "$file_path"
dest_fname="${tokens[1]}.${tokens[0]}"
ln -s "$PWD/$file_path" "$PWD/$dest/$dest_fname"
done
It is supposed to take all files in all subfolders and create a symlink to another directory with the name of the link being filename+filefolder. It does however only give me the error: failed to create symbolic link - no such file or directory here is a screenshot of the console: https://imgur.com/36F4sdX
any ideas what could be the problem?
Edit: Ok, the problem seems to be that it when the path includes a space, it thinks the name stops at this space and thus doesnt find the file. Any idea how to fix this?
Here a description of what the script is supposed to do. my current filesystem looks like this:
dir1: file1, file2
dir2: file1, file2
if i now run the above command i get:
dir3: file1, file2
and the other 2 files are skipped as they have the same name.
also given this scenario:
dir1: file1, file3
dir2: file2, file4
in this case the files would be mixed to:
dir3: file1, file2, file3, file4
what i want though is:
dir3: file1, file3, file2, file4
In my opinion the easiest way to achieve this would be to make the source folder part of the symlinks name, like this:
dir3: dir1-file1, dir1-file3, dir2-file3, dir2-file4
I hope this explains it well enough.
The problem right now seems to be that when file- or foldername contain any special characters like "-" or "_" it stops reading the name at that point.
This results in: dir1-2: file3-4 creating a symlink to dir1.file3 which doesnt exist