LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 10-31-2019, 07:30 PM   #1
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Rep: Reputation: Disabled
LN -s question


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.
 
Old 10-31-2019, 07:42 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by iammike2 View Post
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.

Last edited by scasey; 10-31-2019 at 08:31 PM.
 
1 members found this post helpful.
Old 10-31-2019, 09:09 PM   #3
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
Example of a file is: "Name of file - Screenshot (7).jpg" or "Name of file - Screenshot (1!).jpg" (without the quotes of course.

What I have tried I already thrown away (but was just putting " and ' in several (random ) places and they failed)

Both the Source Path / Desti Path have spaces in it. Some files names have spaces some don't.

With "normal" files for example "File.T07.Sample.jpg" it works great, just not with the Special Chars.

I hope this answers your questions
 
Old 10-31-2019, 09:22 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Sorry you don’t recall what you tried...maybe you need to just try again to show us what doesn’t work

That said, try double quotes around the entire path/filenames:
Code:
”<source path with spaces>/$file”
etc.

Alternatively, clean up file names?

Last edited by scasey; 10-31-2019 at 09:24 PM.
 
Old 10-31-2019, 09:50 PM   #5
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
Clean up file names not possible unfortunately names have to stay intact.

Will try your suggestion !
 
Old 10-31-2019, 09:59 PM   #6
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
Now I tried it with the quotes


This what the error is:

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

!(1).jpg
!(2).jpg
etc
etc
!name
!of
!file

All files are around 64-63 bytes in size

Last edited by iammike2; 10-31-2019 at 10:04 PM.
 
Old 10-31-2019, 10:12 PM   #7
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
I now tried

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

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
And none work
 
Old 10-31-2019, 10:20 PM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
I think we need to see a sample of
Code:
 ls <source path with spaces>/. |grep jpg)
...
 
Old 10-31-2019, 10:33 PM   #9
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
Even going in the directory and removing the source path it fails, so changed the ls to this.

Code:
ls . | grep jpg
When I do this on the command line it shows all the files.

I am thinking of doing it manually via MC as that one works, but some dirs have 200+ files in them

Edit:
Name of files in that dir are for example
Name of file - Screenshot (7).jpg
Name of file - Screenshot (1!).jpg
etc etc


Source Path is something like "Screenshots Firefox dd 01-11"
Dest Path is exactly the same as Source

Source Path is on /volume1/Media
Dest Path is on /volume1/Screenshots

So a full directory looks like
Source: /volume1/Media/Screenshots Firefox dd 01-11/
Dest: /volume1/Screenshots/Screenshots Firefox dd 01-11/

Last edited by iammike2; 10-31-2019 at 10:58 PM. Reason: Added more info (again)
 
Old 10-31-2019, 11:35 PM   #10
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by scasey View Post
I think we need to see a sample of
Code:
 ls <source path with spaces>/. |grep jpg)
...
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.
 
Old 10-31-2019, 11:58 PM   #11
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
If you read post #9, I changed the LS to

Code:
ls . |grep jpg
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]

Last edited by iammike2; 11-01-2019 at 12:00 AM.
 
Old 11-01-2019, 12:19 AM   #12
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Third time...
Copy and paste the exact output of (the first few lines of)
Code:
 ls <source path with spaces>/. |grep jpg)
in code tags...

We (I) can’t debug the problem without seeing the actual output...
And this is just the first step...
 
Old 11-01-2019, 12:23 AM   #13
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
Code:
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
dest dir IS EMPTY so no point in posting that.

Last edited by iammike2; 11-01-2019 at 12:30 AM.
 
Old 11-01-2019, 12:35 AM   #14
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
ok screenshot per screenshot

Code:
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 '

Last edited by iammike2; 11-01-2019 at 12:44 AM.
 
Old 11-01-2019, 01:43 AM   #15
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
$ ln -s $EXISTING $NEW

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.

$ FILENAME=$(ls -l | head -n 23 | tail -n 1 | awk '{ print $9; }')
$ mv $FILENAME GFme$FILENAME
$ mv GFme* ./uRgone/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache newbie question.. (very newbie question) tarballed Linux - Newbie 1 02-07-2003 08:41 PM
RE: Suse 8.0 hardware question {newbie question, pls help} Radiouk Linux - Distributions 2 06-04-2002 12:53 PM
RE: Samba question pls help {Newbie question} Radiouk Linux - Networking 4 06-03-2002 06:40 PM
Security question {newbie question} Radio Linux - Security 3 05-17-2002 06:32 PM
Lilo/kernel question & font question phek Linux - General 9 09-18-2001 12:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration