Yes, you can use find
to look for non-executable files of the right size and then use file
to check for ASCII. Something like:
find . -type f -size 1033c ! -executable -exec file {} + | grep ASCII
The question, however, isn't as simple as it sounds. 'Human readable' is a horribly vague term. Presumably, you mean text. OK, but what kind of text? Latin character ASCII only? Full Unicode? For example, consider these three files:
$ cat file1
abcde
$ cat file2
αβγδε
$ cat file3
abcde
αβγδε
$ cat file4
#!/bin/sh
echo foo
These are all text and human readable. Now, let's see what file
makes of them:
$ file *
file1: ASCII text
file2: UTF-8 Unicode text
file3: UTF-8 Unicode text
file4: POSIX shell script, ASCII text executable
So, the find
command above will only find file1
(for the sake of this example, let's imagine those files had 1033 characters). You could expand the find
to look for the string text
:
find . -type f -size 1033c ! -executable -exec file {} + | grep -w text
With the -w
, grep
will only print lines where text
is found as a stand-alone word. That should be pretty close to what you want, but I can't guarantee that there is no other file type whose description might also include the string text
.
There's no built-in tar
option, but you can filter its output. For example, using humanize:
#!/usr/bin/env python
import fileinput
import humanize
for line in fileinput.input():
(perm, owner, size, date, time, filename) = tuple(line.split())
print '{0} {1} {2:>9} {3} {4} {5}'.format(perm, owner, humanize.naturalsize(size, gnu=True), date, time, filename)
Save this as e.g. humantvf
, then
tar tvf ... | ./humantvf
Best Answer
Since you're already using GNU tools, see
numfmt
from GNU coreutils:With
ksh93
:Or if built with the
ls
builtin (which you can also get as a standalone utility in the ast-open package):