
目次
- 1. ls — ディレクトリの中身を表示する
- 2. pwd — 今いるディレクトリを表示する
- 3. cd — ディレクトリを移動する
- 4. mkdir — 新しいディレクトリを作る
- 5. rm — ファイルを削除する
- 6. cat — ファイルの中身を表示する
- 7. echo — 文字列を表示する
- 8. chmod — ファイルの権限を変更する
- 9. grep — ファイルの中から文字列を検索する
- 10. ping — ネットワークの疎通確認
この記事では、Linuxの基本的なコマンドを、応答例を交えながらご紹介します。
1. ls
— ディレクトリの中身を表示する
$ ls
Documents Downloads Music Pictures Videos
2. pwd
— 今いるディレクトリを表示する
$ pwd
/home/username
3. cd
— ディレクトリを移動する
$ cd Documents
$ pwd
/home/username/Documents
4. mkdir
— 新しいディレクトリを作る
$ mkdir test_folder
$ ls
Documents Downloads Music Pictures Videos test_folder
5. rm
— ファイルを削除する
$ rm example.txt
$ ls
file1.txt file2.txt
※ファイルがない場合は、こうなることも:
$ rm nofile.txt
rm: cannot remove 'nofile.txt': No such file or directory
6. cat
— ファイルの中身を表示する
$ cat file.txt
Hello, this is a sample file.
7. echo
— 文字列を表示する
$ echo "Hello Linux"
Hello Linux
8. chmod
— ファイルの権限を変更する
$ 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
— ファイルの中から文字列を検索する
$ 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
— ネットワークの疎通確認
$ 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