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 11-01-2019, 02:57 AM   #16
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

So the file name is literally "Name of File - Screenshot (1).jpg"?
then
Code:
for file in $(ls . |grep jpg); do ln -s "$file" "/volume1/Screenshots/Screenshots Firefox dd 01-11/$file"  ; done
should work.
 
1 members found this post helpful.
Old 11-01-2019, 03:05 AM   #17
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
So the file name is literally "Name of File - Screenshot (1).jpg"?
then
Code:
for file in $(ls . |grep jpg); do ln -s "$file" "/volume1/Screenshots/Screenshots Firefox dd 01-11/$file"  ; done
should work.
Yep that are the file names.

Thx, will try it, and report back

Edit-1: Nope it doesn't work. Same error.

Last edited by iammike2; 11-01-2019 at 03:13 AM.
 
Old 11-01-2019, 03:11 AM   #18
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
OK. I'll check tomorrow...it's 0100 here now.

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?
 
Old 11-01-2019, 03:32 AM   #19
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
OK. I'll check tomorrow...it's 0100 here now.

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

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

Original Poster
Rep: Reputation: Disabled
The plot thickens

doing this now

src dir = /volume1/test (NO spaces)
dest dir = /volume1/test/1 (no spaces)
file name = a.jpg (no spaces)

and this what happens

Code:
sh-4.3# pwd
/volume1/test
sh-4.3# for file in $(ls . |grep jpg); do ln -s $file "/volume1/test/1/$file"  ; done
ln: failed to create symbolic link ‘/volume1/test/1/a.jpg’: File exists
After running this, In the 1 dir a file exists !a.jpg

Last edited by iammike2; 11-01-2019 at 03:54 AM.
 
Old 11-01-2019, 02:23 PM   #21
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
Yep that are the file names.

Thx, will try it, and report back

Edit-1: Nope it doesn't work. Same error.
What error?
Again...please note quotes.
Code:
for file in $(ls . |grep jpg); do ln -s "$file" "/volume1/Screenshots/Screenshots Firefox dd 01-11/$file"  ; done
 
Old 11-01-2019, 07:06 PM   #22
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
Same error as in post #20.

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)
 
Old 11-01-2019, 08:28 PM   #23
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
Another try

Without quotes

Code:
sh-4.3# for file in $(ls . |grep jpg); do ln -s $file /volume1/test/1/$file  ; done
sh-4.3# mc
Result: NO Error but also NO File found in /1/

with quotes

Code:
sh-4.3# for file in $(ls . |grep jpg); do ln -s "$file" "/volume1/test/1/$file"  ; done
sh-4.3# pwd
/volume1/test
sh-4.3# mc
Result: No Error but a file created in /1/ with filename !a.jpg (note the ! in front)


And changing LS for Find

Code:
sh-4.3# for file in $(find . -maxdepth 1 -name "*.jpg"); do ln -s "$file" "/volume1/test/1/$file"  ; done
sh-4.3# mc
Result: No Error but a file created in /1/ with filename !a.jpg (note the ! in front)

Running out of ideas here
 
Old 11-01-2019, 08:34 PM   #24
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
This one works

Code:
sh-4.3# for file in $(find . -maxdepth 1 -name "*.jpg"); do ln -s /volume1/test/$file /volume1/test/1/$file  ; done
sh-4.3# mc
Result: File created in /1/ with as name @a.jpg

Oke another try created "This is a test.jpg", so there are 2 files 1) a.jpg and 2) "This is a test.jpg"

Code:
sh-4.3# for file in $(find . -maxdepth 1 -name "*.jpg"); do ln -s "/volume1/test/$file" "/volume1/test/1/$file"  ; done
sh-4.3# mc
Result in /1/ there is a @a.jpg and also the following files
!This
!a
!is
!test.jpg


This is what it looks like

Code:
drwxrwxrwx+ 2 root root  4096 Nov  2 08:42 .
drwxrwxrwx+ 7 root root  4096 Nov  2 08:35 ..
lrwxrwxrwx  1 root root   19 Nov  2 08:42 a -> /volume1/test/a
lrwxrwxrwx  1 root root   25 Nov  2 08:42 a.jpg -> /volume1/test/./a.jpg
lrwxrwxrwx  1 root root   20 Nov  2 08:42 is -> /volume1/test/is
lrwxrwxrwx  1 root root   26 Nov  2 08:42 test.jpg -> /volume1/test/test.jpg
lrwxrwxrwx  1 root root   24 Nov  2 08:42 This -> /volume1/test/./This

Last edited by iammike2; 11-01-2019 at 08:44 PM. Reason: Added another Try
 
Old 11-01-2019, 08:49 PM   #25
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
I am getting my new Raspberry 4 this week and will try it on that one, if it works on that one it has something to do with the OS on my NAS.

Thx for the help thus far.
 
Old 11-01-2019, 09:04 PM   #26
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’m not familiar with mc.
Maybe the ! identifies a link?

Yes, something strange is happening. ln shouldn’t create a link to a file that doesn’t exist.

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

Original Poster
Rep: Reputation: Disabled
! = (AFAIK) a failed Symlink
@ = (AFAIK) a correct Symlink

Will report back after I have received my Raspb4 and have tested it

Thanks again for the help, appreciated.

Last edited by iammike2; 11-01-2019 at 09:52 PM.
 
Old 11-02-2019, 11:49 AM   #28
tofino_surfer
Member
 
Registered: Aug 2007
Posts: 483

Rep: Reputation: 153Reputation: 153
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
 
Old 11-02-2019, 03:00 PM   #29
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

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

Last edited by crts; 11-02-2019 at 10:01 PM.
 
1 members found this post helpful.
Old 11-02-2019, 04:31 PM   #30
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by scasey View Post
Yes, something strange is happening. ln shouldn’t create a link to a file that doesn’t exist.
ln will throw an error if you try to create a hardlink to a non-existant file. However, it will create broken symbolic links:
Code:
$ ln -s non-existant-file symlink
$ echo $?
0
It will even exit with SUCCESS code.
 
2 members found this post helpful.
  


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:24 AM.

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