Domanda

I have a folder contains ~30000 files and some of them are empty. I want to find them and put 'NON' as a header of the empty files.

my script is:

 find -type f -empty -exec echo 'NON' {} \;

my output is:

 NON ./file1
 NON ./file2
 NON ./file3
 NON ./file4

but I want the 'NON' to write as a header of the file1 , file2 , file3 and file4.

Thanks in advance.

È stato utile?

Soluzione

Why not just echo NON first and then do your find, with no need for exec?

Also I am not sure how you are running find without specifying a directory to search, so I have added the current directory to search below.

 echo 'NON'
 find . -type f -empty

The other possible interpretation of your question is that you want to add the string NON to all zero-length files. You can do that like this.

find . -type f -empty -exec sh -c "echo NON > {}" \;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top