Find all scripts with a given shebang line with find & sed
6
votes
5
answers
2401
views
I want to find out all scripts with a specific shebang line. Specifically, I want all files that match the following criteria:
* It's mostly a plain text file (stuffs created by
gzexe
don't look very friendly)
* The 1st line contains solely #!/bin/sh
or #! /bin/sh
(with a space)
I would like to do this with find
, sed
and grep
(file
available).
File names are useless, because some scripts don't have extensions or even have wrong extensions. Also a something.sh
may have a shebang line of #!/bin/bash
which is also not what I wanted.
Besides, sometimes I would come across a file like this:
#!/bin/sh blah.blah.blah...The 1st line is empty and the shebang is located at the 2nd line, which **is not what I wanted**. I am able to find shebang lines with
find|grep
but I don't know how to find lines **specifically on the 1st line** of a file.
Thanks for any help in advance.
Asked by iBug
(3638 rep)
Apr 2, 2017, 04:45 AM
Last activity: Mar 18, 2024, 02:24 PM
Last activity: Mar 18, 2024, 02:24 PM