Posted: . At: 11:00 AM. This was 7 years ago. Post ID: 11431
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to find the line number in a file, that a certain line appears on.


This example is using grep on an assembler file to find an exact match for a certain line in the file and which line number it appears on.

ubuntu ~/Documents $ grep -x -n "; copy the virus, we have also to copy the section table, located before" virii.S
143:; copy the virus, we have also to copy the section table, located before

This is used when you have an entire line from the file and it is desired to know which line number it is on.

This even works when piping text into grep from another command.

ubuntu ~/Documents $ ps ax | grep -x "13594 pts/0    S      0:00 bash"
13594 pts/0    S      0:00 bash

Using tr, we can now make the result appear in uppercase!

ubuntu ~/Documents $ ps ax | grep -x "13594 pts/0    S      0:00 bash" | tr "[a-z]" "[A-Z]"
13594 PTS/0    S      0:00 BASH

Find out if Apache web server is running on your machine.

ubuntu ~/Documents $ ps -ef | egrep "apache"
root      4233     1  0 Oct01 ?        00:00:07 /usr/sbin/apache2 -k start
www-data  7643  4233  0 Oct02 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  7644  4233  0 Oct02 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  7645  4233  0 Oct02 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  7646  4233  0 Oct02 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  7647  4233  0 Oct02 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  7805  4233  0 Oct02 ?        00:00:00 /usr/sbin/apache2 -k start
www-data 10338  4233  0 Oct02 ?        00:00:00 /usr/sbin/apache2 -k start
www-data 10339  4233  0 Oct02 ?        00:00:00 /usr/sbin/apache2 -k start
www-data 10340  4233  0 Oct02 ?        00:00:00 /usr/sbin/apache2 -k start
ubuntu   13656 13594  0 23:40 pts/0    00:00:00 egrep --color=auto apache

How to find a file on your system that is SUID root.

ubuntu ~/Documents $ find /sbin \( -perm -4000 -o -perm -2000 ! -type d \) -exec ls -ldb {} \;
-rwxr-sr-x 1 root shadow 35536 Mar 16  2016 /sbin/unix_chkpwd

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.