0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ターミナル上のファイル操作コマンドまとめ

Posted at

1. 表示・移動

コマンド 説明
ls カレントディレクトリの一覧表示 ls -l(詳細表示)
cd ディレクトリ名 ディレクトリ移動 cd Documents
pwd 現在のディレクトリのパス表示 pwd

2. 作成・削除

コマンド 説明
mkdir ディレクトリ名 新しいディレクトリ作成 mkdir myfolder
touch ファイル名 空ファイルの作成 touch file.txt
rm ファイル名 ファイル削除 rm file.txt
rm -r ディレクトリ名 ディレクトリごと削除(再帰削除) rm -r myfolder

3. コピー・移動・名前変更

コマンド 説明
cp コピー元 コピー先 ファイルやディレクトリをコピー cp file.txt backup.txt
mv 移動元 移動先 ファイルやディレクトリの移動・名前変更 mv oldname.txt newname.txt

4. 中身確認

コマンド 説明
cat ファイル名 ファイルの内容を一気に表示 cat file.txt
head ファイル名 ファイルの最初の10行を表示 head file.txt
tail ファイル名 ファイルの最後の10行を表示 tail file.txt
less ファイル名 ページ単位でファイル閲覧 less file.txt

5. 検索・情報確認

コマンド 説明
find パス -name "ファイル名" ファイルを検索 find . -name "*.txt"
grep "文字列" ファイル名 ファイル内で文字列検索 grep "hello" file.txt
stat ファイル名 ファイルの詳細情報を表示 stat file.txt
file ファイル名 ファイルの種類を調べる file image.png

6. パーミッション操作

コマンド 説明
chmod モード ファイル名 ファイルの権限を変更 chmod 755 script.sh
chown ユーザー ファイル名 ファイルの所有者を変更 chown user1 file.txt

7. その他便利コマンド

コマンド 説明
basename パス パスからファイル名だけ抽出 basename /home/user/file.txt
dirname パス パスからディレクトリ名だけ抽出 dirname /home/user/file.txt

シェルでよく使うショートカット

ショートカット 説明
Ctrl + C 現在のコマンドを強制停止
Ctrl + L 画面クリア
Tab コマンドやファイル名の自動補完
!! 直前のコマンドを再実行

もし使い方や応用例が知りたい方はコメントください。
ご参考になれば幸いです!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?