cat /dev/null > fileABC; cat /dev/null/ > fileXYZ
tee
tee
command. echo -n
is considered better practice than cat /dev/null
, an even better solution would be to use printf '
, as noted by Charles Duffy. Resulting in following command:truncate
truncate
is probably the solution you were originally looking for. The command allows arbitrarily many file name arguments to be supplied. You can easily use it as follows:.java
and .c
source files in the current directory and in all directories inside the current directory.find .
execute find
in current directory .
-maxdepth 2
recursion level, descend to directories in directory but no further (level 2). Set this to 1 to not descend or n
to descend n
times.-type f
only apply to files, not directories-name '*.java'
only apply to files ending in .java
-exec truncate --size 0 '{}' ;
truncate each file found (file name is stored in {}
)man find
for more options and a more detailed explanation. Be sure to check it out because find
is one of the most powerful tools for automation of file editing. erasure
.while read file
for each line in the given file, store the line in variable file
do > '$file'
empty the file and output nothing in it (i.e. erase it)done < erasure
specify the input file using <
(redirection)0
). The correct loop now becomes: