Home  |  About  | Last |  Submit  |  Contact
AllQuests.com

Previous Question:  [ubuntu] opera browser  Absolute Beginner TalkNext Question:  GNOME Lockup  Desktop Environments

Question Copying one file to multiple locations ( Ubuntu Forums Desktop Environments )
Updated: 2008-11-23 01:55:03 (0)
Copying one file to multiple locations

Quick background: My laptop is dual-boot Windows and Ubuntu with a shared fat32 partition where I keep all of my documents which is mounted as ~/Documents. Many of the folders and subfolders contain a Thumbs.db file in which Windows stores thumbnails for pictures in that folder. These ar 1f40 e hidden by default in windows but visible in Ubuntu.

I wanted to create a .hidden containing 'Thumbs.db' and 'desktop.ini' in ~/Documents and in every subfolder. After doing quite a bit of research, I decided to create a .hidden file with the two files mentioned above in gedit. I then opened a terminal and ran this:

Code:
~$ find ~/Documents -print0 -type d -iname '*' | sed 's/$/\/\.hidden'/ | xargs -i -0 -n1 -t cp '.hidden' {}
What I thought this would do:
(1) find and list every subfolder directory (e.g. '/home/mark/Documents/Pictures')

(2) append '/.hidden' to the end of every directory (e.g. '/home/mark/Documents/Pictures/.hidden')

(3) copy the .hidden file to the newly created target: '/home/mark/Documents/Pictures/.hidden'

What in fact happened was that not only was the .hidden file copied to the new directory, but every file was being replaced with a copy of the original .hidden--pictures, videos, downloads, etc. Luckily, I had put in the -t option in xargs so I could see this happening and halt the process before too much damage was done. Also luckily, I had backups ready and did not lose any critical data (just 6 gigs of porn ).

Anyway, what was wrong with my command? I tried running it without piping to xargs and the result was a list of directories--no files--like I expected. Why did my command pipe file names as well as directory names to xargs cp?

Previous Question:  [ubuntu] opera browser  Ubuntu Forums  Absolute Beginner TalkNext Question:  GNOME Lockup  Ubuntu Forums  Desktop Environments

- Source: Copying one file to multiple locations Ubuntu Forums Desktop Environments
- Previous Question: [ubuntu] opera browser Ubuntu Forums Absolute Beginner Talk
- Next Question: GNOME Lockup Ubuntu Forums Desktop Environments





AllQuests.com


Best dedicated servers   Top dedicated servers   Cheap dedicated servers   Linux dedicated servers   Windows dedicated servers   Unmetered dedicated servers