Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I guess I'm doubting that every filename starts with "Name of File".
Are you at the command line in a terminal?
On a web page? In some graphical application?
I guess I'm doubting that every filename starts with "Name of File".
Are you at the command line in a terminal?
On a web page? In some graphical application?
Via Putty / thus command line
I am not sure why you are doubting what the structure of the filenames is
Name of File, can be indeed something else, but the structure is this
<part 1> Name of file -> Can be different can be 2 chars long can be 20 chars long (and thus can have spaces)
<part 2> - Screenshot -> Always the same
<part 3> (1).jpg -> incremental and if an error occurred there is "!" added so like this (!1).jpg
BUT before you say anything I am testing it in a dir with only 7 files at the moment and what are they called ????? Indeed
Name of File - Screenshot (1).jpg etc etc etc etc etc
Why I choose "Name of File", because it has everything the other files have, Caps, Lower Case, Space thus if this one works all the other ones will as well.
Happy now or still NOT convinced ????
Thx for all the help, but leave it, I am fed up with it, I am going to do it manually !! Spend too much time on it already if I had done it manually I would be half way right now
ln: failed to create symbolic link ‘/volume1/test/1/a.jpg’: File exists
And there was NO file in /1/ BEFORE I ran this. After running there was a file in /1/ which was called (looked in MC) !a.jpg. A normal SL file would look like @a.jpg.
I am now starting to think it's something quirky with the OS (Synology DSM)
It is quite messy to use ls with grep for this. The find utility is much more professional and can do everything in a single command. Using -maxdepth 1 limits the results to the directory specified just as ls without -R for recursion would do.
Code:
find "source path with spaces" -maxdepth 1 -type f -name '*.jpg' | while read file;
do
ln -s "<source path with spaces>"/$file "<destination path with spaces>"/$file;
done
An alternate form with process substitution and input redirection is:
Code:
while read file;
do
ln -s "<source path with spaces>"/$file "<destination path with spaces>"/$file;
done < <(find "source path with spaces" -maxdepth 1 -type f -name '*.jpg')
Last edited by tofino_surfer; 11-03-2019 at 07:37 PM.
Reason: added alternate form
It is quite messy to use ls with grep for this. The find utility is much more professional and can do everything in a single command. Using -maxdepth 1 limits the results to the directory specified just as ls without -R for recursion would do.
Code:
find "source path with spaces" -maxdepth 1 -type f -name '*.jpg' | while read file;
do
ln -s "<source path with spaces>"/$file "<destination path with spaces>"/$file;
done
Alternately in the form from previous messages without a while loop
Code:
for file in $(find "source path with spaces" -maxdepth 1 -type f -name '*.jpg');
do
ln -s "<source path with spaces>"/$file "<destination path with spaces>"/$file;
done
The while loop works well but the for loop will split the found files on every space. If you want to use a for I recommend using wildcards:
Code:
for file in "source path with spaces"/*.jpg; do
ln -s "$(realpath -e "$file")" "path to target directory"
done
Keep in mind, that a symlink must point to the target as seen from its own location, i.e., it must either be an absolute path or a relative path wich is relative from the link's location.
Hence, I recommend to additionally resolve to an absolute path with realpath. If you know the single, absolute location beforehand, as in OP's case, you can use the absolute path just as well. Personally, I prefer to resolve with realpath. It can handle multiple path locations.
PS:
If files in deeper directories are to be processed then the while loop in combination with find should be preferred.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.