Linux常用指令(完善中)

  1. top 查看進程信息
    輸入top,可查看系統所有進程信息,包括CPU使用率、內存佔用率等,類似Windows系統的任務管理器。
    輸入Shift+P可按CPU使用率排序,輸入Shift+M可按內存佔用率排序,輸入q可退出該界面。
  2. df 查看磁盤空間
    輸入df,可查看文件系統的磁盤空間佔用情況,常見命令參數如下:
    -a, --all include dummy file systems
    -B, --block-size=SIZE use SIZE-byte blocks
    –direct show statistics for a file instead of mount point
    –total produce a grand total
    -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
    -H, --si likewise, but use powers of 1000 not 1024
    -i, --inodes list inode information instead of block usage
    -k like --block-size=1K
    -l, --local limit listing to local file systems
    –no-sync do not invoke sync before getting usage info (default)
    -P, --portability use the POSIX output format
    –sync invoke sync before getting usage info
    -t, --type=TYPE limit listing to file systems of type TYPE
    -T, --print-type print file system type
    -x, --exclude-type=TYPE limit listing to file systems not of type TYPE
    -v (ignored)
    常用命令如下:
    df -ha 顯示所有磁盤空間佔用情況;
    df -i 以inode模式顯示磁盤使用情況;
    df -ht ext4 顯示指定類型磁盤;
    df -h 列出文件系統的類型。
  3. du 查看文件大小
    輸入du -sh,可以查看文件及文件夾的大小, -h輸出文件系統分區使用的情況,例如10KB,10MB,10GB等,-s顯示文件或整個目錄的大小,默認單位是KB。
    du -sh /xxx/xxx 顯示文件夾大小,但不會列出路徑下每一個文件的大小;
    du -sh /xxx/* 列出xxx下每個文件夾和文件的大小;
    du -h --max-depth=1 /xxx/xxx 查找佔用空間最大的文件與目錄,-depth=1代表展示選擇路徑的目錄級別。
  4. rm 刪除文件
    輸入rm -rf /xxx/xxx,可刪除選擇目錄以及其下所有文件和文件夾。
    -r 向下遞歸,不管有多少級目錄,一併刪除;
    -f 直接強行刪除,不作任何提示;
    -i 交互模式,在刪除前詢問用戶是否操作。
    rm -rf /xxx/xxx/*,可刪除選擇目錄下的所有文件和文件夾。
  5. cp 複製文件
    輸入cp [option] source target,可進行文件複製。
    選項參數:
    -a 是指archive的意思,也說是指複製所有的目錄;
    -d 若源文件爲連接文件(link file),則複製連接文件屬性而非文件本身;
    -f 強制(force),若有重複或其它疑問時,不會詢問用戶,而強制複製;
    -i 若目標文件(destination)已存在,在覆蓋時會先詢問是否真的操作;
    -l 建立硬連接(hard link)的連接文件,而非複製文件本身;
    -p 與文件的屬性一起復制,而非使用默認屬性;
    -r 遞歸複製,用於目錄的複製操作;
    -s 複製成符號連接文件(symbolic link),即“快捷方式”文件;
    -u 若目標文件比源文件舊,更新目標文件。
    示例:
    cp -rf /home/user1/* /root/temp/ 將/home/user1目錄下的所有東西拷到/root/temp/下而不拷貝user1目錄本身。
    cp /test1/file1 /test3/file2 將/test1目錄下的file1複製到/test3目錄,並將文件名改爲file2。
  6. mv 移動文件
    輸入mv [option] source target,可進行文件移動(剪切)。
    參數說明:
    -f force,強制直接移動而不詢問;
    -i 若目標文件(destination)已經存在,就會詢問是否覆蓋;
    -u 若目標文件已經存在,且源文件比較新,纔會更新。
    mv ./WorkReport/web.xml ./WorkReport/WEB-INF/ 移動/WorkReport/web.xml文件到/WorkReport/WEB-INF/;
    mv /data/new /data/old/ 移動/data/new 到/data/old/文件夾下,源文件路徑末尾就不加 / 了;
    mv /data/new/* /data/old/ 如果是移動文件夾下的所有文件,源路徑後面跟上 /*。
  7. 開啓端口
    輸入iptables -I INPUT -p tcp --dport 8080 -j ACCEPT,開啓防火牆8080端口之後,可通過網絡遠程連接該機的8080端口。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章