python_note
  • Introduction
  • My Python
    • Anaconda
    • argparse
    • datetime
    • json
    • logging
    • numpy
    • open
    • openCC
    • pandas & csv
    • Socket & SocketServer
    • re
    • yaml
    • smtp
    • 物件操作
    • unittest
    • 線程
    • prettytable
    • IO
    • pycurl
    • sys
    • pickle
    • auto-python-to-exe
    • cython
    • nuitka
  • Crawler
    • Urllib & Requests
      • User-agent
      • Percent-Encoding
      • mail code
    • Selenium
    • TCP & UDP
    • 控制字符(control character)
  • Web Development
    • Flask
      • RESTful api
      • Template
      • blueprint
    • Django
      • 環境佈署(windows)
    • 檢查Port
    • Apache
    • 使用者行為
    • jQuery
    • 壓力測試
    • DataTable
    • Bootstrap
    • CSS
    • JavaScript
    • Chart.js
  • Deep Learning
    • Keras 設定
    • RNN
    • LSTM
  • Test
    • T-Test
  • 資料結構
    • Hash
    • 時間複雜度
  • NLP
    • N-gram
    • CKIP
    • 中文轉數字
    • CRF
    • Mutual Information
    • 模糊比對
  • Linebot
    • Heroku
    • 圖文選單
    • channel
  • Linux
    • 常用指令
    • shell script
    • sshfs
    • ssh
    • nodejs & npm
    • debug
  • GCP
    • app engine
    • ssh(gcp)
    • gsutil
    • brabrabra
    • Load Balancer
    • k8s
  • Database
    • mysql
    • elasticsearch
      • Query
      • Backup and Restore
      • elasticdump
      • es2csv
      • ELK
    • mongodb
      • install
      • authentication
      • pymongo
    • sql server
  • go
    • Swarm
  • Docker
    • Kitematic
    • Dockerfile
    • Swarm
  • Git
  • 其他
    • USB軟體保護
    • Windows效能監視器
  • Blockchain
Powered by GitBook
On this page
  • vim
  • 複製貼上
  • 暫存檔問題
  • 檔案與資料夾操作
  • 查看使用記憶體
  • 壓縮檔操作
  • 使用金鑰進行ssh連線與傳輸檔案
  • 中止程式
  • 查看使用中的port
  • 查看log
  • 測試連線
  • 開關機紀錄
  • 設定使用者密碼
  • 權限設定
  • Failed to lock the file
  • share folder
  • 執行程式被kill
  • 關閉ssh連線時,保留欲執行的程式
  • ctrl+c vs ctrl+z
  • 排程設定
  • MTA錯誤

Was this helpful?

  1. Linux

常用指令

PreviousLinuxNextshell script

Last updated 5 years ago

Was this helpful?

vim

複製貼上

參考連結:

暫存檔問題

#查看所有檔案,包含隱藏檔案
ls -al

#手動刪除
rm -r [filename]

參考連結:

檔案與資料夾操作

刪除

#砍掉整個資料夾問都不問
rm -rf [dirname or file name]

#會問
rm -i [dirname or file name]

複製

#-f=覆蓋
cp -r -f [input] [output]

狀態查詢

# 查看建立時間、大小等
stat [filename or dirname]

# 查看容量大小
du -sh [filename or dirname]

查詢檔案或資料夾

# 尋找家目錄底下名稱包含 test(不分大小寫) 的資料夾
find ~ -iname "*test*" -type d

# 尋找家目錄底下名稱包含 test(不分大小寫) 的資料夾或檔案
find ~ -iname "*test*"

# 尋找家目錄底下的 test 資料夾或檔案
find ~ -name "test"

# 列出所有檔案與資料夾(包含隱藏)
ls -a

# 找出隱藏檔案與資料夾
find /path/to/ -name ".*" -print

查看使用記憶體

cat /proc/meminfo
top

壓縮檔操作

#製作壓縮檔
tar -zcvC [output dir] -f [output tar file name] [input dirname]

#製作壓縮檔2
tar -zcf [output_file_name] [input dirname] [input dirname2]

#解壓縮
tar -zxvf [file_name] -C [output_path]

#解壓縮 (gz)
gunzip FileName.gz
gzip -d FileName.gz

.zip
壓縮:zip FileName.zip DirName
解壓:unzip FileName.zip

使用金鑰進行ssh連線與傳輸檔案

cp [key file] ~
chmod 400 [key file]

#傳輸
scp -i [key file] [input file] ubuntu@[ip]:[output dir]

#連線
ssh -i [key file] ubuntu@[ip]

