網路上有一些方便的指令,會在這邊持續的更新做為筆記
設定 history 顯示時間
| |
| |
| $ HISTTIMEFORMAT="%Y-%m-%d %T " |
| $ HISTTIMEFORMAT="%F %T: " |
| |
| |
| |
| export HISTTIMEFORMAT="%Y-%m-%d %T " |
檢查 port 是否存在
| |
| $ telnet cha15.info 21 |
| |
| |
| $ nc -zv chan15.info 80 |
| $ Connection to chan15.info 80 port [tcp/http] succeeded! |
| |
| |
| $ nc -zv chan15.info 80 21 33 |
| $ Connection to chan15.info 80 port [tcp/http] succeeded! |
| $ Connection to chan15.info 21 port [tcp/ftp] succeeded! |
| $ nc: connect to chan15.info port 33 (tcp) failed: Connection refused |
一次寫入多行資料
| $ cat <<eot > test.txt |
| > 1 |
| > 2 |
| > 3 |
| > eot |
搜尋語取代檔案文字
grep -rl 'windows' | xargs sed -i 's/windows/linux/g'
刪除超過三十天的檔案
find PATH -ctime +30 | xargs -f
nmap
之前會用 nc
檢查 service,用 nmap
來做更方便
| $ nmap localhost |
| |
| Starting Nmap 7.01 ( https://nmap.org ) at 2019-05-03 15:05 CST |
| Nmap scan report for localhost (127.0.0.1) |
| Host is up (0.0000080s latency). |
| Not shown: 995 closed ports |
| PORT STATE SERVICE |
| 21/tcp open ftp |
| 22/tcp open ssh |
| 25/tcp open smtp |
| 80/tcp open http |
| 443/tcp open https |
du 特殊用法
一般使用 du 的話他會列出你當前目錄每一個層級的所有的檔案內容跟大小,不過其實這樣不太實用,我們通常只要在第一層知道檔案大小即可
| $ du -h -d 1 |
| 12K ./apm |
| 24K ./wireshark |
| 16K ./cron.d |
| 20K ./apport |
| 8.0K ./cron.hourly |
| 40K ./sysctl.d |
如果希望可以照檔案大小排序的話
| $ du -h -d 1 | sort -h |
| 4.0K ./binfmt.d |
| 4.0K ./landscape |
| 4.0K ./libpaper.d |
| 4.0K ./modules-load.d |
| 4.0K ./opt |
| 4.0K ./pki |
| |
| $ du -h -d 1 | sort -h -r |
| 8.7M . |
| 880K ./apache2 |
| 756K ./ssl |
| 668K ./apparmor.d |
| 440K ./php |
| 400K ./init |
| 368K ./init.d |