Results 1 to 5 of 5
I have a directory full of jpgs and zips. I want to create an empty copy of that file. If I have test.jpg. I want to create test.jpg in another ...
- 08-01-2008 #1Just Joined!
- Join Date
- Feb 2007
- Posts
- 4
Create New Empty File
I have a directory full of jpgs and zips. I want to create an empty copy of that file. If I have test.jpg. I want to create test.jpg in another directory that's pretty much an empty file.
I have this:
for file in `find . -type f`; do SOMETHING; done;
Is there an easy way to do this?
Any help would be great!
- 08-01-2008 #2Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
If you want to recreate the same structure, you can use find -type d to find first all the directories with -exec mkdir to recreate them. You might need to parse a bit the paths depending on the way the script is going to operate.
After that, you can use find -type f to find the files. The usual command to create an empty file is touch.
- 08-01-2008 #3Linux Newbie
- Join Date
- Feb 2008
- Location
- Bangalore, India
- Posts
- 112
- nileshCode:#!/bin/bash SRC=/source/dir DEST=/dest/dir cd $SRC for file in `ls -al *.conf | awk '{print $8}'` do touch $DEST/$file echo "Empty File created $DEST/$file " donebigunix.blogspot.com
Registered Linux User: #476440
- 08-01-2008 #4Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
Hi,
I discourage the usage of ls to get file names, since it will screw up if the file names contain any space or the ls output format changes. Parsing the ls output is complex and non-reliable. Plus this is just simpler:
Aditional advantages are that you don't have to launch ls, nor awk, nor to open a pipe, which are all a waste of resources.Code:for file in *.conf do ... done
If you insist on using ls, at least make sure the format is correct:
Note that "-1" is a number one, not an 'l' letter. At least that way you ensure you are reading more consistent data (though I still see no point in using ls).It just make the things more complicated and error prone.Code:ls -1 *.conf | while read file do ... done
Anyway, this will not replicate the directory tree as the original posted wanted. The 'find' approach is the simplest because it recurses through the directory tree.
- 08-02-2008 #5Linux Newbie
- Join Date
- Feb 2008
- Location
- Bangalore, India
- Posts
- 112
Thanks, i was not knowing it
bigunix.blogspot.com
Registered Linux User: #476440


Reply With Quote
