いまさらディレクトリ削除とか

  • ファイル処理 コマンド
    * コピー
      cp コピー前のファイル名 コピー後のファイル名
      cp コピー前のパス コピー後のパス
      例:cp sample.html /home/test/test.html
    * 移動
      mv 移動前のファイル名 移動後のファイル名
      mv 移動前のパス 移動後のパス
      例:mv ./abc/sample.html /home/test/ (sample.htmlがtestディレクトリに移動)
      例:mv ../sample.html /home/test/test.html (sample.htmlをtest.htmlというファイル名でtestディレクトリに移動)
    * 削除
      rm 削除するファイル名
      rm -r 削除するディレクトリ名 (ディレクトリ以下全て消す場合)
      rm -rf 削除するディレクトリ名 (-fで、消すかどうかの確認メッセージを出さない)
      例:rm ./test/sample.html
      例:rm -rf /home/test/
    * ディレクトリ作成
      mkdir ディレクトリ名
      例:mkdir ./sample
    * ディレクトリ削除
      rmdir ディレクトリ名
      例:rmdir ./sample
      ディレクトリにファイルがない場合のみ削除可能。
      通常はrm -rコマンドを利用。
    * ディレクトリにあるファイル名やディレクトリ名を表示
      ls
      や
      ls -la
      など。
      -l:縦にリストを表示。
      -a:ピリオドで始まるファイルやディレクトリも表示。
  • 検索
    * ファイルの検索
      find パス名 -name ファイル名
      例:find . -name sample.php (カレントディレクトリ以下からsample.phpを検索)
      例:find /test/ -name sample.php (/testディレクトリ以下からsample.phpを検索)
    * コマンド用のファイルを検索
      whereis コマンド名
      例:whereis php
    * コマンドのパスを検索
      which コマンド名
      例:which perl
    * インストール済みのrpmを検索
      rpm -qa | grep ソフト名
    * ファイルやディレクトリの属性を変更します。
      確認メッセージなして、強制的に実行する場合、-fオプションを指定。
    * グループ
      chgrp グループ名 パス名
      例:chgrp tanaka ./sample.txt
    * パーミッション
      chmod モード パス名
      例:chmod 755 ./sample.txt
      例:chmod o+w ./sample.txt

      絶対モード(オーナー、グループ、その他の順に数字を並べます)
          4    読み取り許可
          2    書き込み許可
          1    実行許可

      シンボリックモード
          u    オーナー
          g    グループ
          o    その他
          a    すべて
          +    アクセス権追加
          -    アクセス権削除
          =    指定したアクセス権に変更
          r    読み取り許可
          w    書き込み許可
          x    実行許可

    * 所有者(オーナー)
      chown オーナー名 パス名
      例:chown suzuki ./sample.txt
  • その他
    * タイムスタンプ変更、空ファイル作成
      ファイルのタイムスタンプを更新。
      ファイルが存在しない場合は、新しくファイルを作成します。
      touch ファイル名
      例:touch ./sample.txt (sample.txtの更新日時を現在の時刻にします)
      例:touch ./data/* (/dataディレクトリ以下の全てのファイルのタイムスタンプ更新)
      例:touch -t 0601151010 sample.txt (タイムスタンプを2006年1月15日10時10分にします)

        -a                     アクセス日時を更新
        -c, --no-create        ファイルが存在しない場合、ファイルを作成しない
        -m                     更新日時を更新
        -r, --reference=FILE   現在時刻の代りにこのファイルの時刻を使う
        -t STAMP               現在時刻の代りに [[CC]YY]MMDDhhmm[.ss] を使う

    * カレントディレクトリのパスを表示
      pwd
    * ワイルドカード
      *で、ファイル名の省略が可能。
      例:cp ./*.html ./sample/
      で、拡張子が.htmlのファイルをすべてsampleディレクトリに移動。
  • SCP
    * コピー
      別のサーバにSCPでファイルをコピーする場合など。
      scp -r /htdocs/sample/index.jsp ユーザ名@サーバ名:/htdocs/sample/
      scp -r /htdocs/sample/* ユーザ名@サーバ名:/htdocs/sample/
      scp -r ./* ユーザ名@サーバ名:/htdocs/sample/

http://memorva.jp/memo/linux/file.php