สร้างถังขยะสำหรับ Linux Command
เมื่อวานนี้รุ่นน้องผมโทรศัพท์มาหาผมด้วยเสียงประหม่าเล็กน้อย พูดกับผมว่า พี่ครับ ผมเผลอลบไฟล์ใน Linux ผมจะ restore กลับมาได้ยังไงครับ ผมก็เลยสอบถามข้อมูลเบื้องต้น ก็ได้ใจความว่า เครื่องเซิร์ฟเวอร์ เป็น SCSI ต่อ RAID กันอีก คงถอด HD ออกมาไม่ได้แน่ แถมยังเป็น Text mode อีก คงเอากลับมาได้ลำบากแน่ ๆ (ใครมีวิธีที่ดีกว่า บอกผมด้วยนะครับ อยากรู้เหมือนกัน)
ผมก็แนะนำให้ใช้ซอฟต์แวร์อื่นในการจัดการแล้ว ไม่รู้ว่าจะได้ผลยังไงเหมือนกันนะครับ
ในเมื่อเรารู้ว่าปัญหามันอาจจะต้องเกิดแบบนี้แล้ว เราหาวิธีป้องกันดีกว่า โดยการสร้างถังขยะสำหรับ Linux Command ไว้ เผื่อว่าเผลอลบมันอีกจะได้เอาคืนกลับมาได้ง่าย ๆ หน่อย ถังขยะ ที่ว่าคือ Trash-Cli ครับ
root@Linux:~# apt-cache search trash-cli
trash-cli – command line trashcan utility
root@Linux:~# apt-get install trash-cli
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages were automatically installed and are no longer required:
binutils-static
Use ‘apt-get autoremove’ to remove them.
The following NEW packages will be installed:
trash-cli
0 upgraded, 1 newly installed, 0 to remove and 23 not upgraded.
Need to get 0B/14.5kB of archives.
After this operation, 143kB of additional disk space will be used.
Selecting previously deselected package trash-cli.
(Reading database … 81890 files and directories currently installed.)
Unpacking trash-cli (from …/trash-cli_0.10.r55-0ubuntu1_all.deb) …
Processing triggers for man-db …
Setting up trash-cli (0.10.r55-0ubuntu1) …Processing triggers for python-support …
root@Linux:~#
จากนั้นก็สร้าง Alias สำหรับถังขยะดังนี้
root@Linux:~#alias rm=trash
เรียบร้อยแล้วครับทดสอบการทำงานดังนี้ครับ ผมสร้างไฟล์ 12345.txt ไว้ที่ /root/12345.txt
จากนั้นก็ใช้คอมมานด์ rm ในการลบครับ rm /root/12345.txt
root@Linux:~# touch 12345.txt
root@Linux:~# ls
12345.txt
root@Linux:~# rm 12345.txt
root@Linux:~# ls
root@Linux:~#
สังเกตุได้ว่าไฟล์ถูกลบไปเรียบร้อยแล้วนะครับ
ถ้าเราจะเอาคืนกลับมาก็ใช้คำสั่ง restore-trash ดังนี้
root@Linux:~# restore-trash
0 2011-02-07 08:46:23 /root/12345.txt
What file to restore [0..0]: 0 <– เลขศูนย์ คือ ลำดับของไฟล์ที่ต้องการ restore
root@Linux:~# ls
12345.txt
root@Linux:~#
เพียงเท่านี้ ก็จะได้ไฟล์กลับมาแล้วครับ