目次
1. はじめに
こんにちは、初心者エンジニアです。
働く中でLinuxのコマンドがわからなくなり、調べてしまうことが多々あるため、メモとしてまとめることにしました。
テスト環境ということで、基本rootで行ってます。
オプション等はまた別の機会に...
2. 基本系
2.1. pwd
カレントディレクトリを表示
# pwd
/root
2.2. cd
ディレクトリの変更
# cd /tmp
# pwd
/tmp
2.3. ls
ディレクトリにあるファイル等を表示
# ls /
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
2.4. mkdir
ディレクトリの作成
# mkdir test
# ls -F
test/
2.5. cat
ファイルの表示&連結
# cat test1
This is a pen.
2.6. find
ファイル等の検索
# find ./test1
./test1
2.7. cp
ファイル等のコピー
# mkdir /tmp/testdir
# cp test1 /tmp/testdir
# ls /tmp/testdir
test1
2.8. mv
ファイル等の移動&名前変更
# mv /tmp/testdir/test1 /tmp/testdir/test2
# ls /tmp/testdir
test2
# mv /tmp/testdir/test2 /root
# ls /root
test1 test2
2.9. rm
ファイル等の消去
# rm test2
rm: remove rehular file 'test2'? y
# ls
test1
2.10. ln
ファイル等のリンクを作成
# pwd
/tmp/testdir
# ln -s /root/test1 testfile
# ls -l
lrwxrwxrwx 1 root root 11 xxxxxxxxx testfile -> /root/test1
2.11. more
ファイルを画面ごとに表示
# more test1
2.12. touch
ファイルのタイムスタンプを更新&無のファイル作成
# touch test2
# ls
test1 test2
3. 管理系
3.1. who
ログインしているユーザーを表示
# who
root tty1 xxxxxxxxx
3.2. chmod
ファイル等の権限変更
# ls -l
-rw-r--r-- 1 root root 15 xxxxxxxxx test1
# chmod 755 test1
# ls -l
-rwxr-xr-x 1 root root 15 xxxxxxxxx test1
3.3. chown
ファイル等の所有者&グループ変更
# ls -l
-rwxr-xr-x 1 root root 15 xxxxxxxxx test1
# chown user1 test1
# ls -l
-rwxr-xr-x 1 user1 root 15 xxxxxxxxx test1
3.4. chgrp
ファイル等のグループ変更
# ls -l
-rwxr-xr-x 1 user1 root 15 xxxxxxxxx test1
# chgrp user1 test1
# ls -l
-rwxr-xr-x 1 user1 user1 15 xxxxxxxxx test1
3.5. umask
ファイル等を作成した時のデフォルト権限の確認&変更
# umask
0022
# umask 077
# umask
0077
3.6. su
別ユーザーでコマンド実行
# whoami
user1
# cat /tmp/testdir/testfile
cat: /tmp/testdir/testfile: Permission denied
# su
Password:
# whoami
root
# cat /tmp/testdir/testfile
This is a pen.
4. 特徴的系
4.1. | 『パイプライン』
コマンドを組み合わせる
# ls
test1 test2
# ls | grep test1
test1
4.2. <, >, >> 『リダイレクト』
別のコマンドやファイルに入力、出力を移行
# ls
test1 test2
# ls > test3
# ls
test1 test2 test3
# cat test3
test1
test2
test3
4.3. grep
絞り込み
# cat test3 | grep test2
test2
4.4. sort
並び替え
# cat test3
test1
test2
test3
# sort -r test3
test3
test2
test1
4.5. cut
切り取り
# cat test1
This is a pen.
# cut -c 3-7 test1
is is
4.6. tee
標準出力とファイル出力を行う
# sort -r test3 | tee test4
test3
test2
test1
# ls
test1 test2 test3 test4
5. おわりに
個人的な感想ですが、ここ数ヶ月ですっかりLinuxに魅了されました。
コマンドのボキャブラリーが増えたら、記事更新か別記事にまとめたいと思います。