Monday, June 13, 2016

Quickly deleting large file

Deleting larger file takes time, but when we dont want the file, why shout be their waiting time to delete it.

These files i am deleting

-rw-r--r--  1 sanjeev.tripurari  1114871328  24931090000 Jun 13 17:28 words3.txt
-rw-r--r--  1 sanjeev.tripurari  1114871328  24931090000 Jun 13 17:28 words2.txt

Normal deletion

$ time rm -fv words2.txt 
words2.txt

real 0m0.672s
user 0m0.001s
sys 0m0.080s


copy /dev/null will make it zerobyte quickly and then delete 

$ time cp -v /dev/null words3.txt 
/dev/null -> words3.txt

real 0m0.321s
user 0m0.001s
sys 0m0.294s


$ time rm -fv words3.txt 
words3.txt

real 0m0.006s
user 0m0.001s
sys 0m0.003s



Sunday, June 12, 2016

quick share code snippet

We often need to share the code snippet or some text file for review or comments, attaching to chat window or mail take time.

we can run netcat and expose the code on the web and do the quick correction,

$ cat poweroff.sh |nc   -l   0.0.0.0 8088

yes though it just stays for one instance, it saves time of getting on to another application,

the remote user can now use curl/links

function retun value

Have been using bash for long, and never expected to have return value, as the function was written just do the repetative job

But when we need a bash function to return value, be sure that it just has one echo which is for return, any other display will be returned otherwise

here how it is..



$ cat poweroff.sh 


#!/bin/bash

##
## Program to test return value from bash script..
##

function power(){

#
# power(3,2)=9
# power(5,3)=125
#
local fv=$1
local sv=$2

local p=1


for i in ` seq 1 $sv ` ; do
p=` expr $p \* $fv `
done

echo $p
}

v1=${1:-3}
v2=${2:-2}

p1=$(power $v1 $v2)

echo "power($v1,$v2)=$p1"

# Done.




$ ./poweroff.sh 

power(3,2)=9