Command to determine the public IP in Linux OS

If you are behind a router, then your computer will not know about the public IP address as the router does a network address translation.

If you are not behind a router, you can find it out using ifconfig. Else you could request this website using curl or wget and extract the information you need from it, e.g. using a perl script.

curl -s checkip.dyndns.org | sed -e ‘s/.*Current IP Address: //’ -e ‘s/<.*$//’
or shorter

wget http://ipinfo.io/ip -qO –

should do the trick.

Delete / truncate the entries in a file

The following command is the efficient one to delete/truncate all the entries from a file which is being actively used:

truncate -s 0 filename

Refer: http://linux.die.net/man/1/truncate

 

On the other hand, truncate would likely be slower than > filename when run from a script since running the truncate command requires the system to open the executable, load it, and the run it.

Delete files of certain size range using FIND command

Delete files of certain size range using FIND command:

find /path -type f -name “*.tmp” -size +500M  -size –100G -exec rm -fv {} \;

–> size is a numeric argument that can optionally be prefixed with + and –

Numeric arguments can be specified as:
+n    for greater than n,
-n     for less than n,
n      for exactly n.

 

Usage:

-size n[cwbkMG]
File uses n units of space.  The following suffixes can be used:

`b’    for 512-byte blocks (this is the default if no suffix is used)

`c’    for bytes

`w’    for two-byte words

`k’    for Kilobytes (units of 1024 bytes)

`M’    for Megabytes (units of 1048576 bytes)

`G’    for Gigabytes (units of 1073741824 bytes)