scp –r [file or dir] [name of ubuntu]:[dirname]

中止程式

# 關閉執行中的process
kill –TERM [process_id]
或
kill -9 [process_id]

查看使用中的port

netstat –ntlp |grep LISTEN
或
sudo netstat -tuap

查詢功能

#查詢包含sh名稱的pid
ps aux|grep sh

查看log

# 查看系統的log
sudo cat /var/log/syslog


# 動態監聽某個程式所產生的log檔

測試連線

#時間間隔和次數限制的ping

ping -c 10 -i 0.5 192.168.120.206

開關機紀錄

# 關機記錄
last -x shutdown

# 重新開機記錄
last -x reboot

設定使用者密碼

sudo passwd [使用者名稱]

權限設定

三種身份:

  • u: 自己(user)

  • g: 和自己同一組的人(group)

  • o: 其它人 (other)

每種身份皆有四種可能的權限:

  • r : 讀取權 (read)

  • w : 寫入權 (write)

  • x : 執行權 (execute)

# 如果要一次設定資料夾下所有子檔案和子資料夾加上 -R
sudo chown [擁有者]:[群組] [檔案或資料夾]

# 開啟所有權限
sudo chmod -R 777 [檔案或料夾]

# 啟用sh
sudo chmod +x [sh檔案名稱]

# 啟用所有sh檔案
sudo chmod +x *.sh

Failed to lock the file

當vm當機或被強迫關機,再度開啟時會出現的錯誤

解決方法1:
進到 VMware 的 Guest OS 資料夾,將所有的 *.lck 資料夾或檔案刪除

share folder

無法正常顯示資料夾時可重新安裝vmware tools

執行程式被kill

關閉ssh連線時,保留欲執行的程式

sudo nohup [command] & >/dev/null 2>&1

test:

ctrl+c vs ctrl+z

c是kill,z是掛起

z掛起後可以先做其他事,可用bg查看被掛起來的程式,再用fg把掛起的程式叫回來

排程設定

分鐘, 小時, 日期, 月份, 星期

# vm 排程每五分鐘執行一次start.sh,*/5要連在一起,總共5個時間點

*/5 * * * * /home/start.sh

0 10 * * * ~/test/test.sh >/dev/null 2>&1

MTA錯誤

# 查看crontab log
sudo cat /var/sys/syslog

# 加上>/dev/null 2>&1
* * * * * ./temp.sh >/dev/null 2>&1

參考連結:

參考連結:

參考連結:

參考連結:

參考連結:

參考資料:

參考連結:

參考連結:

參考連結:

參考資料:

參考資料:

參考連結:

參考資料:

http://unclecode.blogspot.tw/2012/05/vim.html
http://linux.vbird.org/linux_basic/0310vi.php
https://ithelp.ithome.com.tw/articles/10159398
https://blog.longwin.com.tw/2017/01/linux-cli-stat-find-file-time-2017/
https://blog.camel2243.com/2016/09/21/linux-find-指令,搜尋檔案資料夾名稱與全文搜尋/
https://www.ubuntudoc.com/show-hidden-files-folders-ubuntu/?lang=zh-tw
https://dotblogs.com.tw/may05005/2015/12/24/160605
http://idobest.pixnet.net/blog/post/22040782-[轉貼]-linux解壓-tar-命令
http://note.drx.tw/2008/04/command.html
https://blog.gtwang.org/linux/linux-kill-killall-xkill/
https://blog.csdn.net/LY_Dengle/article/details/53997450
http://jashliao.pixnet.net/blog/post/163943597-每天一個linux指令--ping指令(用來測試與目標主
https://stackoverflow.com/questions/35016795/get-root-password-for-google-cloud-engine-vm
https://blog.gtwang.org/linux/linux-chown-command-tutorial/
http://s2.naes.tn.edu.tw/~kv/file.htm
http://www.vixual.net/blog/archives/842
https://snippetinfo.net/mobile/media/2004
http://jimmu-jimmu.blogspot.com/2012/12/vmwareguesthost.html
https://blog.csdn.net/ktigerhero3/article/details/80004315
https://blog.csdn.net/stonesharp/article/details/28904529
https://dotblogs.com.tw/newmonkey48/2012/06/28/73115
http://linuxdiary.blogspot.com/2007/10/blog-post_30.html
https://blog.csdn.net/mylizh/article/details/38385739
https://code.kpman.cc/2015/02/11/利用-crontab-來做-Linux-固定排程/
https://blog.csdn.net/win_turn/article/details/53000899
https://blog.csdn.net/disappearedgod/article/details/43191693