Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm scanning for all shell scripts on my server, and are doing this by the following command:

find / -type f -exec file --mime-type {} \; | grep "text/x-shellscript"

This is working fine, and here is a sample output from this:

/lib/udev/hwclock-set: text/x-shellscript
/lib/init/ text/x-shellscript
/etc/network/if-up.d/openssh-server: text/x-shellscript
/etc/network/if-up.d/mountnfs: text/x-shellscript

Now, I want to work on the filenames, and try to use awk for this:

find / -type f -exec file --mime-type {} \; | grep "text/x-shellscript" | awk -F: '{ print $1 }'

This however, does not produce any output. Ive tried redirecting pipes etc, but here I've hit the wall.

Anyone have an idea of what I'm doing wrong?

share|improve this question
What happens with echo "/etc/network/if-up.d/mountnfs: text/x-shellscript" | awk -F: '{ print $1 }'? – Daniel Beck Oct 16 '11 at 13:51
@DanielBeck That works. Maybe find does not write to stdout? But then I can't explain how grep to do its part... – Dog eat cat world Oct 16 '11 at 13:53
You can redirect error output to standard output. Your command will then look like this: find / -type f -exec file --meta-type {} \; | grep "text/x-shellscript" 2>&1 | awk -F: '{ print $1 }' – Daniel Beck Oct 16 '11 at 14:03
@DanielBeck No, it does not help. I've tried "find / -type f -exec file --mime-type {} \; | grep "text/x-shellscript" 2>&1 1>this_file_should_not_be_empty", but it seems like grep is outputting to nowhere! Even if the text is displayed on the monitor without pipe redirection. – Dog eat cat world Oct 16 '11 at 14:20
You can narrow your problem locus, and get rid of one of those tags on the question, by eliminating the useless use of grep there. – JdeBP Oct 16 '11 at 15:41

Try this:

  find / -type f -exec file --meta-type {} \; | grep "text/x-shellscript" | cut -d: -f 1
share|improve this answer
Thanks, this works. But I'm still curious why awk doesn't – Dog eat cat world Oct 16 '11 at 13:54
Your awk command works fine here, there's nothing wrong with it. If you're embedding this pipe into some other command (backticks, etc.) then the only difference I can think of is the single quotes you use in awk command. – haimg Oct 16 '11 at 14:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.