Linux Utility Tips

解壓縮檔案

unzip [ZipFile/WAR] -d [DIR]

壓縮目錄

zip -rq [ZipFile] [DIR]

壓縮檔案

gzip [file]

ex. gzip *log*

顯示執行檔路徑

which [command]

顯示檔案型態

file [command]

掛載檔案系統

mount -t vboxsf software /opt/software

or

/etc/fstab

software /opt/software vboxsf defaults 0 0

mount -a

查看Disk使用量

df -kh

查看Folder使用量

du -sh *

du –maxdepth=1

尋找檔案內容, 列出檔案

find -exec grep -l [keyword] {} \;

刪除目前目錄中n天前的檔案

find . -maxdepth 1 -name ‘*.tmp’ -mtime +[n] -exec rm -f {} \;

find . -maxdepth 1 -type f -mtime +[n] -exec rm -f {} \;

將Dos檔案轉成Linux檔案格式

(將Dos文件中^M符號刪除. ^M=Carriage Return)

dos2unix -n  [target file]

doc2unix [file] (直接轉換原檔)

or

Using vi -b to open the file→esc→:set ff=unix→esc→wq

分檔 (大檔分小檔)

split -b [size (bytes)] [file name] [prefix]

 

依Size分檔
split -b 10000000 server.log server-

每10MB分一個檔, 檔名為server-a, server-b, server-c…看會分出多少檔, 依字母編號

-d : 以數字編號

去除^M (Windows換行符號CR+LF)

cat [fileName] | tr -d ‘\r’ > [New fileName]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s