LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-18-2004, 12:26 PM   #1
jamieunb
LQ Newbie
 
Registered: Aug 2004
Location: Canada
Distribution: Mandrake 10.0
Posts: 8

Rep: Reputation: 0
Question I Need script Help!


Hey Everyone,

This is the first time ever that I have used these forums. I've installed Mandrake 10.0 on my system as a dual boot system with winxp. I am still becoming familiar with linux and need a little help.
I would like a script that will copy the contents on my documents on my winxp system to the Documents directory in my home/jamie/ directory. This I can do with:

echo "Update Documents in Linux with My Documents in Winxp"
echo "----------------------------------------------------"
echo "Updating Pictures From WinXP"
cd /mnt/win_c/Document*/James*/My*/My*P*/ && tar -cf - . | (cd /home/jamie/Documents/Pictures && tar -xpvf -)
echo "Updating Music From WinXP"
cd /mnt/win_c/Document*/James*/My*/My*M*/ && tar -cf - . | (cd /home/jamie/Documents/Music && tar -xpvf -)

The only problem that I am encountering is that this also copies all of the junk that windows puts into this directories, such as Destop.ini, Thumbs.db and AlbumArt_*.jpg files. I need a line or two that will remove all files with a spefic extension and from all sub-directories as well.

Can anyone help me out? Thanks!
 
Old 08-18-2004, 12:49 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Welcome to LQ!

You might be interested in reading about the find command (man find). It's a bit long, but it's an extremely useful tool. To give you an example, this command would find every file that does not end in ".db":
find /mnt/win_c/Document* ! -name "*.db"

As another example, this command will find every file that does not end with ".db" or ".jpg":
find /mnt/win_c/Document* \( ! -name "*.db" \) -a \( ! -name "*.jpg" \)

Don't let the \( and \) throw you... they're just used to separate the conditions of the search. The -a says that files must satisfy both requirements (a logical AND if you're familiar with that terminology).

With find, you can also execute a command. To simplify things, I'll go back to the first example. Suppose you wanted to copy the file to a specific directory. You can do this:
find /mnt/win_c/Document* ! -name "*.db" -exec cp {} /some/backup/directory \;

The {} is replaced with the path and filename of the file that matched.

So, you can use find to try and perform the task you want (it does have some limitations though), or you can use it to generate a file list that you can feed into a script.
 
Old 08-18-2004, 01:07 PM   #3
jamieunb
LQ Newbie
 
Registered: Aug 2004
Location: Canada
Distribution: Mandrake 10.0
Posts: 8

Original Poster
Rep: Reputation: 0
Thank you, That was very helpful.
-Newbie
 
Old 08-18-2004, 01:16 PM   #4
jamieunb
LQ Newbie
 
Registered: Aug 2004
Location: Canada
Distribution: Mandrake 10.0
Posts: 8

Original Poster
Rep: Reputation: 0
I now have this and it still won't work!
Any help??

I want this so that if I download songs or pictures into winxp, I can update my files on my linux drive!


echo "Update Documents in Linux with My Documents in Winxp"
echo "----------------------------------------------------"
echo "Updating Pictures From WinXP"
cd /mnt/win_c/Document*/James*/My*/My*P*/ && tar -cf - . | (cd /home/jamie/Documents/Pictures && tar -xpvf -)
echo "Updating Music From WinXP"
cd /mnt/win_c/Document*/James*/My*/My*M*/ && tar -cf - . | (cd /home/jamie/Documents/Music && tar -xpvf -)
echo "Removing *ini, *.jpg, *.db from Music"
rm {find /home/jamie/Documents/Music* \( ! -name "*.mp3" \) -a \( ! -name "*.mwa" \)}
echo "Removing *.ini and *.db from Pictrures"
rm {find /home/jamie/Pictures/Music* \( ! -name "*.jpg" \) -a \( ! -name "*.gif" \) -a \( ! -name "*.bmp" \)}
echo "Finished!"
 
Old 08-18-2004, 01:41 PM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Alright, how about this:

change your "rm { }" lines to
find /home/jamie/Documents/Music* \( ! -name "*.mp3" \) -a \( ! -name "*.mwa" \) -exec rm {} \;

find /home/jamie/Pictures/Music* \( ! -name "*.jpg" \) -a \( ! -name "*.gif" \) -a \( ! -name "*.bmp" \) -exec rm {} \;
 
Old 08-18-2004, 02:07 PM   #6
jamieunb
LQ Newbie
 
Registered: Aug 2004
Location: Canada
Distribution: Mandrake 10.0
Posts: 8

Original Poster
Rep: Reputation: 0
Okay, It's working, although I am gettting errors as rm is trying to remove directories but it cannot (Good Thing!) Anyways, here is what I have now. Again, it works but it would be nice to avoid all of those "errors"
Any ideas? Thanks again.

echo "Update Documents in Linux with My Documents in Winxp"
echo "----------------------------------------------------"
echo "Updating Pictures From WinXP"
cd /mnt/win_c/Document*/James*/My*/My*P*/ && tar -cf - . | (cd /home/jamie/Documents/Pictures && tar -xpvf -)
echo "Updating Music From WinXP"
cd /mnt/win_c/Document*/James*/My*/My*M*/ && tar -cf - . | (cd /home/jamie/Documents/Music && tar -xpvf -)

echo "Updating File Permissions..."
cd /home/jamie/Documents/
chmod -R 777 *

echo "Removing *ini, *.jpg, *.db from Music"
find /home/jamie/Documents/Music* \( ! -name "*.mp3" \) -a \( ! -name "*.wma" \) -a \( ! -name "*.MP3" \) -a \( ! -name "*.WMA" \) -a \( ! -name "*.Wma" \) -a \( ! -name "*.Mp3" \) -exec rm -f {} \;

#echo "Removing *ini and *.db from Pictrures"
find /home/jamie/Documents/Pictures* \( ! -name "*.jpg" \) -a \( ! -name "*.gif" \) -a \( ! -name "*.bmp" \) -a \( ! -name "*.JPG" \) -a \( ! -name "*.Jpg" \) -a \( ! -name "*.GIF" \) -a \( ! -name "*.Gif" \) -a \( ! -name "*.BMP" \) -a \( ! -name "*.Bmp" \) -exec rm -f {} \;

echo "Finished!"
 
Old 08-18-2004, 02:22 PM   #7
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Ok, here we go...

You can change your find command slightly to allow for case insensitive matching based on the filename. All you have to do is change each '-name' option to '-iname'. For instance '-iname "*.jpg"' will match *.JPG, *.Jpg, *.jPg, *.jpg, etc.

You can also tell find to match only files (and not directories) using another option. All you need to do is add "-type f" after the directory in the find command.

Here's an example of both to clarify:
find /home/jamie/Documents/Music* -type f \( ! -iname "*.mp3" \) -a \( ! -iname "*.wma" \) -exec rm -f {} \;
 
Old 08-18-2004, 03:41 PM   #8
jamieunb
LQ Newbie
 
Registered: Aug 2004
Location: Canada
Distribution: Mandrake 10.0
Posts: 8

Original Poster
Rep: Reputation: 0
There we go. Everything is working good. Thanks for your time.
 
  


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
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 04:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:56 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