LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 07-15-2009, 08:07 PM   #1
ADF-Sniper
LQ Newbie
 
Registered: Jul 2005
Location: Wangaratta, Australia
Posts: 7

Rep: Reputation: 0
find command without outputing ./


Hi,

I am using this line of code but the resault is not quite what I want.

Code:
cd /shares ; find -maxdepth 1 -type d -exec echo rar a -v1g -m0 -ow -ag[dd-mm-yy] '{}' '/shares/{}' \;
The resault I get is....
Code:
rar a -v1g -m0 -ow -ag[dd-mm-yy] ./temp /shares/./temp
I want to remove the ./ so the resault is....

Code:
rar a -v1g -m0 -ow -ag[dd-mm-yy] temp /shares/temp
Any help would be great!

Regards,
Nathum
 
Old 07-15-2009, 09:49 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
I just skimmed the man page for find to see if it has an option to omit the path---I did not see one, but that does not mean it's not there...

You can always pipe the output into SED to remove the "./"

Code:
<your stuff> | sed 's%\./%%g'
 
Old 07-15-2009, 10:19 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
find can get rid of the ./, just not in conjunction with the exec ... you could
do something like this instead:
Code:
cd /shares && find -maxdepth 1 -type d -printf "%P\n" |xargs -i rar a -v1g -m0 -ow -ag[dd-mm-yy] {} share/{} \;

Cheers,
Tink
 
Old 07-16-2009, 12:59 AM   #4
ADF-Sniper
LQ Newbie
 
Registered: Jul 2005
Location: Wangaratta, Australia
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks for the help

I went with pixellany idea because I can understand it and my use it in the future.
 
Old 07-16-2009, 01:35 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
I'm curious ... how did you wrap the sed into the finds exec?
 
Old 07-16-2009, 01:53 AM   #6
ADF-Sniper
LQ Newbie
 
Registered: Jul 2005
Location: Wangaratta, Australia
Posts: 7

Original Poster
Rep: Reputation: 0
Im still trying to work it out...

When echo to screen this looks fine
Code:
cd /shares ; find -maxdepth 1 -type d -exec echo rar a -v1g -m0 -ow -ag[dd-mm-yy] '{}' '"\shares\{}"' \; | sed 's%\./%%g'
Result
Quote:
rar a -v1g -m0 -ow -ag[dd-mm-yy] Dev_cal "\shares\Dev_cal"
rar a -v1g -m0 -ow -ag[dd-mm-yy] atsend "\shares\atsend"
rar a -v1g -m0 -ow -ag[dd-mm-yy] cadd "\shares\cadd"
rar a -v1g -m0 -ow -ag[dd-mm-yy] home "\shares\home"
rar a -v1g -m0 -ow -ag[dd-mm-yy] ohs "\shares\ohs"
But when I remove the echo the | sed 's%\./%%g' does not work.
Code:
cd /shares ; find -maxdepth 1 -type d -exec ./rar a -v1g -m0 -ow -ag[dd-mm-yy] '{}' '"\shares\{}"' \; | sed 's%\./%%g'
rar gives me the error

Code:
Cannot open "\shares\./testa"
No such file or directory
Creating archive testa[16-07-09].rar
WARNING: No files
I also have another issue, im am guessing rar will run 15 times if it rar's 15 directories. I assume there is a loop somewere and tried the wait command with no success.

Nath

Last edited by ADF-Sniper; 07-16-2009 at 01:56 AM.
 
Old 07-16-2009, 02:19 AM   #7
ADF-Sniper
LQ Newbie
 
Registered: Jul 2005
Location: Wangaratta, Australia
Posts: 7

Original Poster
Rep: Reputation: 0
I have now gone with what tinkster has posted... after a couple of changes I have it working perfectly with no issues.

Code:
cd /shares && find -maxdepth 1 -type d -printf "%P\n" |xargs -i ./rar a -v1g -m0 -ow -ag[dd-mm-yy] {} /shares/{} \;
I still have to get it to save the rar files from wherever location I run it from and not in the same /shares/ directory.

But ill get there.

Thanks both again.

Last edited by ADF-Sniper; 07-16-2009 at 02:24 AM.
 
Old 07-16-2009, 02:29 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Try to use an absolute search path to avoid the leading ./, that is change
Code:
cd /shares ; find -maxdepth 1 blah blah blah
with
Code:
find /shares -maxdepth 1 blah blah blah
Anyway the error is not due to the presence of ./, since a path like /shares/./dir is valid and the shell interprets it as /shares/dir. The problem is that in my opinion you switched the arguments of rar:
Code:
rar <command> -<switch 1> -<switch N> <archive> <files...>
that is maybe you changed <files...> with <archive>. Another clue can be the usage of windows-like backslashes in your last example: that's not correct.
 
Old 07-16-2009, 02:39 AM   #9
ADF-Sniper
LQ Newbie
 
Registered: Jul 2005
Location: Wangaratta, Australia
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks Colucix

Final working code that I will now be using to backup my shares

Quote:
find /shares -maxdepth 1 -type d -printf "%P\n" |xargs -i ./rar a -v1g -m0 -ow -ag[dd-mm-yy] {} /shares/{} \;


Regards,
Nathum
 
  


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
how to tell if a file is outputing to STDOUT or STDERR? xskycamefalling Linux - Newbie 5 05-15-2009 01:52 AM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 05:45 PM
Outputing a 3D image file from a Java program sniff Programming 0 01-17-2007 09:29 AM
wall command not outputing to screen aaronj Fedora 1 06-11-2004 04:40 AM
real-time get the pixel image outputing from OpenGL phil123 Programming 0 02-26-2004 02:09 AM

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

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