
この記事では、Linuxの基本的なコマンドを、応答例を交えながらご紹介します。
1. ls
— ディレクトリの中身を表示する
1 2 3 |
$ ls Documents Downloads Music Pictures Videos |
2. pwd
— 今いるディレクトリを表示する
1 2 3 |
$ pwd /home/username |
3. cd
— ディレクトリを移動する
1 2 3 4 |
$ cd Documents $ pwd /home/username/Documents |
4. mkdir
— 新しいディレクトリを作る
1 2 3 4 |
$ mkdir test_folder $ ls Documents Downloads Music Pictures Videos test_folder |
5. rm
— ファイルを削除する
1 2 3 4 |
$ rm example.txt $ ls file1.txt file2.txt |
※ファイルがない場合は、こうなることも:
1 2 3 |
$ rm nofile.txt rm: cannot remove 'nofile.txt': No such file or directory |
6. cat
— ファイルの中身を表示する
1 2 3 |
$ cat file.txt Hello, this is a sample file. |
7. echo
— 文字列を表示する
1 2 3 |
$ echo "Hello Linux" Hello Linux |
8. chmod
— ファイルの権限を変更する
1 2 3 4 5 6 7 8 |
$ ls -l script.sh -rw-r--r-- 1 user user 1234 Jun 15 10:00 script.sh $ chmod +x script.sh $ ls -l script.sh -rwxr-xr-x 1 user user 1234 Jun 15 10:00 script.sh |
9. grep
— ファイルの中から文字列を検索する
1 2 3 4 |
$ grep "error" log.txt 2025-06-15 12:00:01 error: something went wrong 2025-06-15 12:01:05 error: failed to connect |
10. ping
— ネットワークの疎通確認
1 2 3 4 5 6 7 8 9 10 |
$ ping -c 3 google.com PING google.com (142.250.72.46) 56(84) bytes of data. 64 bytes from iad30s25-in-f14.1e100.net (142.250.72.46): icmp_seq=1 ttl=117 time=14.5 ms 64 bytes from iad30s25-in-f14.1e100.net (142.250.72.46): icmp_seq=2 ttl=117 time=14.3 ms 64 bytes from iad30s25-in-f14.1e100.net (142.250.72.46): icmp_seq=3 ttl=117 time=14.6 ms --- google.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 14.300/14.466/14.644/0.143 ms |