Find human-readable files
up vote
8
down vote
favorite
I am trying to find an efficient way to do the level 5 of the OverTheWire bandit challenge.
Anyway, I have a bunch of files, and there is only one that respects the following criteria:
- Human-readable
- 1033 bytes in size
- Non-executable
Right now, I am using the find
command, and I am able to find the files matching the 2 last criteria:
find . -size 1033c ! -executable
However, I don't know how to excluse non-human-readable files. Solutions I found for that challenge use the -readable
test parameter, but I don't think this works. -readable
only looks at the files' permissions, and not at its content, while the challenge description ask for an ASCII file or something like that.
files find
|
show 5 more comments
up vote
8
down vote
favorite
I am trying to find an efficient way to do the level 5 of the OverTheWire bandit challenge.
Anyway, I have a bunch of files, and there is only one that respects the following criteria:
- Human-readable
- 1033 bytes in size
- Non-executable
Right now, I am using the find
command, and I am able to find the files matching the 2 last criteria:
find . -size 1033c ! -executable
However, I don't know how to excluse non-human-readable files. Solutions I found for that challenge use the -readable
test parameter, but I don't think this works. -readable
only looks at the files' permissions, and not at its content, while the challenge description ask for an ASCII file or something like that.
files find
1
How do you define human readable? Not binary?
– terdon♦
Sep 30 '16 at 13:51
file command is your friend :)
– Romeo Ninov
Sep 30 '16 at 13:52
Maybe duplicate of: stackoverflow.com/questions/14505218/…
– zuazo
Sep 30 '16 at 13:55
@zuazo there's no such thing as cross-site duplicates. That post might have the answer, but it isn't a "duplicate".
– terdon♦
Sep 30 '16 at 13:56
2
Humans are one of the most intelligent known species on earth. They're also the only one known to versed with computers. They can read most files provided they can find out the type and get hold of the encryption keys for encrypted one.
– Stéphane Chazelas
Sep 30 '16 at 13:58
|
show 5 more comments
up vote
8
down vote
favorite
up vote
8
down vote
favorite
I am trying to find an efficient way to do the level 5 of the OverTheWire bandit challenge.
Anyway, I have a bunch of files, and there is only one that respects the following criteria:
- Human-readable
- 1033 bytes in size
- Non-executable
Right now, I am using the find
command, and I am able to find the files matching the 2 last criteria:
find . -size 1033c ! -executable
However, I don't know how to excluse non-human-readable files. Solutions I found for that challenge use the -readable
test parameter, but I don't think this works. -readable
only looks at the files' permissions, and not at its content, while the challenge description ask for an ASCII file or something like that.
files find
I am trying to find an efficient way to do the level 5 of the OverTheWire bandit challenge.
Anyway, I have a bunch of files, and there is only one that respects the following criteria:
- Human-readable
- 1033 bytes in size
- Non-executable
Right now, I am using the find
command, and I am able to find the files matching the 2 last criteria:
find . -size 1033c ! -executable
However, I don't know how to excluse non-human-readable files. Solutions I found for that challenge use the -readable
test parameter, but I don't think this works. -readable
only looks at the files' permissions, and not at its content, while the challenge description ask for an ASCII file or something like that.
files find
files find
edited Sep 30 '16 at 14:09
Jeff Schaller
37.4k1052121
37.4k1052121
asked Sep 30 '16 at 13:44
J.Doe
41112
41112
1
How do you define human readable? Not binary?
– terdon♦
Sep 30 '16 at 13:51
file command is your friend :)
– Romeo Ninov
Sep 30 '16 at 13:52
Maybe duplicate of: stackoverflow.com/questions/14505218/…
– zuazo
Sep 30 '16 at 13:55
@zuazo there's no such thing as cross-site duplicates. That post might have the answer, but it isn't a "duplicate".
– terdon♦
Sep 30 '16 at 13:56
2
Humans are one of the most intelligent known species on earth. They're also the only one known to versed with computers. They can read most files provided they can find out the type and get hold of the encryption keys for encrypted one.
– Stéphane Chazelas
Sep 30 '16 at 13:58
|
show 5 more comments
1
How do you define human readable? Not binary?
– terdon♦
Sep 30 '16 at 13:51
file command is your friend :)
– Romeo Ninov
Sep 30 '16 at 13:52
Maybe duplicate of: stackoverflow.com/questions/14505218/…
– zuazo
Sep 30 '16 at 13:55
@zuazo there's no such thing as cross-site duplicates. That post might have the answer, but it isn't a "duplicate".
– terdon♦
Sep 30 '16 at 13:56
2
Humans are one of the most intelligent known species on earth. They're also the only one known to versed with computers. They can read most files provided they can find out the type and get hold of the encryption keys for encrypted one.
– Stéphane Chazelas
Sep 30 '16 at 13:58
1
1
How do you define human readable? Not binary?
– terdon♦
Sep 30 '16 at 13:51
How do you define human readable? Not binary?
– terdon♦
Sep 30 '16 at 13:51
file command is your friend :)
– Romeo Ninov
Sep 30 '16 at 13:52
file command is your friend :)
– Romeo Ninov
Sep 30 '16 at 13:52
Maybe duplicate of: stackoverflow.com/questions/14505218/…
– zuazo
Sep 30 '16 at 13:55
Maybe duplicate of: stackoverflow.com/questions/14505218/…
– zuazo
Sep 30 '16 at 13:55
@zuazo there's no such thing as cross-site duplicates. That post might have the answer, but it isn't a "duplicate".
– terdon♦
Sep 30 '16 at 13:56
@zuazo there's no such thing as cross-site duplicates. That post might have the answer, but it isn't a "duplicate".
– terdon♦
Sep 30 '16 at 13:56
2
2
Humans are one of the most intelligent known species on earth. They're also the only one known to versed with computers. They can read most files provided they can find out the type and get hold of the encryption keys for encrypted one.
– Stéphane Chazelas
Sep 30 '16 at 13:58
Humans are one of the most intelligent known species on earth. They're also the only one known to versed with computers. They can read most files provided they can find out the type and get hold of the encryption keys for encrypted one.
– Stéphane Chazelas
Sep 30 '16 at 13:58
|
show 5 more comments
10 Answers
10
active
oldest
votes
up vote
9
down vote
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
.
add a comment |
up vote
2
down vote
While -exec
is mostly used to do something with the files that where found, it can also act as a test. Therefore, we can add it to your other criteria:
find .
-size 1033c
-not -executable
-exec sh -c 'file {} | grep "text$"' ;
Remember, grep
returns non-zero when the pattern wasn't found, and sh -c "COMMAND"
will return the result of the evaluation (as long as it's valid). So this will only print files where file <filename>
spits something out that ends with text
, e.g. "UTF-8 Unicode text` or "ASCII text", but not "Non-ISO extended-ASCII text, with escape sequences".
In a single line, it even ends up shorter than going over xargs
:
find . -size 1033c -not -executable -exec sh -c 'file {} | grep "text$"' ;
Keep in mind that you can replace sh -c 'file {} | grep "text$"'
with any custom command. If you want to check for something very complex, it might be a better idea to provide a shell script and use that instead:
find . -size 1033c -not -executable -exec is_human_readable.sh {} ;
which, in the long run, is easier to maintain than your shell's history:
#!/bin/sh
file "$@" | grep "text$" > /dev/null
Nice! Note, however, that matchingtext$
will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.
– terdon♦
Sep 30 '16 at 14:39
@terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
– Zeta
Sep 30 '16 at 14:43
add a comment |
up vote
1
down vote
find . -size 1033c ! -executable -exec file {} +
add a comment |
up vote
0
down vote
find . -size 1033c ! -executable|xargs file|grep "ASCII text" |awk -F: '{print $1}'
Please try this combined commands. it works on my station.
add a comment |
up vote
0
down vote
You can try this
find . -size 1033c ! -executable -exec file {} +
Your challenge does not allows grep
. password file will be reported as "ASCII text, with very long lines"
add a comment |
up vote
0
down vote
To filter out the human-readable file names, you can make use of the [:print:]
(printable) character class name. You will find more about such classes in the manual for grep
.
find . -type f -size 1033c -name "[[:print:]]*" ! -executable
On a second thought, the "human-readable" requirement might refer to the file's content, instead of its name. In other words, you would be searching for text files. That is a little more tricky. As @D_Bye suggested in a comment, you should then use the file
command to determine the file content type. But it would not be a good idea to run file
after a pipe, because it would complicate the task of displaying the file's name. Here's what I suggest:
find . -type f -size 1033c ! -executable -exec sh -c 'file -b $0 | grep -q text' {} ; -print
This is briefly how the file
-part works:
- The
-exec
predicate executessh -c 'file -b $0 | grep -q text' FILENAME
for eachFILENAME
that satisfies all the previous conditions (type, size, non-executable). - For each of those files, a shell (
sh
) runs this short script:file -b $0 | grep -q text
, replacing$0
with the filename. - The
file
program determines the content type of each file and outputs this information. The-b
option prevents printing the name of each tested file.
grep
filters the output coming fromfile
program, searching for lines containing "text". (See for yourself, how a typical output of thefile
command looks like.)- But
grep
does not output the filtered text, because it has the-q
(quiet) option given. What it does, is just change its exit status to either0
(which represents "true" - the filtered text was found) or 1 (meaning "error" - the text "text" did not appear in the output fromfile
). - The true/false exit status coming from
grep
is passed further bysh
tofind
and acts as the final result of the whole "-exec sh -c 'file $0 | grep -q text' {} ;
" test. - In case the above test returned true, the
-print
command is executed (i.e. the name of the tested file is printed).
add a comment |
up vote
0
down vote
You only need to use:
find inhere -size 1033c
It will give you the only file that contains the password.
add a comment |
up vote
0
down vote
bandit4@bandit:~$ ls
inhere
bandit4@bandit:~$ file inhere/*
inhere/-file00: data
inhere/-file01: data
inhere/-file02: data
inhere/-file03: data
inhere/-file04: data
inhere/-file05: data
inhere/-file06: data
inhere/-file07: ASCII text
inhere/-file08: data
inhere/-file09: data
bandit4@bandit:~$ pwd
/home/bandit4
bandit4@bandit:~$ cat /home/bandit4/inhere/-file07
koReBOKuIDDepwhWk7jZC0RTdopnAYKh
bandit4@bandit:~$
Simply use file inhere/* and cat /home/bandit4/inhere/-file07
– user234732
Jun 5 '17 at 22:41
add a comment |
up vote
0
down vote
find -type f ! -executable -size 1033c
will get you the file from the exercise
add a comment |
up vote
-1
down vote
du --human-readable | find -not -executable -size 1033c
will get your result
New contributor
add a comment |
10 Answers
10
active
oldest
votes
10 Answers
10
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
9
down vote
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
.
add a comment |
up vote
9
down vote
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
.
add a comment |
up vote
9
down vote
up vote
9
down vote
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
.
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
.
answered Sep 30 '16 at 14:36
terdon♦
127k31245422
127k31245422
add a comment |
add a comment |
up vote
2
down vote
While -exec
is mostly used to do something with the files that where found, it can also act as a test. Therefore, we can add it to your other criteria:
find .
-size 1033c
-not -executable
-exec sh -c 'file {} | grep "text$"' ;
Remember, grep
returns non-zero when the pattern wasn't found, and sh -c "COMMAND"
will return the result of the evaluation (as long as it's valid). So this will only print files where file <filename>
spits something out that ends with text
, e.g. "UTF-8 Unicode text` or "ASCII text", but not "Non-ISO extended-ASCII text, with escape sequences".
In a single line, it even ends up shorter than going over xargs
:
find . -size 1033c -not -executable -exec sh -c 'file {} | grep "text$"' ;
Keep in mind that you can replace sh -c 'file {} | grep "text$"'
with any custom command. If you want to check for something very complex, it might be a better idea to provide a shell script and use that instead:
find . -size 1033c -not -executable -exec is_human_readable.sh {} ;
which, in the long run, is easier to maintain than your shell's history:
#!/bin/sh
file "$@" | grep "text$" > /dev/null
Nice! Note, however, that matchingtext$
will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.
– terdon♦
Sep 30 '16 at 14:39
@terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
– Zeta
Sep 30 '16 at 14:43
add a comment |
up vote
2
down vote
While -exec
is mostly used to do something with the files that where found, it can also act as a test. Therefore, we can add it to your other criteria:
find .
-size 1033c
-not -executable
-exec sh -c 'file {} | grep "text$"' ;
Remember, grep
returns non-zero when the pattern wasn't found, and sh -c "COMMAND"
will return the result of the evaluation (as long as it's valid). So this will only print files where file <filename>
spits something out that ends with text
, e.g. "UTF-8 Unicode text` or "ASCII text", but not "Non-ISO extended-ASCII text, with escape sequences".
In a single line, it even ends up shorter than going over xargs
:
find . -size 1033c -not -executable -exec sh -c 'file {} | grep "text$"' ;
Keep in mind that you can replace sh -c 'file {} | grep "text$"'
with any custom command. If you want to check for something very complex, it might be a better idea to provide a shell script and use that instead:
find . -size 1033c -not -executable -exec is_human_readable.sh {} ;
which, in the long run, is easier to maintain than your shell's history:
#!/bin/sh
file "$@" | grep "text$" > /dev/null
Nice! Note, however, that matchingtext$
will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.
– terdon♦
Sep 30 '16 at 14:39
@terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
– Zeta
Sep 30 '16 at 14:43
add a comment |
up vote
2
down vote
up vote
2
down vote
While -exec
is mostly used to do something with the files that where found, it can also act as a test. Therefore, we can add it to your other criteria:
find .
-size 1033c
-not -executable
-exec sh -c 'file {} | grep "text$"' ;
Remember, grep
returns non-zero when the pattern wasn't found, and sh -c "COMMAND"
will return the result of the evaluation (as long as it's valid). So this will only print files where file <filename>
spits something out that ends with text
, e.g. "UTF-8 Unicode text` or "ASCII text", but not "Non-ISO extended-ASCII text, with escape sequences".
In a single line, it even ends up shorter than going over xargs
:
find . -size 1033c -not -executable -exec sh -c 'file {} | grep "text$"' ;
Keep in mind that you can replace sh -c 'file {} | grep "text$"'
with any custom command. If you want to check for something very complex, it might be a better idea to provide a shell script and use that instead:
find . -size 1033c -not -executable -exec is_human_readable.sh {} ;
which, in the long run, is easier to maintain than your shell's history:
#!/bin/sh
file "$@" | grep "text$" > /dev/null
While -exec
is mostly used to do something with the files that where found, it can also act as a test. Therefore, we can add it to your other criteria:
find .
-size 1033c
-not -executable
-exec sh -c 'file {} | grep "text$"' ;
Remember, grep
returns non-zero when the pattern wasn't found, and sh -c "COMMAND"
will return the result of the evaluation (as long as it's valid). So this will only print files where file <filename>
spits something out that ends with text
, e.g. "UTF-8 Unicode text` or "ASCII text", but not "Non-ISO extended-ASCII text, with escape sequences".
In a single line, it even ends up shorter than going over xargs
:
find . -size 1033c -not -executable -exec sh -c 'file {} | grep "text$"' ;
Keep in mind that you can replace sh -c 'file {} | grep "text$"'
with any custom command. If you want to check for something very complex, it might be a better idea to provide a shell script and use that instead:
find . -size 1033c -not -executable -exec is_human_readable.sh {} ;
which, in the long run, is easier to maintain than your shell's history:
#!/bin/sh
file "$@" | grep "text$" > /dev/null
answered Sep 30 '16 at 14:36
Zeta
45627
45627
Nice! Note, however, that matchingtext$
will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.
– terdon♦
Sep 30 '16 at 14:39
@terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
– Zeta
Sep 30 '16 at 14:43
add a comment |
Nice! Note, however, that matchingtext$
will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.
– terdon♦
Sep 30 '16 at 14:39
@terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
– Zeta
Sep 30 '16 at 14:43
Nice! Note, however, that matching
text$
will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.– terdon♦
Sep 30 '16 at 14:39
Nice! Note, however, that matching
text$
will exclude things recognized as shell scripts. Anything with a shebang is identified as a script, and those are perfectly human readable.– terdon♦
Sep 30 '16 at 14:39
@terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
– Zeta
Sep 30 '16 at 14:43
@terdon true, but scripts tend to be executable :D. That being said, a proper script should also recognize PDFs. But on the other hand, is a PDF containing an image human readable? Is a PNG of some text readable? Probably. I guess a complet test will be… challenging.
– Zeta
Sep 30 '16 at 14:43
add a comment |
up vote
1
down vote
find . -size 1033c ! -executable -exec file {} +
add a comment |
up vote
1
down vote
find . -size 1033c ! -executable -exec file {} +
add a comment |
up vote
1
down vote
up vote
1
down vote
find . -size 1033c ! -executable -exec file {} +
find . -size 1033c ! -executable -exec file {} +
edited Aug 16 at 11:21
jimmij
30.5k869103
30.5k869103
answered Aug 16 at 10:22
user305801
111
111
add a comment |
add a comment |
up vote
0
down vote
find . -size 1033c ! -executable|xargs file|grep "ASCII text" |awk -F: '{print $1}'
Please try this combined commands. it works on my station.
add a comment |
up vote
0
down vote
find . -size 1033c ! -executable|xargs file|grep "ASCII text" |awk -F: '{print $1}'
Please try this combined commands. it works on my station.
add a comment |
up vote
0
down vote
up vote
0
down vote
find . -size 1033c ! -executable|xargs file|grep "ASCII text" |awk -F: '{print $1}'
Please try this combined commands. it works on my station.
find . -size 1033c ! -executable|xargs file|grep "ASCII text" |awk -F: '{print $1}'
Please try this combined commands. it works on my station.
answered Sep 30 '16 at 14:11
Fengbo Wu
11
11
add a comment |
add a comment |
up vote
0
down vote
You can try this
find . -size 1033c ! -executable -exec file {} +
Your challenge does not allows grep
. password file will be reported as "ASCII text, with very long lines"
add a comment |
up vote
0
down vote
You can try this
find . -size 1033c ! -executable -exec file {} +
Your challenge does not allows grep
. password file will be reported as "ASCII text, with very long lines"
add a comment |
up vote
0
down vote
up vote
0
down vote
You can try this
find . -size 1033c ! -executable -exec file {} +
Your challenge does not allows grep
. password file will be reported as "ASCII text, with very long lines"
You can try this
find . -size 1033c ! -executable -exec file {} +
Your challenge does not allows grep
. password file will be reported as "ASCII text, with very long lines"
edited Sep 30 '16 at 14:52
answered Sep 30 '16 at 13:57
Emmanuel
2,98911120
2,98911120
add a comment |
add a comment |
up vote
0
down vote
To filter out the human-readable file names, you can make use of the [:print:]
(printable) character class name. You will find more about such classes in the manual for grep
.
find . -type f -size 1033c -name "[[:print:]]*" ! -executable
On a second thought, the "human-readable" requirement might refer to the file's content, instead of its name. In other words, you would be searching for text files. That is a little more tricky. As @D_Bye suggested in a comment, you should then use the file
command to determine the file content type. But it would not be a good idea to run file
after a pipe, because it would complicate the task of displaying the file's name. Here's what I suggest:
find . -type f -size 1033c ! -executable -exec sh -c 'file -b $0 | grep -q text' {} ; -print
This is briefly how the file
-part works:
- The
-exec
predicate executessh -c 'file -b $0 | grep -q text' FILENAME
for eachFILENAME
that satisfies all the previous conditions (type, size, non-executable). - For each of those files, a shell (
sh
) runs this short script:file -b $0 | grep -q text
, replacing$0
with the filename. - The
file
program determines the content type of each file and outputs this information. The-b
option prevents printing the name of each tested file.
grep
filters the output coming fromfile
program, searching for lines containing "text". (See for yourself, how a typical output of thefile
command looks like.)- But
grep
does not output the filtered text, because it has the-q
(quiet) option given. What it does, is just change its exit status to either0
(which represents "true" - the filtered text was found) or 1 (meaning "error" - the text "text" did not appear in the output fromfile
). - The true/false exit status coming from
grep
is passed further bysh
tofind
and acts as the final result of the whole "-exec sh -c 'file $0 | grep -q text' {} ;
" test. - In case the above test returned true, the
-print
command is executed (i.e. the name of the tested file is printed).
add a comment |
up vote
0
down vote
To filter out the human-readable file names, you can make use of the [:print:]
(printable) character class name. You will find more about such classes in the manual for grep
.
find . -type f -size 1033c -name "[[:print:]]*" ! -executable
On a second thought, the "human-readable" requirement might refer to the file's content, instead of its name. In other words, you would be searching for text files. That is a little more tricky. As @D_Bye suggested in a comment, you should then use the file
command to determine the file content type. But it would not be a good idea to run file
after a pipe, because it would complicate the task of displaying the file's name. Here's what I suggest:
find . -type f -size 1033c ! -executable -exec sh -c 'file -b $0 | grep -q text' {} ; -print
This is briefly how the file
-part works:
- The
-exec
predicate executessh -c 'file -b $0 | grep -q text' FILENAME
for eachFILENAME
that satisfies all the previous conditions (type, size, non-executable). - For each of those files, a shell (
sh
) runs this short script:file -b $0 | grep -q text
, replacing$0
with the filename. - The
file
program determines the content type of each file and outputs this information. The-b
option prevents printing the name of each tested file.
grep
filters the output coming fromfile
program, searching for lines containing "text". (See for yourself, how a typical output of thefile
command looks like.)- But
grep
does not output the filtered text, because it has the-q
(quiet) option given. What it does, is just change its exit status to either0
(which represents "true" - the filtered text was found) or 1 (meaning "error" - the text "text" did not appear in the output fromfile
). - The true/false exit status coming from
grep
is passed further bysh
tofind
and acts as the final result of the whole "-exec sh -c 'file $0 | grep -q text' {} ;
" test. - In case the above test returned true, the
-print
command is executed (i.e. the name of the tested file is printed).
add a comment |
up vote
0
down vote
up vote
0
down vote
To filter out the human-readable file names, you can make use of the [:print:]
(printable) character class name. You will find more about such classes in the manual for grep
.
find . -type f -size 1033c -name "[[:print:]]*" ! -executable
On a second thought, the "human-readable" requirement might refer to the file's content, instead of its name. In other words, you would be searching for text files. That is a little more tricky. As @D_Bye suggested in a comment, you should then use the file
command to determine the file content type. But it would not be a good idea to run file
after a pipe, because it would complicate the task of displaying the file's name. Here's what I suggest:
find . -type f -size 1033c ! -executable -exec sh -c 'file -b $0 | grep -q text' {} ; -print
This is briefly how the file
-part works:
- The
-exec
predicate executessh -c 'file -b $0 | grep -q text' FILENAME
for eachFILENAME
that satisfies all the previous conditions (type, size, non-executable). - For each of those files, a shell (
sh
) runs this short script:file -b $0 | grep -q text
, replacing$0
with the filename. - The
file
program determines the content type of each file and outputs this information. The-b
option prevents printing the name of each tested file.
grep
filters the output coming fromfile
program, searching for lines containing "text". (See for yourself, how a typical output of thefile
command looks like.)- But
grep
does not output the filtered text, because it has the-q
(quiet) option given. What it does, is just change its exit status to either0
(which represents "true" - the filtered text was found) or 1 (meaning "error" - the text "text" did not appear in the output fromfile
). - The true/false exit status coming from
grep
is passed further bysh
tofind
and acts as the final result of the whole "-exec sh -c 'file $0 | grep -q text' {} ;
" test. - In case the above test returned true, the
-print
command is executed (i.e. the name of the tested file is printed).
To filter out the human-readable file names, you can make use of the [:print:]
(printable) character class name. You will find more about such classes in the manual for grep
.
find . -type f -size 1033c -name "[[:print:]]*" ! -executable
On a second thought, the "human-readable" requirement might refer to the file's content, instead of its name. In other words, you would be searching for text files. That is a little more tricky. As @D_Bye suggested in a comment, you should then use the file
command to determine the file content type. But it would not be a good idea to run file
after a pipe, because it would complicate the task of displaying the file's name. Here's what I suggest:
find . -type f -size 1033c ! -executable -exec sh -c 'file -b $0 | grep -q text' {} ; -print
This is briefly how the file
-part works:
- The
-exec
predicate executessh -c 'file -b $0 | grep -q text' FILENAME
for eachFILENAME
that satisfies all the previous conditions (type, size, non-executable). - For each of those files, a shell (
sh
) runs this short script:file -b $0 | grep -q text
, replacing$0
with the filename. - The
file
program determines the content type of each file and outputs this information. The-b
option prevents printing the name of each tested file.
grep
filters the output coming fromfile
program, searching for lines containing "text". (See for yourself, how a typical output of thefile
command looks like.)- But
grep
does not output the filtered text, because it has the-q
(quiet) option given. What it does, is just change its exit status to either0
(which represents "true" - the filtered text was found) or 1 (meaning "error" - the text "text" did not appear in the output fromfile
). - The true/false exit status coming from
grep
is passed further bysh
tofind
and acts as the final result of the whole "-exec sh -c 'file $0 | grep -q text' {} ;
" test. - In case the above test returned true, the
-print
command is executed (i.e. the name of the tested file is printed).
answered Mar 13 '17 at 19:13
Alfran
1011
1011
add a comment |
add a comment |
up vote
0
down vote
You only need to use:
find inhere -size 1033c
It will give you the only file that contains the password.
add a comment |
up vote
0
down vote
You only need to use:
find inhere -size 1033c
It will give you the only file that contains the password.
add a comment |
up vote
0
down vote
up vote
0
down vote
You only need to use:
find inhere -size 1033c
It will give you the only file that contains the password.
You only need to use:
find inhere -size 1033c
It will give you the only file that contains the password.
answered Mar 26 '17 at 0:09
BugHunterUK
178119
178119
add a comment |
add a comment |
up vote
0
down vote
bandit4@bandit:~$ ls
inhere
bandit4@bandit:~$ file inhere/*
inhere/-file00: data
inhere/-file01: data
inhere/-file02: data
inhere/-file03: data
inhere/-file04: data
inhere/-file05: data
inhere/-file06: data
inhere/-file07: ASCII text
inhere/-file08: data
inhere/-file09: data
bandit4@bandit:~$ pwd
/home/bandit4
bandit4@bandit:~$ cat /home/bandit4/inhere/-file07
koReBOKuIDDepwhWk7jZC0RTdopnAYKh
bandit4@bandit:~$
Simply use file inhere/* and cat /home/bandit4/inhere/-file07
– user234732
Jun 5 '17 at 22:41
add a comment |
up vote
0
down vote
bandit4@bandit:~$ ls
inhere
bandit4@bandit:~$ file inhere/*
inhere/-file00: data
inhere/-file01: data
inhere/-file02: data
inhere/-file03: data
inhere/-file04: data
inhere/-file05: data
inhere/-file06: data
inhere/-file07: ASCII text
inhere/-file08: data
inhere/-file09: data
bandit4@bandit:~$ pwd
/home/bandit4
bandit4@bandit:~$ cat /home/bandit4/inhere/-file07
koReBOKuIDDepwhWk7jZC0RTdopnAYKh
bandit4@bandit:~$
Simply use file inhere/* and cat /home/bandit4/inhere/-file07
– user234732
Jun 5 '17 at 22:41
add a comment |
up vote
0
down vote
up vote
0
down vote
bandit4@bandit:~$ ls
inhere
bandit4@bandit:~$ file inhere/*
inhere/-file00: data
inhere/-file01: data
inhere/-file02: data
inhere/-file03: data
inhere/-file04: data
inhere/-file05: data
inhere/-file06: data
inhere/-file07: ASCII text
inhere/-file08: data
inhere/-file09: data
bandit4@bandit:~$ pwd
/home/bandit4
bandit4@bandit:~$ cat /home/bandit4/inhere/-file07
koReBOKuIDDepwhWk7jZC0RTdopnAYKh
bandit4@bandit:~$
bandit4@bandit:~$ ls
inhere
bandit4@bandit:~$ file inhere/*
inhere/-file00: data
inhere/-file01: data
inhere/-file02: data
inhere/-file03: data
inhere/-file04: data
inhere/-file05: data
inhere/-file06: data
inhere/-file07: ASCII text
inhere/-file08: data
inhere/-file09: data
bandit4@bandit:~$ pwd
/home/bandit4
bandit4@bandit:~$ cat /home/bandit4/inhere/-file07
koReBOKuIDDepwhWk7jZC0RTdopnAYKh
bandit4@bandit:~$
edited Aug 2 at 16:00
Jesse_b
11.5k23063
11.5k23063
answered Jun 5 '17 at 22:38
user234732
Simply use file inhere/* and cat /home/bandit4/inhere/-file07
– user234732
Jun 5 '17 at 22:41
add a comment |
Simply use file inhere/* and cat /home/bandit4/inhere/-file07
– user234732
Jun 5 '17 at 22:41
Simply use file inhere/* and cat /home/bandit4/inhere/-file07
– user234732
Jun 5 '17 at 22:41
Simply use file inhere/* and cat /home/bandit4/inhere/-file07
– user234732
Jun 5 '17 at 22:41
add a comment |
up vote
0
down vote
find -type f ! -executable -size 1033c
will get you the file from the exercise
add a comment |
up vote
0
down vote
find -type f ! -executable -size 1033c
will get you the file from the exercise
add a comment |
up vote
0
down vote
up vote
0
down vote
find -type f ! -executable -size 1033c
will get you the file from the exercise
find -type f ! -executable -size 1033c
will get you the file from the exercise
answered Sep 29 at 12:42
coolhand
1092
1092
add a comment |
add a comment |
up vote
-1
down vote
du --human-readable | find -not -executable -size 1033c
will get your result
New contributor
add a comment |
up vote
-1
down vote
du --human-readable | find -not -executable -size 1033c
will get your result
New contributor
add a comment |
up vote
-1
down vote
up vote
-1
down vote
du --human-readable | find -not -executable -size 1033c
will get your result
New contributor
du --human-readable | find -not -executable -size 1033c
will get your result
New contributor
edited 16 hours ago
New contributor
answered 16 hours ago
Varun Rathore
11
11
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f313442%2ffind-human-readable-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
How do you define human readable? Not binary?
– terdon♦
Sep 30 '16 at 13:51
file command is your friend :)
– Romeo Ninov
Sep 30 '16 at 13:52
Maybe duplicate of: stackoverflow.com/questions/14505218/…
– zuazo
Sep 30 '16 at 13:55
@zuazo there's no such thing as cross-site duplicates. That post might have the answer, but it isn't a "duplicate".
– terdon♦
Sep 30 '16 at 13:56
2
Humans are one of the most intelligent known species on earth. They're also the only one known to versed with computers. They can read most files provided they can find out the type and get hold of the encryption keys for encrypted one.
– Stéphane Chazelas
Sep 30 '16 at 13:58