Get time by increasing or decreasing an hour in Linux command

Posted on November 16, 2014, 11:09 pm


Some linux commands tips and tricks (get time by increasing/decreasing an hour in Linux command)

How to get time by -/+ an hour in Linux command ?

Bad command

echo $(date "+%Y%m%d")$(($(date "+%H")-1))

Why ? : the output format is only one digit from (0-9) for midnight (00h) you will have (00-1) -> WTF !

Good command
"OK but not the top one :/" and this one cans only decrease

echo $(date "+%Y%m%d")$(date +%H -d "1 hour ago")

Good command
"Yes, this one is perfect :)"

echo $(date "+%Y%m%d%H" -d "1 hour ago")   


Get time by increasing or decreasing an hour in Linux command
Get time by increasing or decreasing an hour in Linux command


/!\with the same command you can decrease by day or year
Ex:

echo $(date "+%Y%m%d%H" -d "1 day ago") echo $(date "+%Y%m%d%H" -d "1 year ago")
echo $(date "+%Y%m%d%H" -d "1 day ago")
echo $(date "+%Y%m%d%H" -d "1 year ago")
Read More

Read text file by condition with AWK

Posted on November 15, 2014, 8:55 pm


What is AWK ?

AWK (sometimes called nawk) is a Linux programming language designed by Alfred V. Aho, Peter J. Weinberger, and Brian W. Kernighan.
The name of the language was taken from the three letters of the designer's name (Aho, Weinberger, and W. Kernighan).

Read text file by condition with AWK
Read text file by condition with AWK


Even the original version of awk was written in 1977 and continue their innovation to this day, but this language is still new for me :p and I found that it is more powerful, more practice and largely used in shell programming.
It is easy to discover another programming language if you've already known one isn't it ?
So now let's start some tutorial with me.

Read More

Some linux commands tips and tricks

Posted on September 27, 2014, 9:19 pm


I am not new to linux but i am not friendly with linux :D, within my new mission i work every day with black and white terminal screen so command line every day.
How beautiful linux is !!
Soon i might become a shell script developer ^^ or this is another challenge !! but you know i'am already fall in love with JAVA :)
Today i share with you some useful linux command :

How to KillPorcess By PortNumber ?

netstat -ap | grep :PortNumber
kill -9 PortNumber

How much do you know about VI or VIM editor ?

By using VI/VIM i can easily read a 2GB text file :) really appreciated about that and feel sorry for notepad/notepad++ :(

+ Save : Ctrl + c then type :wq then type Enter
+ Close without save : Ctr + c then type :q!
+ Find : Ctr + c then type / and the word that you want to find 

if the word contain space then use quote between the word

+ Show line number : Ctrl + c then type :set nu
+ hide line number : Ctrl + c then type :set nu!
+ hide syntax hilighting : Ctr + c then type :syntax off
+ Show syntax hilighting : Ctr + c then type :syntax on

How to count file in a directory ?

ls | wc
Read More

3 ways to read log file on the fly in linux

Posted on September 19, 2014, 9:26 pm


Suppose that you have a log file generate each time when you launch your script.
How can you read this file on the fly (while the script is writing in to that file) ?

1-Using tee

./run-report.sh 2>&1 | tee /var/spt/log/runrepot.log

2-Using tail -f

./run-report.sh > /var/spt/log/runrepot.log 2>&1 | tail -f /var/spt/log/runrepot.log

3.Using Watch + tail

./run-report.sh > /var/spt/log/runrepot.log 2>&1 | watch tail -20 /var/spt/log/runrepot.log
Read More

Some line of shell script to convert VCD to mpg

Posted on September 7, 2014, 9:29 pm


Because of my TV does not support the .DAT, and I have hundred of VCD file so the only way to read these files on the other devices is to convert these files to a format that's supported by the target devices. Most of devices can read (.mpg, *.avi etc) so today I share with you how to convert these files on linux, by using “avconv” with some line of code to automate the converting process.

Get the below script and make some change for your own :)

#!/bin/sh
#

source="/home/psph-linux/Desktop/vcd_2_mpg"
destination="/home/psph-linux/Desktop/vcd_2_mpg"
path=$1

for i in `ls $path`
do
 `cd $source/$path`
 `avconv -i $source/$path/$i -target vcd $destination/$path/$i.mpg`
 echo $i "source = ${source}"
done

If you want to convert one by one use the command line below

`avconv -i $source -target vcd $destination`
Read More

Blog Archive

  • 2023-May (1)
  • 2023-February (1)
  • 2020-October (1)
  • 2020-May (1)
  • 2020-February (2)
  • 2019-December (5)
  • 2019-November (1)
  • 2018-July (1)
  • 2017-December (1)
  • 2017-November (1)
  • 2017-June (1)
  • 2016-September (5)
  • 2016-August (3)
  • 2016-June (1)
  • 2015-September (1)
  • 2015-May (1)
  • 2015-February (2)
  • 2014-December (1)
  • 2014-November (2)
  • 2014-September (3)
  • 2014-August (1)
  • 2014-June (1)
  • 2014-May (1)
  • 2014-March (1)
  • 2013-December (2)
  • 2013-October (2)
  • 2013-July (1)
  • 2013-June (3)
  • 2013-May (4)
  • 2013-March (1)
  • 2012-December (2)
  • 2012-November (1)
  • 2012-October (1)
  • 2012-September (2)
  • 2012-August (2)
  • 2012-July (2)
  • 2012-June (1)
  • 2012-May (2)
  • 2012-March (2)
  • 2012-February (2)
  • 2012-January (5)
  • 2011-December (2)
  • 2011-November (4)
  • 2011-October (5)
  • 2011-September (2)
  • 2011-August (1)
  • 2011-June (2)
  • 2011-May (1)
  • 2011-April (9)
  • 2011-March (3)
  • 2011-February (12)
  • 2011-January (16)
  • 2010-December (17)
  • 2010-November (6)
  • 2010-October (10)
  • 2010-September (8)