Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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!"
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 {} \;
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 {} \;
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.