Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create file with same filename but zero contents

Status
Not open for further replies.

omoo

Programmer
May 30, 2005
87
0
0
US
Hi,

I need to create a file with the same filename as another file in another directory but without the contents.

For example, I have:
originaldirectory/oldfile.zip size:1234kb

I need to create:
newdirectory/oldfile.zip size:no contents - 0kb

 
Hi

Code:
cd originaldirectory
for f in *; do touch "newdirectory/$f"; done
Or if you want to skip subdirectories :
Code:
cd originaldirectory
for f in *; do test ! -d "$f" && touch "newdirectory/$f"; done

Feherke.
 
Use
Code:
> newdirectory/oldfile.zip
For example
Code:
for file in $(ls olddirectory)
do
  > newdirectory/$file
done
this will produce a zeor length file in newdirectory for every file in olddirectory. You can also use touch i.e.
Code:
for file in $(ls olddirectory)
do
  touch newdirectory/$file
done
will do the same thing

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top