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?

More than 5 years have passed since last update.

dLinuxの基本コマンド集

Last updated at Posted at 2018-04-03
 今いる場所の確認
[root@ik1-321-20522 home]# pwd  
/home
中身の確認
[root@ik1-321-20522 home]# ls -l 
total 2
drwx------ 6 lee       lee       4096 Apr  3 14:30 lee
drwx------ 2      1001      1001   59 Apr  3 13:20 okuno
dirを作る
[root@ik1-321-20522 home]# mkdir test
[root@ik1-321-20522 home]# mkdir test2

二つ作る (-P)
[root@ik1-321-20522 home]# mkdir -P test/test2

確認
[root@ik1-321-20522 home]# ls -l
total 4
drwx------ 6 lee  lee  4096 Apr  3 14:30 lee
drwx------ 2 1001 1001   59 Apr  3 13:20 okuno
drwxr-xr-x 4 root root   46 Apr  3 15:26 test
drwxr-xr-x 3 root root   39 Apr  3 15:16 test2
testのファイルで移動する
[root@ik1-321-20522 home]# cd test

確認
[root@ik1-321-20522 test]# pwd
/home/test

また戻る
[root@ik1-321-20522 test]# cd ..
[root@ik1-321-20522 home]# pwd
/home
ファイルを作る ( > )
[root@ik1-321-20522 test]# cal > cal123.txt

[root@ik1-321-20522 test]# ls -l
total 8
-rw-r--r-- 1 root root 133 Apr  3 18:04 cal10.txt
-rw-r--r-- 1 root root 133 Apr  3 18:05 cal123.txt  ( O )

削除
[root@ik1-321-20522 test]# rm cal10.txt
dirの場合は# rm -G cal10.txt

答え y
rm: remove regular file 'cal10.txt'? y
[root@ik1-321-20522 123.txt]# ls -l
total 4
-rw-r--r-- 1 root root 133 Apr  3 18:05 cal123.txt
中身を見る
[root@ik1-321-20522 123.txt]# cat cal123.txt   
     April 2018
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

中身を見る
[root@ik1-321-20522 123.txt]# less cal123.txt  
     April 2018
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

cal123.txt (END) 
出てる時にq
[root@ik1-321-20522 test]# ls -l
total 4
drwxr-xr-x 2 root root 4096 Apr  3 16:38 subtest
drwxr-xr-x 2 root root    6 Apr  3 11:05 test
-rw-r--r-- 1 root root    0 Apr  3 18:43 test1.txt

[root@ik1-321-20522 test]# cp コピーするファイル名 新しいファイル名
[root@ik1-321-20522 test]# cp test1.txt test2.txt
[root@ik1-321-20522 test]# ls -l
total 4
drwxr-xr-x 2 root root 4096 Apr  3 16:38 subtest
drwxr-xr-x 2 root root    6 Apr  3 11:05 test
-rw-r--r-- 1 root root    0 Apr  3 18:43 test1.txt
-rw-r--r-- 1 root root    0 Apr  3 18:44 test2.txt ( O )
他の所にあるファイルをコピー
[root@ik1-321-20522 test]# ls -l
total 4
drwxr-xr-x 2 root root 4096 Apr  3 16:38 subtest
drwxr-xr-x 2 root root    6 Apr  3 11:05 test
-rw-r--r-- 1 root root    0 Apr  3 18:43 test1.txt
-rw-r--r-- 1 root root    0 Apr  3 18:44 test2.txt

