Linux 常用命令-touch, cp, mv, rm

  • touch:
    • 創建空文件: touch filename
      • 示例: touch test.txt
    • 改變文件的修改時間: touch existedFileName
      • 示例: touch test.txt
    • 改變文件的訪問時間: touch -a existedFileName
      • 示例: touch -a test.txt
      • 訪問時間查看: li -l --time=atime test.txt
  • cp:
    • 複製文件: cp sourceFileName targetFileName
      • 示例: cp test.txt test.txt.copy
    • 複製文件提示是否覆蓋已存在目標文件: cp -i sourceFileName targetFileName
      • 示例: cp -i test.txt test.txt.copy
        若目標文件已存在則會提示是否覆蓋已有文件, 若是才繼續.
    • 遞歸複製: cp -r sourceFileName targetFileName
      • cp -r src/* destination/
  • mv:
    • 重命名文件: mv oldFileName newFileName
      • 示例: mv test.txt test1.txt
    • 移動文件: mv sourceFile targetFolder
      • 示例: mv test.txt ./study/
        和 cp 命令一樣可以使用 -i 來提示是否覆蓋已有文件
  • rm:
    • 刪除文件: rm -i fileName
      • 示例: rm -i test.txt
    • 遞歸刪除: rm -rf folder
      • 示例: rm -rf ./study
        遞歸刪除時爲了避免提示符, 可以使用 -f 參數強制刪除.
  • 參考:
    [1] : linux命令行與shell腳本編程大全
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章