Unix – How to convert to a zero byte file

command-lineshellunix

HI,

in unix there are number of files in my directory.
i want to change all the files to zero byte files.
is that possible on a single command line?

for example:

-rw-r--r--   1 sumanma  dev          434 Jan  8 14:36 pprbc_NL.cpp
-rw-r--r--   1 sumanma  dev          488 Jan  8 14:37 pprbc_TreeBuild.cpp
-rw-r--r--   1 sumanma  dev          783 Jan  8 14:37 pprbc_UPDwm.cpp

i want to change these to

-rw-r--r--   1 sumanma  dev          0 Jan  8 14:36 pprbc_NL.cpp
-rw-r--r--   1 sumanma  dev          0 Jan  8 14:37 pprbc_TreeBuild.cpp
-rw-r--r--   1 sumanma  dev          0 Jan  8 14:37 pprbc_UPDwm.cpp

I am using tcsh

Best Solution

Yes you can.

Try this

for i in *
do
 echo -n > $i
done

(Assuming bash here but the basic idea is the echo).

Edit : One liner (bash). You'll need the semicolons etc. which you won't need in the multiline version.

 for i in * ; do echo -n > $i ; done

Edit: If you're stuck using tcsh, you can always invoke bash to run a one liner like so

 bash -c 'for i in * ; do echo -n > $i ; done'