Tag: chmod

  • date นั้นสำคัญไฉน

    ที่ Shell prompt พิมพ์คำสั่ง man date

    ได้อะไรมาไม่รู้เยอะแยะ…

    man date
    man date

    จากคู่มือจะเอารูปแบบวันที่ 12-09-2017 ตัวเลือกที่เกี่ยวข้องได้แก่ %d %D %e %F %g %G %m %y %Y เป็นต้น ลองส่งคำสั่ง

    date +"%d-%m-%Y"

    ได้ผลลัพธ์

    12-09-2017

    ตรงตามที่ต้องการ มาเขียนสคริปต์กันหน่อย อยากได้เมื่อวานทำไง วันนี้เล่น tcsh shell สร้างแฟ้ม date.tcsh ด้วย editor ที่ชื่นชอบมีข้อความว่า

    #!/bin/tcsh -f
    set tday=`date +"%d"`
    set tmonth=`date +"%m"`
    set tyear=`date +"%Y"`
    echo "Today is ${tday}-${tmonth}-${tyear}."
    set yday=`expr ${tday} - 1`
    echo "Yesterday was ${yday}-${tmonth}-${tyear}."

    ทดสอบสคริปต์ด้วยคำสั่ง

    tcsh date.tcsh

    ไม่อยากพิมพ์ tcsh ทุกครั้งเพิ่ม execution bit ด้วยคำสั่ง

    chmod +x date.tcsh

    เรียกใช้ได้โดยพิมพ์

    ./date.tcsh (อ่านว่า จุด-ทับ-เดต-จุด-ที-ซี-เอส-เอช)

    ผลลัพธ์ที่ได้

    Today is 12-09-2017.
    Yesterday was 11-09-2017.

    อยากได้เมื่อวานทำไมมันยากอย่างนี้ ฮา… ซึ่งเมื่อกลับไปอ่านคู่มือ (man date) ให้ดี..อีกครั้งจะพบว่ามีตัวเลือก

    -d, –date=STRING
    display time described by STRING, not ‘now’

    และเมื่่อเลื่อนลงมาล่างสุดจะพบว่า

    DATE STRING
    The –date=STRING is a mostly free format human readable date string such as “Sun, 29 Feb 2004 16:21:42 -0800” or
    “2004-02-29 16:21:42” or even “next Thursday”. A date string may contain items indicating calendar date, time of day,
    time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day.
    The date string format is more complex than is easily documented here but is fully described in the info documentation.

    โอ้ววว มันเขียนไว้หมดแล้ว…

    เขียนใหม่ได้ว่า
    date -d yesterday

    ได้ผลลัพธ์

    Mon Sep 11 21:43:51 +07 2017

    เปลี่ยนให้ผลลัพธ์ออกมาในรูปแบบที่ต้องการได้ด้วยคำสั่ง

    date -d yesterday +"%d-%m-%Y"

    ก็จะได้ผลลัพธ์ว่า

    11-09-2017

    แก้สคริปต์ date.tcsh

    #!/bin/tcsh -f
    set tday=`date -d today +"%d-%m-%Y"`
    set yday=`date -d yesterday +"%d-%m-%Y"`
    echo "Today is ${tday}."
    echo "Yesterday was ${yday}."

    เจ็บมาเท่าไหร่แล้วกับคำว่าไม่อ่านเอกสาร….

    ยังใส่ข้อความอื่นๆ แทน string ได้เช่น
    date -d 'tomorrow'
    date -d '-1 days ago'
    date -d '200 days'
    date -d '1000 weeks'
    date -d '30 months'
    date -d '300 years'

    เรื่องนี้สอนให้รู้ว่า บางทีเอกสารก็มีให้หมดแล้ว ไม่ต้องทำเองก็ด้ายยยยย….

    จบขอให้สนุก

    man date
    ค้นเพิ่มเติม https://www.cyberciti.biz/tips/linux-unix-get-yesterdays-tomorrows-date.html

  • Joomla Folder 777

    • ก่อน เปลี่ยนต้องเปลี่ยน Site Offline เป็น yes ก่อนทุกครั้ง โดยการแก้ configuration.php แก้ไขบรรทัดที่เขียนว่า public $offline = ‘0’; เปลี่ยนเป็น public $offline = ‘1’;
    • โฟลเดอร์ที่ต้องเปลี่ยน permission เป็น 777 หรือเปลี่ยนให้ apache (www-data สำหรับ ubuntu) เป็นเจ้าของในระหว่างติดตั้ง component, module, language ได้แก่ (more…)