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.
Need your help again.
I am using this snippet to make symlinks for a lot of files
Code:
for file in $(ls <source path with spaces>/. |grep jpg); do ln -s <source path with spaces>/$file <destination path with spaces>/$file ; done
It works BUT, it doesn't handle files with special characters very well.
I tried with ' and " but no luck.
Thx in advance for any pointers.
Show us what you tried...where did you put the quotes. And what do you mean by "special characters"? Which characters?
Do the file names also have spaces?
EDIT: If you're trying to have links to the destination path, just linking the path should be all you need to do:
Code:
ln -s source/path destination/path/
You don't need a link for each file in the source.
Oh.. just noticed you only want to link jpg files...sorry...so please answer my questions...thanks.
ln: failed to create symbolic link ‘./Name’: File exists
ln: failed to create symbolic link ‘./of’: File exists
ln: failed to create symbolic link ‘./file’: File exists
ln: failed to create symbolic link ‘./-’: File exists
ln: failed to create symbolic link ‘./Screenshot’: File exists
etc etc etc
And this is what the directory looks like afterwards
for file in $(ls "source path with spaces/." |grep jpg); do ln -s <source path with spaces>/$file <destination path with spaces>/$file ; done
for file in $(ls <source path with spaces>/. |grep jpg); do ln -s "source path with spaces/$file" <destination path with spaces>/$file ; done
for file in $(ls <source path with spaces>/. |grep jpg); do ln -s <source path with spaces>/$file "<destination path with spaces>/$file" ; done
and
for file in $(ls "source path with spaces/." |grep jpg); do ln -s "source path with spaces>/$file" "destination path with spaces>/$file" ; done
Sorry. Repeating this. “See a sample of” not “tell us about...”. Use code tags.
We need to see the output of that command...If it’s a gazillion lines, just show us the first 2 or 3
I’m frankly not clear about what the dot at the end is doing.
and I change into the source dir before running the commands.
What more samples do you want ??
I have no idea what more I can give you??
I already gave samples of file names [Post #2 and #9]
I already gave samples of dir name (both source and dest) [Post #9]
I already gave error messages [Post #6]
I already gave what the dest dir looks like after I ran the command [Post #6]
I already gave all the commands I tried [Post #7]
me@NAS:/volume1/Media/Screenshots Firefox dd 01-11/$ ls . | grep jpg
Name of File - Screenshot (1).jpg
Name of File - Screenshot (2).jpg
Name of File - Screenshot (3).jpg
Name of File - Screenshot (4).jpg
Name of File - Screenshot (5).jpg
Name of File - Screenshot (6).jpg
Name of File - Screenshot (7!).jpg
etc etc etc etc etc etc
me@NAS:/volume1/Media/Screenshots Firefox dd 01-11/$ ls . | grep jpg
Name of File - Screenshot (1).jpg
Name of File - Screenshot (2).jpg
Name of File - Screenshot (3).jpg
Name of File - Screenshot (4).jpg
Name of File - Screenshot (5).jpg
Name of File - Screenshot (6).jpg
Name of File - Screenshot (7!).jpg
etc etc etc etc etc etc
Code:
me@NAS:/volume1/Media/Screenshots Firefox dd 01-11/$ for file in $(ls . |grep jpg); do ln -s $file /volume1/Screenshots/Screenshots Firefox dd 01-11/$file ; done
Error messages
Code:
ln: failed to create symbolic link ‘./Name’: File exists
ln: failed to create symbolic link ‘./of’: File exists
ln: failed to create symbolic link ‘./file’: File exists
ln: failed to create symbolic link ‘./-’: File exists
ln: failed to create symbolic link ‘./Screenshot’: File exists
etc etc etc
And what the Dest Dir looks like afterwards
Code:
lrwxrwxrwx 1 root root 1 Nov 1 10:30 - -> -
lrwxrwxrwx 1 root root 7 Nov 1 10:30 (1).jpg -> (1).jpg
lrwxrwxrwx 1 root root 7 Nov 1 10:30 (2).jpg -> (2).jpg
lrwxrwxrwx 1 root root 7 Nov 1 10:30 (3).jpg -> (3).jpg
lrwxrwxrwx 1 root root 7 Nov 1 10:30 (4).jpg -> (4).jpg
lrwxrwxrwx 1 root root 7 Nov 1 10:30 (5).jpg -> (5).jpg
lrwxrwxrwx 1 root root 7 Nov 1 10:30 (6).jpg -> (6).jpg
lrwxrwxrwx 1 root root 7 Nov 1 10:30 (7).jpg -> (7).jpg
lrwxrwxrwx 1 root root 5 Nov 1 10:30 Name -> Name
lrwxrwxrwx 1 root root 4 Nov 1 10:30 of -> of
lrwxrwxrwx 1 root root 10 Nov 1 10:30 Screenshot -> Screenshot
lrwxrwxrwx 1 root root 6 Nov 1 10:30 File -> File
Tried the command with without " with and without '
If you're doing entire directories, perhaps lndir is in order? Kind of used to create ./build/ type things so you're not compiling in the "actual" source trees. AKA make clean is simple in the form of rm -rf ./build/ and such. Beyond that I've been known to use $VAR's of the ls output to get "odd" filenames to "move". Unicode and whatnot.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.