Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Friday, July 18, 2014

check or remove multiple backup files filter by number

Assume on the backup directory has files like this
backup-2011-01-01-data.tar.gz
backup-2011-02-01-data.tar.gz
backup-2011-03-01-data.tar.gz
. . .
backup-2012-01-01-data.tar.gz
backup-2012-02-01-data.tar.gz
backup-2012-03-01-data.tar.gz
. . .
backup-2013-01-01-data.tar.gz
backup-2013-02-01-data.tar.gz
backup-2013-03-01-data.tar.gz
. . .

If I want to check or remove all files from year 2011 to 2012 by command line, how to do that. Do one by one? just 24 times. but if more?

You can check on file by command line by :

$du -ch backup-2012-01-01-data.tar.gz
3.4M backup-2012-01-01-data.tar.gz
3.4M total

For more files and filter by number can use this command

$du -ch backup-{2011,2012}*
3.4M backup-2011-01-01-data.tar.gz
3.4M backup-2011-02-01-data.tar.gz
3.4M backup-2011-03-01-data.tar.gz
. . .
3.4M backup-2012-12-01-data.tar.gz
81.6M total

And you can remove files

rm backup-{2011,2012}*

Read More

Bookmark and Share

Monday, October 17, 2011

How to find current runlevel on unix with who

คำสั่ง who เป็นคำสั่งเอาไว้แสดงว่าตอนนี้มีใคร log in อยู่ในระบบบ้าง โดยเมื่อใช้คำสั่ง
who
จะแสดงผลประมาณนี้
yut  tty7         2011-10-17 08:55 (:0)
yut  pts/1        2011-10-17 08:55 (:0)
ในขณะที่คำสั่งสำหรับดู previous and current runlevel ก็คือคำสั่ง runlevel
runlevel
N 2
แต่สำหรับคำสั่ง who นั้นสามารถดู current runlevel ได้ด้วยคำสั่ง
who -r
         run-level 2  2011-10-17 08:54
โดยถ้าหากต้องการดูทั้ง current runlevel และ ดูว่ามีใคร log in ในระบบด้วย จะใช้คำสั่ง
who -a
           system boot  2011-10-17 08:54
           run-level 2  2011-10-17 08:54
LOGIN      tty4         2011-10-17 08:54              1008 id=4
LOGIN      tty5         2011-10-17 08:54              1014 id=5
LOGIN      tty2         2011-10-17 08:54              1034 id=2
LOGIN      tty3         2011-10-17 08:54              1036 id=3
LOGIN      tty6         2011-10-17 08:54              1042 id=6
LOGIN      tty1         2011-10-17 08:54              1637 id=1
yut        + tty7         2011-10-17 08:55  old         2043 (:0)
yut       + pts/1        2011-10-17 08:55 01:03        2133 (:0)

ที่มา www.theunixtips.com

Read More

Bookmark and Share