showkey
showkey

Reputation: 298

How to write the wc's stdout into a file?

The below command will show how many characters contains in every file in current directory.

find  -name '*.*' |xargs  wc -c  

I want to write the standout into a file.

find  -name '*.*' |xargs  wc -c  > /tmp/record.txt

It encounter an issue:

wc: .: Is a directory

How to write all the standard output into a file?

Upvotes: 0

Views: 1092

Answers (3)

Quasímodo
Quasímodo

Reputation: 4004

Why -name '*.*'? That will not find every file and will find directories. You need to use -type f, and better than piping the result to xargs is using -exec:

find . -type f -maxdepth 1 -exec wc -c {} + > /tmp/record.txt

-maxdepth 1 guarantees that the search won't dive in subdirectories.

Upvotes: 1

KamilCuk
KamilCuk

Reputation: 141493

Filter only files, if you want only files.

find -type f

Upvotes: 0

LevitatingBusinessMan
LevitatingBusinessMan

Reputation: 339

I think you maybe meant find |xargs wc -c?

find -name '.' just returns .

Upvotes: 0

Related Questions