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?

Linux基本コマンド解説:初心者向けまとめ

Posted at

1. cd(Change Directory)

用途:ディレクトリを移動するコマンドです。
例:
cd .. 1つ上のディレクトリへ
cd ~ ホームディレクトリへ

2. pwd(Print Working Directory)

用途:現在のディレクトリのフルパスを表示します。

例:
pwd
出力例: /home/user/Documents

3. ls(List)

用途:ディレクトリの内容を一覧表示します。

よく使うオプション:

-l:詳細情報がついて表示

-a:隠しファイルも表示

4. mkdir(Make Directory)

用途:新しいディレクトリを作成します。

例:
mkdir new_folder
mkdir -p parent/child
※-pオプションで親ディレクトリも同時に作れる

5. rmdir(Remove Directory)

用途:空のディレクトリを削除します。

例:

rmdir old_folder
※ 中身があるディレクトリは削除できません(その場合は rm -r を使用)。

6. cat(Concatenate)

用途:ファイルの中身を表示します。
例:cat file.txt

7. less

用途:長いテキストファイルを1ページずつスクロール表示できます。

例:

less large_file.txt
q で終了、/keyword で検索も可能。

8. tail

用途:ファイルの末尾(最終行)を表示します。

よく使うオプション:

-n:表示する行数(20なら最終行から20行)

-f:リアルタイム監視(ログなどに便利)

例:

tail -n 20 log.txt
tail -f /var/log/syslog

9. touch

用途:空のファイルを作成します。
例:

touch newfile.txt

10. rm(Remove)

用途:ファイルやディレクトリを削除します。

よく使うオプション:

-r:ディレクトリを再帰的に削除

-f:確認なしで強制削除

例:

rm file.txt
rm -rf old_folder

11. mv(Move)

用途:ファイルやディレクトリを移動または名前変更します。

例:

mv oldname.txt newname.txt # 名前変更
mv file.txt /tmp/ # 移動

パターン
mv A B(Bがファイル名)   A → B(名前変更)
mv A /path/(Bがディレクトリ) A をそのディレクトリに移動
mv A /path/B(Bがファイル名付きのパス)A を移動して名前も変更

12. cp(Copy)

用途:ファイルやディレクトリをコピーします。

よく使うオプション:

-r:ディレクトリを再帰的にコピー

例:

cp file.txt backup.txt(backup.txtが存在しない場合、自動で作られます)
cp -r dir1/ dir2/

13. ln(Link)

用途:ファイルのリンクを作成します(ハードリンクまたはシンボリックリンク)。

ln original.txt link.txt # ハードリンク

イメージ
[original.txt] ─┬─> 実体
[link.txt] ─────┘

ln -s original.txt symlink.txt # シンボリックリンク

イメージ
[symlink.txt] ──> [original.txt] ──> 実体

14. find

用途:指定条件でファイルやディレクトリを検索します。

例:

find . -name "*.txt"

意味
今いるディレクトリ(.)以下から
「.txt で終わるファイル名」のファイルを探す

find /home/user -type f -size +10M

意味
/home/user 以下にある
「サイズが10MBより大きい」
「通常ファイル(ディレクトリじゃない)」を探す

-type f 通常のファイルだけ対象(ディレクトリ除外)
-size +10M 10MBより大きい(+は「より大きい」)

15. chmod(Change Mode)

用途:ファイルやディレクトリのパーミッションを変更します。

例:

chmod 755 script.sh
chmod u+x script.sh

16. chown(Change Owner)

用途:ファイルやディレクトリの所有者を変更します。

例:

chown user:group file.txt
※ sudo 権限が必要なことが多いです。

17. ps(Process Status)

用途:現在実行中のプロセスを表示します。

例:

ps aux  BSD系の書き方(MacやUbuntuでよく使う)
ps -ef  UNIX System V系の書き方

18. kill

用途:プロセスにシグナルを送って終了させます。

例:

kill 1234 # プロセスIDで終了
kill -9 1234 # 強制終了(SIGKILL)
※1234はプロセスID
psと組み合わせて使うことが多いです。

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?