test2の中にあるtest3.txtファイルを今の所にコピーしました。
[root@ik1-321-20522 test]# cp /home/test2/test3.txt .
[root@ik1-321-20522 test]# ls -l
total 4
drwxr-xr-x 2 root root 4096 Apr  3 16:38 subtest
drwxr-xr-x 2 root root    6 Apr  3 11:05 test
-rw-r--r-- 1 root root    0 Apr  3 18:43 test1.txt
-rw-r--r-- 1 root root    0 Apr  3 18:44 test2.txt
-rw-r--r-- 1 root root    0 Apr  3 18:51 test3.txt
ここにあるファイルを他の所に移動する
[root@ik1-321-20522 test2]# ls -l
total 0
-rw-r--r-- 1 root root  0 Apr  3 11:43 mydiary.txt
drwxr-xr-x 2 root root 53 Apr  3 15:20 subtest2
-rw-r--r-- 1 root root  0 Apr  3 18:54 test4.txt

test2の中にあるtest4.txtファイルをtest1に移動する
[root@ik1-321-20522 test2]# mv test4.txt ../test

[root@ik1-321-20522 test]# ls -l
total 4
drwxr-xr-x 2 root root 4096 Apr  3 16:38 subtest
drwxr-xr-x 2 root root    6 Apr  3 11:05 test
-rw-r--r-- 1 root root    0 Apr  3 18:43 test1.txt
-rw-r--r-- 1 root root    0 Apr  3 18:44 test2.txt
-rw-r--r-- 1 root root    0 Apr  3 18:51 test3.txt
-rw-r--r-- 1 root root    0 Apr  3 18:54 test4.txt ( O )
他の所にあるファイルを今いる所に移動する
[root@ik1-321-20522 test2]# ls -l
total 0
-rw-r--r-- 1 root root  0 Apr  3 11:43 mydiary.txt
drwxr-xr-x 2 root root 53 Apr  3 15:20 subtest2
-rw-r--r-- 1 root root  0 Apr  3 18:59 test5.txt

test2の中にあるtest5.txtファイルを今の所に移動する
[root@ik1-321-20522 test]# mv /home/test2/test5.txt .
[root@ik1-321-20522 test]# ls -l
total 4
drwxr-xr-x 2 root root 4096 Apr  3 16:38 subtest
drwxr-xr-x 2 root root    6 Apr  3 11:05 test
-rw-r--r-- 1 root root    0 Apr  3 18:43 test1.txt
-rw-r--r-- 1 root root    0 Apr  3 18:44 test2.txt
-rw-r--r-- 1 root root    0 Apr  3 18:51 test3.txt
-rw-r--r-- 1 root root    0 Apr  3 18:54 test4.txt
-rw-r--r-- 1 root root    0 Apr  3 18:59 test5.txt ( O )
ファイル名を変える時
[root@ik1-321-20522 test]# mv 古いファイル名 新しいファイル名
[root@ik1-321-20522 test]# mv test5.txt test6.txt
[root@ik1-321-20522 test]# ls -l
total 4
drwxr-xr-x 2 root root 4096 Apr  3 16:38 subtest
drwxr-xr-x 2 root root    6 Apr  3 11:05 test
-rw-r--r-- 1 root root    0 Apr  3 18:43 test1.txt
-rw-r--r-- 1 root root    0 Apr  3 18:44 test2.txt
-rw-r--r-- 1 root root    0 Apr  3 18:51 test3.txt
-rw-r--r-- 1 root root    0 Apr  3 18:54 test4.txt
-rw-r--r-- 1 root root    0 Apr  3 18:59 test6.txt ( O )
現在のユーザーを確認
[root@ik1-321-20522 home]# whoami
root
新しいユーザー追加
[root@ik1-321-20522 home]# useradd ユーザー名
[root@ik1-321-20522 home]# useradd me

[root@ik1-321-20522 home]# passwd ユーザー名
[root@ik1-321-20522 home]# passwd me
Changing password for user me.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

ユーザー変更
[root@ik1-321-20522 home]# su ユーザー名
[root@ik1-321-20522 home]# su me

ユーザー検索
[me@ik1-321-20522 home]$ whoami
me
出る
[me@ik1-321-20522 home]$ exit
exit
[root@ik1-321-20522 home]#
パーミッション
-rw-r--r-- 1 root root    0 Apr  3 18:54 test4.txt
-rwxr--r-- 1 root root    0 Apr  3 18:59 test6.txt
-rwx   r--    r--      r:4   w:2
user    group   other     x:1   -:0

test4は 644
test6は 744
[root@ik1-321-20522 test]# wc -l test1.txt
0 test1.txt
[root@ik1-321-20522 test]# nl test1.txt
[root@ik1-321-20522 test]# cat cal1.txt
     April 2018
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

cal1.txtの中身をdateで変更

[root@ik1-321-20522 test]# date > cal1.txt
[root@ik1-321-20522 test]# cat cal1.txt
Tue Apr  3 20:17:58 JST 2018
中身を見るのもできるし内容を変更できる
[root@ik1-321-20522 test]# vi ファイル名
[root@ik1-321-20522 test]# vi sample.txt
iを入力すると書くのができる。
移動する時左(H)上(J)下(K)右(L)
      1 hello
      2 hi
      3 how are you?
      4 ok
      5 thank you
      6
~
~
~
出る時
:q! 保存しなくて出る
:wq 保存して出る
:w  保存
:se nu 列の番号が見やすい
ユーザー追加
[root@ik1-321-20522 test]#useradd ユーザー名
[root@ik1-321-20522 test]#useradd me

ユーザー確認
[root@ik1-321-20522 test]#cat /etc/passwd
me:x:1005:1007::/home/me:/bin/bash

ユーザー削除
[root@ik1-321-20522 test]#userdel me
gorupも同じ groupadd , groupdel
groupにユーザーを追加

[root@ik1-321-20522 test]# usermod -G グループ名 ユーザー名
[root@ik1-321-20522 test]# usermod -G base me

確認
[root@ik1-321-20522 test]# id ユーザー名
[root@ik1-321-20522 test]# id me
uid=1005(me) gid=1007(me) groups=1007(me),1008(base)
[root@ik1-321-20522 subNewDir3]# pstree
-bash: pstree: command not found

コマンドがないのでインストールする
[root@ik1-321-20522 subNewDir3]# yum install psmisc
Loaded plugins: fastestmirror, langpacks
base                                                                                                                      | 3.6 kB  00:00:00
epel/x86_64/metalink                                                                                                      | 7.8 kB  00:00:00
epel                                                                                                                      | 4.7 kB  00:00:00
extras                                                                                                                    | 3.4 kB  00:00:00
updates                                                                                                                   | 3.4 kB  00:00:00
(1/7): base/7/x86_64/group_gz                                                                                             | 156 kB  00:00:02
(2/7): epel/x86_64/group_gz                                                                                               | 266 kB  00:00:01
(3/7): extras/7/x86_64/primary_db                                                                                         | 185 kB  00:00:01
(4/7): epel/x86_64/updateinfo                                                                                             | 904 kB  00:00:03
(5/7): epel/x86_64/primary_db                                                                                             | 6.3 MB  00:00:04
(6/7): base/7/x86_64/primary_db                                                                                           | 5.7 MB  00:00:07
(7/7): updates/7/x86_64/primary_db                                                                                        | 6.9 MB  00:00:07
Determining fastest mirrors
 * base: ftp.tsukuba.wide.ad.jp
 * epel: mirror01.idc.hinet.net
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
Resolving Dependencies
--> Running transaction check
---> Package psmisc.x86_64 0:22.20-15.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================
 Package                          Arch                             Version                                  Repository                      Size
=================================================================================================================================================
Installing:
 psmisc                           x86_64                           22.20-15.el7                             base                           141 k

Transaction Summary
=================================================================================================================================================
Install  1 Package

Total download size: 141 k
Installed size: 475 k

参考URL:https://qiita.com/todanano/items/f421c237eaa2d9adff04

上手くインストールできたので確認してみる
[root@ik1-321-20522 subNewDir3]# pstree
systemd-+-NetworkManager---2*[{NetworkManager}]
        |-abrt-watch-log
        |-abrtd
        |-2*[agetty]
        |-atd
        |-auditd---{auditd}
        |-chronyd
        |-crond
        |-dbus-daemon
        |-fail2ban-server---2*[{fail2ban-server}]
        |-firewalld---{firewalld}
        |-lsmd
        |-lvmetad
        |-master-+-pickup
        |        `-qmgr
        |-polkitd---5*[{polkitd}]
        |-rngd
        |-rsyslogd---2*[{rsyslogd}]
        |-smartd
        |-sshd---sshd---bash---pstree
        |-systemd-journal
        |-systemd-logind
        |-systemd-udevd
        |-tuned---4*[{tuned}]
        `-wpa_supplicant
実行中のプロセスを表示 : ps , pstree , top
実行中のプロセスの優先度を確認する : ps -l , top
プロセスをツリー構造で表示する : pstree
[root@ik1-321-20522 home]# ps
  PID TTY          TIME CMD
 7827 pts/0    00:00:00 bash
 8266 pts/0    00:00:00 ps

[root@ik1-321-20522 home]# top
top - 19:11:37 up 2 days,  5:17,  1 user,  load average: 0.00, 0.01, 0.05
Tasks:  92 total,   2 running,  90 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.3 st
KiB Mem :   500824 total,    27212 free,   113980 used,   359632 buff/cache
KiB Swap:  4194300 total,  4193636 free,      664 used.   340612 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
  524 libstor+  20   0    8532    804    656 S  0.3  0.2   0:02.00 lsmd
 1210 root      20   0  300940  12544   3864 S  0.3  2.5   1:26.22 fail2ban-server
    1 root      20   0   41304   3444   2128 S  0.0  0.7   0:08.14 systemd
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.09 kthreadd
    3 root      20   0       0      0      0 S  0.0  0.0   0:00.61 ksoftirqd/0
    6 root      20   0       0      0      0 S  0.0  0.0   0:00.82 kworker/u2:0
    7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0
    8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh
    9 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcuob/0
   10 root      20   0       0      0      0 S  0.0  0.0   0:07.62 rcu_sched
   11 root      20   0       0      0      0 R  0.0  0.0   0:11.07 rcuos/0
   12 root      rt   0       0      0      0 S  0.0  0.0   0:01.97 watchdog/0
   13 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 khelper
   14 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs
   15 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns
   16 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 perf
   17 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback
   18 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kintegrityd
   19 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset
   20 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kblockd
   21 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 md
   29 root      20   0       0      0      0 S  0.0  0.0   0:00.26 khungtaskd
   30 root      20   0       0      0      0 S  0.0  0.0   0:00.30 kswapd0
   31 root      25   5       0      0      0 S  0.0  0.0   0:00.00 ksmd
   32 root      20   0       0      0      0 S  0.0  0.0   0:00.00 fsnotify_mark
   33 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 crypto
   41 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kthrotld
   42 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kmpath_rdacd
   43 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kpsmoused
   45 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 ipv6_addrconf
   64 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 deferwq
  116 root      20   0       0      0      0 S  0.0  0.0   0:00.08 kauditd
  220 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kworker/u2:2
  221 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 ata_sff

[root@ik1-321-20522 home]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0  7827  7825  0  80   0 -  3242 wait   pts/0    00:00:00 bash
0 T     0  8276  7827  0  80   0 -  1668 signal pts/0    00:00:00 less
0 R     0  8277  7827  0  80   0 - 11325 -      pts/0    00:00:00 ps
& : less /etc/passwdをバックグラウンドで実行
[root@ik1-321-20522 home]# less pstree &
[1] 8273

現在バックグラウンドで走っているジョブを全て表示
[root@ik1-321-20522 home]# jobs
[1]+  Stopped                 less pstree

fg : バックグラウンドで実行中のジョブをフォアグラウンドで実行
[root@ik1-321-20522 home]# fg less petree
less pstree
[root@ik1-321-20522 home]# jobs
[root@ik1-321-20522 home]#

nohup : ログアウトしてもジョブしてもバックグラウンドでless /etc/passwdを実行
[root@ik1-321-20522 home]# nohup less /etc/paswwd &
設定した最終行を見れる
[root@ik1-321-20522 home]# tail -5 /etc/passwd
yamada:x:1007:1010::/home/yamada:/bin/bash
suzuki:x:1008:1011::/home/suzuki:/bin/bash
takahashi:x:1009:1012::/home/takahashi:/bin/bash
bob:x:1010:1013::/home/bob:/bin/bash
jack:x:1011:1014::/home/jack:/bin/bash

* は全部の意味
例 *.txtをすると.txtの全てのファイル
新しく習ったこと
絶対パースで他の所にあるファイルを確認とか色んな命令ができる


yahooページの情報があるファイルを作る
[root@ik1-321-20522 home]# wget http://yahoo.co.jp
--2018-04-05 19:40:02--  http://yahoo.co.jp/
Resolving yahoo.co.jp (yahoo.co.jp)... 183.79.135.206, 182.22.59.229
Connecting to yahoo.co.jp (yahoo.co.jp)|183.79.135.206|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://www.yahoo.co.jp/ [following]
--2018-04-05 19:40:02--  https://www.yahoo.co.jp/
Resolving www.yahoo.co.jp (www.yahoo.co.jp)... 183.79.248.252
Connecting to www.yahoo.co.jp (www.yahoo.co.jp)|183.79.248.252|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: 'index.html'

    [ <=>                                                                                            ] 20,099      --.-K/s   in 0.03s

2018-04-05 19:40:02 (682 KB/s) - 'index.html' saved [20099]

'index.html'のファイルでyahooページのhtmlコーディングを確認する
cal.txtリンクでcal2.txtを作ったらcal.txtの中身を変更してもcal2.txtの
中身が同じになる
[root@ik1-321-20522 lntest]# ln cal.txt cal2.txt
[root@ik1-321-20522 lntest]# cat cal.txt
     April 2018
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

[root@ik1-321-20522 lntest]# cat cal2.txt
     April 2018
Su Mo Tu We Th Fr Sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
ディレクトリ中のファイルをまとめてする
[root@ik1-321-20522 test]# tar cf ファイル名 *
[root@ik1-321-20522 test]# tar cf all.txt *
[root@ik1-321-20522 test]# ls -l
total 4
-rw-r--r-- 1 root root  0 Apr 11 19:17 cal.txt
-rw-r--r-- 1 root root 29 Apr 11 19:17 date.txt

確認
[root@ik1-321-20522 test]# tar tvf all.txt
-rw-r--r-- root/root       133 2018-04-11 19:18 cal.txt
-rw-r--r-- root/root        29 2018-04-11 19:17 date.txt

zipにする
[root@ik1-321-20522 test]# gzip all.txt
[root@ik1-321-20522 test]# ls -l
total 12
-rw-r--r-- 1 root root 262 Apr 11 19:19 all.txt.gz
-rw-r--r-- 1 root root 133 Apr 11 19:18 cal.txt
-rw-r--r-- 1 root root  29 Apr 11 19:17 date.txt

帰る
[root@ik1-321-20522 test]# tar xf all.txt
[root@ik1-321-20522 test]# gunzip all.txt
linux version 検索
[root@ik1-321-20522 test]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
  4735  /usr/lib/python2.7/site-packages/langtable-0.0.31-py2.7.egg-info
  4736  /usr/lib/python2.7/site-packages/langtable.py
  4737  /usr/lib/python2.7/site-packages/langtable.pyc
  4738  /usr/lib/python2.7/site-packages/langtable.pyo
4738 python.pkg.info
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?