Skip to main content


Searching files in Linux

Search the whole directory:

    find / -name "php.ini" -print

    find / -name "owncloud.conf" -print

Using whereis command:

  whereis php.ini

From man whereis (command):
       whereis  -  locate the binary, source, and manual page files for a com-

Using locate command:

locate php.ini

From man locate (command):
       locate - find files by name

To find out more, type at terminal:

    info locate
    info whereis

    locate --help
    whereis --help

Cheers..till next time.

================================ Free Android Apps:
Click on links below to find out more:
Linux Android App cheat sheet:
Multiplication Table for early learners
Catholic Rosary Guide  for Android:

Linux Awk insert text at specific line number

One liner command for Awk to insert a new string or text at a specific line number on a file.

awk 'NR==3{print "new line text at row 3"}1' original_file.txt > modified_file.txt

'NR==3 --insert string or data at line number 3
"}1' -- number 1 (can be any number) means to append the new text or string
> modified_file.txt -- redirect the output to a new file

To find out more, type this at the terminal.

                info awk
                info print
                man awk
                man print

Or you can redirect the output of info and man to a file for offline viewing.

Check out links below for other examples of awk command.

Tools for Linux Troubleshooting

A basic troubleshooting skill is just necessary for a System Administrator. One way or another thing will go south, no matter how you make sure that the system is working perfectly healthy.
Patches, updates, new security holes or vulnerabilities will definitely change the whole system and if something goes wrong, then a working system will need troubleshooting.
Even new system configuration changes that are not recorded and left forgotten and cause an adverse effect that is applied to the system will cause chaos and more time will be spent in troubleshooting, only to find out that a minor change causes the whole thing.
Here are some tools below, which could provide a basic troubleshooting to a Linux system.
A general purpose logs files, which shows messages from the system.
    tail -f /var/log/messages
/var/log/  -- directories which contains log files for the system. This directory can easily fill up the space of the whole system if not the log files are not managed properly.

Linux Check IP Address or MAC Address

Linux good old command to check IP Address is  ifconfig which works probably in all distro.

There is already new implementation on how to check the IP Address via command line from some distro.

Some distro now supports the command, ip addr show which also displays the IP Address.

The ifconfig command has a long output, which is quite scary if you are new to Linux.

To filter the desired output in ifconfig, awk or gawk will come to the rescue.

Below are some examples on how to do it:

Display only the IP Address:

ifconfig -a | awk 'NR==2'

Sample Output:
inet addr: Bcast: Mask:

Display only the MAC Address:

ifconfig -a | awk 'NR==1'

Sample Output:
eth0  Link encap:Ethernet  HWaddr 07:00:16:f1:bb:ac
HWaddr is the MAC Address

Display both IP and MAC Address:

ifconfig -a | awk 'NR==1,NR==2'

Using awk command ifconfig output is displayed line by line.

Some other useful command below to check users login in Linux.

last /var/log/wtmp
last /v…

Linux count string occurrences

How to use grep in Linux to count string occurrences?

grep -oi "error" /home/xlog/xerrorlogs.txt| wc -l
Sample output: 5 (if there are 5 matches)
Grep will look for the word "error" in xerrorlogs.txt and count its occurrence per line.
Grep will find the string occurrence without case sensitivity.
Grep parameters: -o --only-matching Print only the matched (non-empty) parts of matching lines, with each such part on a separate output line. -i --ignore-case Ignore case distinctions, so that characters that differ only in case match each other. wc - print newline, word, and byte counts for each file -l, --lines print the newline counts
If "wc -l" is omitted: grep -oi "error" /home/xlog/xerrorlogs.txt
Grep will display the match string.
Sample output: Error Error Error Error Error
If Grep uses -c parameter: grep -oic "error" /home/xlog/xerrorlogs.txt 
Sample output: 4
The output is "4" if there are 5 matches since counting starts at ze…