0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【初心者エンジニア Presents】 よく使うLinuxコマンドメモ

Last updated at Posted at 2021-09-10

目次

1. はじめに

こんにちは、初心者エンジニアです。
働く中でLinuxのコマンドがわからなくなり、調べてしまうことが多々あるため、メモとしてまとめることにしました。
テスト環境ということで、基本rootで行ってます。
オプション等はまた別の機会に...

2. 基本系

2.1. pwd

カレントディレクトリを表示

Command
# pwd
/root 

2.2. cd

ディレクトリの変更

Command
# cd /tmp
# pwd
/tmp

2.3. ls

ディレクトリにあるファイル等を表示

Command
# ls /
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr

2.4. mkdir

ディレクトリの作成

Command
# mkdir test
# ls -F
test/

2.5. cat

ファイルの表示&連結

Command
# cat test1
This is a pen.

2.6. find

ファイル等の検索

Command
# find ./test1
./test1

2.7. cp

ファイル等のコピー

Command
# mkdir /tmp/testdir 
# cp test1 /tmp/testdir 
# ls /tmp/testdir
test1

2.8. mv

ファイル等の移動&名前変更

Command
# mv /tmp/testdir/test1 /tmp/testdir/test2
# ls /tmp/testdir
test2
# mv /tmp/testdir/test2 /root
# ls /root
test1 test2

2.9. rm

ファイル等の消去

Command
# rm test2
rm: remove rehular file 'test2'? y
# ls
test1

2.10. ln

ファイル等のリンクを作成

Command
# pwd
/tmp/testdir
# ln -s /root/test1 testfile
# ls -l
lrwxrwxrwx 1 root root 11 xxxxxxxxx testfile -> /root/test1

2.11. more

ファイルを画面ごとに表示

Command
# more test1

2.12. touch

ファイルのタイムスタンプを更新&無のファイル作成

Command
# touch test2
# ls
test1 test2

3. 管理系

3.1. who

ログインしているユーザーを表示

Command
# who
root    tty1    xxxxxxxxx

3.2. chmod

ファイル等の権限変更

Command
# 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

ファイル等の所有者&グループ変更

Command
# 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

ファイル等のグループ変更

Command
# 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

ファイル等を作成した時のデフォルト権限の確認&変更

Command
# umask
0022
# umask 077
# umask
0077

3.6. su

別ユーザーでコマンド実行

Command
# 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. | 『パイプライン』

コマンドを組み合わせる

Command
# ls
test1 test2
# ls | grep test1
test1

4.2. <, >, >> 『リダイレクト』

別のコマンドやファイルに入力、出力を移行

Command
# ls
test1 test2
# ls > test3
# ls
test1 test2 test3
# cat test3
test1
test2
test3

4.3. grep

絞り込み

Command
# cat test3 | grep test2
test2

4.4. sort

並び替え

Command
# cat test3
test1
test2
test3
# sort -r test3
test3
test2
test1

4.5. cut

切り取り

Command
# cat test1
This is a pen.
# cut -c 3-7 test1
is is

4.6. tee

標準出力とファイル出力を行う

Command
# sort -r test3 | tee test4
test3
test2
test1
# ls
test1 test2 test3 test4

5. おわりに

個人的な感想ですが、ここ数ヶ月ですっかりLinuxに魅了されました。
コマンドのボキャブラリーが増えたら、記事更新か別記事にまとめたいと思います。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?