LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-02-2019, 09:27 PM   #31
iammike2
Member
 
Registered: Oct 2018
Distribution: Raspbian
Posts: 55

Original Poster
Rep: Reputation: 1

Thx guys

Tried again (PS: Changed LS to Find in post #23 )

Mainly Experimenting with placement of "/"

Code:
ln: failed to create symbolic link ‘/volume1/test/1//volume1/test/a.jpg’: No such file or directory
ln: target ‘test.jpg’ is not a directory
sh-4.3# find "/volume1/test/" -maxdepth 1 -type f -name '*.jpg' | while read file;  do     ln -s "/volume1/test"/$file "/volume1/test/1"/$file; done
ln: failed to create symbolic link ‘/volume1/test/1//volume1/test/a.jpg’: No such file or directory
ln: target ‘test.jpg’ is not a directory
sh-4.3# mc

sh-4.3# find "/volume1/test" -maxdepth 1 -type f -name '*.jpg' | while read file;  do     ln -s "/volume1/test"/$file "/volume1/test/1"/$file; done
ln: failed to create symbolic link ‘/volume1/test/1//volume1/test/a.jpg’: No such file or directory
ln: target ‘test.jpg’ is not a directory
sh-4.3# find "/volume1/test" -maxdepth 1 -type f -name '*.jpg' | while read file;  do     ln -s "volume1/test"/$file "/volume1/test/1"/$file; done
ln: failed to create symbolic link ‘/volume1/test/1//volume1/test/a.jpg’: No such file or directory
ln: target ‘test.jpg’ is not a directory
sh-4.3# mc

sh-4.3# find "/volume1/test/" -maxdepth 1 -type f -name '*.jpg' | while read file;  do     ln -s "/volume1/test"$file "/volume1/test/1"/$file; done
ln: failed to create symbolic link ‘/volume1/test/1//volume1/test/a.jpg’: No such file or directory
ln: target ‘test.jpg’ is not a directory
sh-4.3# find "/volume1/test/" -maxdepth 1 -type f -name '*.jpg' | while read file;  do     ln -s "/volume1/test"$file "/volume1/test/1"$file; done
ln: failed to create symbolic link ‘/volume1/test/1/volume1/test/a.jpg’: No such file or directory
ln: target ‘test.jpg’ is not a directory
sh-4.3# mc

sh-4.3# find "/volume1/test" -maxdepth 1 -type f -name '*.jpg' | while read file;  do     ln -s "/volume1/test"$file "/volume1/test/1"$file; done
ln: failed to create symbolic link ‘/volume1/test/1/volume1/test/a.jpg’: No such file or directory
ln: target ‘test.jpg’ is not a directory
sh-4.3# find "/volume1/test/" -maxdepth 1 -type f -name '*.jpg' | while read file;  do ln -s "/volume1/test/"$file "/volume1/test/1/"$file; done
ln: failed to create symbolic link ‘/volume1/test/1//volume1/test/a.jpg’: No such file or directory
ln: target ‘test.jpg’ is not a directory
sh-4.3# find "/volume1/test" -maxdepth 1 -type f -name '*.jpg' | while read file;  do ln -s "/volume1/test/"$file "/volume1/test/1/"$file; done
ln: failed to create symbolic link ‘/volume1/test/1//volume1/test/a.jpg’: No such file or directory
ln: target ‘test.jpg’ is not a directory
sh-4.3#
I am waiting for my Raspb before trying again, on this NAS I am definitely giving up !

Last edited by iammike2; 11-02-2019 at 09:30 PM.
 
Old 11-02-2019, 11:05 PM   #32
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,844

Rep: Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626
Have you tried my solution from post #29?
 
Old 11-03-2019, 03:13 AM   #33
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,287

Rep: Reputation: 591Reputation: 591Reputation: 591Reputation: 591Reputation: 591Reputation: 591
Again you have $file outside the "quotes"!
Have it inside the quotes:
Code:
ln -s "/volume1/test/$file" "/volume1/test/1/$file"
Expanded wildcards are surprisingly safe, so you can do all in one command
Code:
ln -s "/volume1/test/"*.jpg "/volume1/test/1/"
But this can overflow with "ln: two many arguments".
A for loop can handle more arguments than commands; again the file names produced by wildcards are safe; but you must have $var in quotes
Code:
for file "/volume1/test/"*.jpg; do [ -f "$file" ] && ln -s "$file" "/volume1/test/1/"; done
By default the ln repeats the $file (shortname, witout a path). If you put it explicitly (like ${file##*/} that strips off a path) then inside "quotes"!
A while loop has no limits but struggles a bit with special file names. Nearly safe is
Code:
ls "/volume1/test/" | while IFS= read -r file; do case "$file" in (*.jpg) ln -s "/volume1/test/$file" "/volume1/test/1/";; esac; done
100% safe is find -exec
Code:
find "/volume1/test/" -maxdepth 1 -type f -name "*.jpg" -exec ln -s {} "/volume1/test/1/" \;; done
But some find versions want {} to be last, just before the closing \;
And a while loop again struggles a bit with special file names (e.g. with a new line character).
Code:
find "/volume1/test/" -maxdepth 1 -type f -name "*.jpg" | while IFS= read -r file; do ln -s "$file" "/volume1/test/1/"; done
My personal choice here would be the for loop. Safe with special file names, and can handle several thousand filenames.

Last edited by MadeInGermany; 11-03-2019 at 07:03 AM. Reason: Added info: repeated $file is shortname
 
1 members found this post helpful.
Old 11-03-2019, 03:28 AM   #34
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: Currently: openSUSE, Raspbian, Slackware. Formerly: CentOS, MacOS, Red Hat. Other: Solaris, Tru64
Posts: 1,728

Rep: Reputation: 212Reputation: 212Reputation: 212
0x20 in filenames... just say "No!" (Directory names, too!)

Oy! Eons ago, I wound up writing a couple of Perl scripts that renamed files (or subdirectories) with spaces in their names with new names substituting underscores for the spaces. Allowing spaces in the names is fine and dandy when you're doing all of your manipulations (dragging/dropping/etc.) with a GUI tool but always bites you in the backside when trying to perform any operations with any quick and dirty shell script. After I've gotten lazy and allowed spaces to creep back into my directory trees, these scripts come in handy.

For files in the current directory:
Code:
#!/usr/bin/perl -w

#
#  Renames any files in the current directory that contain spaces in
#  the names to names that contain underscores instead.
#
use strict;
use warnings;

my ( $cmd );
my ( $infile );
my ( $n_renamed );
my ( $outfile );
my ( $pwd );

my ( @filelist );

$n_renamed = 0;

opendir( DIR, "." )
    || die "Could not open directory \"$pwd\" (Reason: $!)\n";
    @filelist = grep { ! /^\./ && -f "./$_" } readdir( DIR );
closedir( DIR );

for $infile ( @filelist ) {
    if ( -e "$infile" ) {
        if ( "$infile" =~ /\s/ ) {
            $outfile = "$infile";
            $outfile =~ s/\s/_/g;
            $cmd = sprintf "mv \"%s\" \"%s\"", "$infile", "$outfile";
            system( $cmd );
            printf "%s\n", $cmd;
            $n_renamed++;
        }
    }
}

printf "%d renamed.\n", $n_renamed;

exit( 0 );
It's not elegant but it works. The version that renames subdirectories uses "find" to build the list of directories, but is otherwise identical.

This scripts could be used to do other things---like creating the symlinks the OP was interested in. That would be a trivial change to how "$cmd" is defined (trivial in that it's a one liner).
 
1 members found this post helpful.
Old 11-03-2019, 04:51 AM   #35
iammike2
Member
 
Registered: Oct 2018
Distribution: Raspbian
Posts: 55

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by crts View Post
Have you tried my solution from post #29?
Nope not yet sorry.

Quote:
Originally Posted by MadeInGermany View Post
Again you have $file outside the "quotes"!
Have it inside the quotes:
Yes I done that, I guess my copy and paste didn't show that, I have tried at least 10 different versions, quotes no quotes quotes in different places different type of quotes ' etc

But thx for the examples !!

But I am at the moment not bothering anymore and I will mark the thread solved, but I will report back once I tried it on a different machine with a "real" Unix/Linux version. (Hopefully end of the week)

Last edited by iammike2; 11-03-2019 at 05:06 AM.
 
Old 11-03-2019, 05:57 AM   #36
iammike2
Member
 
Registered: Oct 2018
Distribution: Raspbian
Posts: 55

Original Poster
Rep: Reputation: 1
Ding Ding we have a winner !!!!!!!

I couldn't keep you guys hanging and thus started trying again

This one worked

Code:
sh-4.3# find "/volume1/test/" -maxdepth 1 -type f -name "*.jpg" | while IFS= read -r file; do ln -s "$file" "/volume1/test/1/"; done

sh-4.3# cd 1
sh-4.3# ls -al
total 8
d---------+ 2 root root 4096 Nov  3 17:49 .
d---------+ 7 root root 4096 Nov  3 08:14 ..
lrwxrwxrwx  1 root root   23 Nov  3 17:49 a.jpg -> /volume1/test/a.jpg
lrwxrwxrwx  1 root root   36 Nov  3 17:49 This is a test.jpg -> /volume1/test/This is a test.jpg
sh-4.3#
Wow this was a real exercise in patience (not only on my behalf but also other members)

Thx to all the guys who replied. We can finally close this one hahahahahaha

And to all of you !!!
 
Old 11-03-2019, 06:01 AM   #37
iammike2
Member
 
Registered: Oct 2018
Distribution: Raspbian
Posts: 55

Original Poster
Rep: Reputation: 1
One question (now for something completely different

Code:
sh-4.3# find "/volume1/test/" -maxdepth 1 -type f -name "*.jpg" | while IFS= read -r file; do ln -s "$file" "/volume1/test/1/"; done
sh-4.3# cd 1
sh-4.3# ls -al
total 8
d---------+ 2 root root 4096 Nov  3 17:49 .
d---------+ 7 root root 4096 Nov  3 08:14 ..
lrwxrwxrwx  1 root root   23 Nov  3 17:49 a.jpg -> /volume1/test/a.jpg
lrwxrwxrwx  1 root root   36 Nov  3 17:49 This is a test.jpg -> /volume1/test/This is a test.jpg
sh-4.3#
After ls -al it says "total 8" why is that ? I could understand if it was 4 (or 6 with the symlinks) but 8 ?????
 
Old 11-03-2019, 07:12 AM   #38
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,287

Rep: Reputation: 591Reputation: 591Reputation: 591Reputation: 591Reputation: 591Reputation: 591
Deleted this wrong post.

Last edited by MadeInGermany; 11-03-2019 at 09:21 AM.
 
Old 11-03-2019, 08:52 AM   #39
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,844

Rep: Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626
Quote:
Originally Posted by iammike2 View Post
One question (now for something completely different

Code:
sh-4.3# find "/volume1/test/" -maxdepth 1 -type f -name "*.jpg" | while IFS= read -r file; do ln -s "$file" "/volume1/test/1/"; done
sh-4.3# cd 1
sh-4.3# ls -al
total 8
d---------+ 2 root root 4096 Nov  3 17:49 .
d---------+ 7 root root 4096 Nov  3 08:14 ..
lrwxrwxrwx  1 root root   23 Nov  3 17:49 a.jpg -> /volume1/test/a.jpg
lrwxrwxrwx  1 root root   36 Nov  3 17:49 This is a test.jpg -> /volume1/test/This is a test.jpg
sh-4.3#
After ls -al it says "total 8" why is that ? I could understand if it was 4 (or 6 with the symlinks) but 8 ?????
It is the number of occupied blocks by files, defaulting to a blocksize of 1024. It can be adjusted by the '--block-size' option to ls, e.g., 'ls -al --block-size=512' will yield a total of 16.

PS:
It has no relation to the actual blocksize of the underlying filesystem, it is an "arbitrary" value by ls which can be manipulated as the user sees fit. This is yet another reason why one should generally not parse the output of ls. The default value may be system dependend. The output of ls is meant as visual feedback for the user.

Last edited by crts; 11-03-2019 at 08:58 AM. Reason: Added PS
 
2 members found this post helpful.
Old 11-03-2019, 09:18 AM   #40
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,287

Rep: Reputation: 591Reputation: 591Reputation: 591Reputation: 591Reputation: 591Reputation: 591
You are right, it is a total of disk blocks!
It is a bit confusing. See this discussion.
I recommend to ignore the "total" line.
 
1 members found this post helpful.
Old 11-03-2019, 05:17 PM   #41
iammike2
Member
 
Registered: Oct 2018
Distribution: Raspbian
Posts: 55

Original Poster
Rep: Reputation: 1
I just tested this on a "real" directory with spaces in it and on files with Special Chars for example (7) or (!7) and it works like a charm !


Wow Guys, I can't thank you enough, now I can start Symlinking Big Style


Again





Quote:
Originally Posted by iammike2 View Post
Ding Ding we have a winner !!!!!!!

I couldn't keep you guys hanging and thus started trying again

This one worked

Code:
sh-4.3# find "/volume1/test/" -maxdepth 1 -type f -name "*.jpg" | while IFS= read -r file; do ln -s "$file" "/volume1/test/1/"; done

sh-4.3# cd 1
sh-4.3# ls -al
total 8
d---------+ 2 root root 4096 Nov  3 17:49 .
d---------+ 7 root root 4096 Nov  3 08:14 ..
lrwxrwxrwx  1 root root   23 Nov  3 17:49 a.jpg -> /volume1/test/a.jpg
lrwxrwxrwx  1 root root   36 Nov  3 17:49 This is a test.jpg -> /volume1/test/This is a test.jpg
sh-4.3#
Wow this was a real exercise in patience (not only on my behalf but also other members)

Thx to all the guys who replied. We can finally close this one hahahahahaha

And to all of you !!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 09:41 PM
RE: Suse 8.0 hardware question {newbie question, pls help} Radiouk Linux - Distributions 2 06-04-2002 01:53 PM
RE: Samba question pls help {Newbie question} Radiouk Linux - Networking 4 06-03-2002 07:40 PM
Security question {newbie question} Radio Linux - Security 3 05-17-2002 07:32 PM
Lilo/kernel question & font question phek Linux - General 9 09-18-2001 01:20 PM

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

All times are GMT -5. The time now is 04:32 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration