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")

How to list all file recursively?

find . -exec ls -dl \{\} \; | awk '{print $3, $4, $9}'

How to show the process by name ?

ps aux | grep non_du_processus_ou_non_du_script

How to show the directory with size ?

du -h /dir/size   
du -ch | grep total

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)