Linux基礎命令注釋
目錄
cat 查看文件
[root@localhost ~]# cat anaconda-ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability
repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8
...
ls 列出目錄
- ls 列出目錄下所有文件(不包括以' . '開頭的隱藏文件)
[root@localhost ~]# ls
anaconda-ks.cfg
- ls -a 列出文件下所有文件(包括以' . '開頭的隱藏文件)
[root@localhost ~]# ls -a
. anaconda-ks.cfg .bash_logout .bashrc .tcshrc
.. .bash_history .bash_profile .cshrc
- ls -l 列出文件詳細信息 創建者,創建時間,文件讀寫權限
[root@localhost ~]# ls -l
總用量 4
-rw-------. 1 root root 1451 9月 6 22:57 anaconda-ks.cfg
// 1 目錄下只有一個文件 1451 文件大小
- ls . 顯示當前目錄 = ls
basht@localhost ~]# ls .
anaconda-ks.cfg
- ls .. 顯示上一級目錄 = ls /
bashot@localhost ~]# ls /
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
- ls a* 列出a開頭的目錄
[root@localhost ~]# ls a*
anaconda-ks.cfg
a:
- ls /tmp/ /root/ 查看兩個文件的目錄
[root@localhost ~]# ls /tmp/ /root/
/root/:
a abc acd anaconda-ks.cfg bbb c cc qwq vbn wqw
/tmp/:
ks-script-bCAQaW
systemd-private-11747351e8364d83b070d6be17400cce-chronyd.service-lGLDlY
systemd-private-11747351e8364d83b070d6be17400cce-vgauthd.service-g3JiUd
systemd-private-11747351e8364d83b070d6be17400cce-vmtoolsd.service-wE4Eut
yum.log
mkdir 創建目錄
- mkdir 創建目錄
[root@localhost ~]# mkdir a
[root@localhost ~]# ls
a anaconda-ks.cfg
- mkdir -p 創建目錄,若父目錄不在則自動創建
[root@localhost ~]# mkdir -p a/b/{c,d/{e,f/g}}
[root@localhost ~]# ls a
b
[root@localhost ~]# ls a/b
c d
[root@localhost ~]# ls a/b/d
e f
- mkdir -v 顯示創建的目錄的過程
[root@localhost ~]# mkdir -pv a/b/{c,d/{e,f/g}}
mkdir: 已創建目錄 "a"
mkdir: 已創建目錄 "a/b"
mkdir: 已創建目錄 "a/b/c"
mkdir: 已創建目錄 "a/b/d"
mkdir: 已創建目錄 "a/b/d/e"
mkdir: 已創建目錄 "a/b/d/f"
mkdir: 已創建目錄 "a/b/d/f/g"
mv 移動文件(也可用於重命名)
[root@localhost ~]# ls
a anaconda-ks.cfg
[root@localhost ~]# mv a aa
[root@localhost ~]# ls
aa anaconda-ks.cfg
history 歷史命令
- history
[root@localhost ~]# history
1 ls
2 file anaconda-ks.cfg
3 vi anaconda-ks.cfg
4 shutdown -h now
5 cd /etc/sysconfig/network-scripts/
6 vi ifcfg-ens33
7 systemctl restrat network
8 systemctl restart network
9 ip a
10 cdnte
11 cdnet
12 cdnte
13 `
14 cdnte
15 .
16 cdnte
17 cdnet
18 ls /tmp
19 ls
20 cd
- ![n] 調用歷史命令
[root@localhost ~]# !9
ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:3a:87:11 brd ff:ff:ff:ff:ff:ff
inet 192.168.213.128/24 brd 192.168.213.255 scope global dynamic ens33
valid_lft 1309sec preferred_lft 1309sec
inet6 fe80::c862:f7d8:eac7:83ae/64 scope link
valid_lft forever preferred_lft forever
- !! 上一條命令也可以用鍵盤上鍵
[root@localhost ~]# cd -
/etc
[root@localhost etc]# !!
cd -
/root
- history -d[n] 刪除歷史命令 -c刪除所有
[root@localhost ~]# history
1 history
2 pwd
3 cd
4 ls
5 ll
6 history
7 history -n1
8 history -n 1
9 history
[root@localhost ~]# history -d1
[root@localhost ~]# history
1 pwd
2 cd
3 ls
4 ll
5 history
6 history -n1
7 history -n 1
8 history
9 history -d1
10 history
cd 切換目錄
- cd 切換目錄
[root@localhost ~]# cd /etc/
[root@localhost etc]# pwd
/etc
- cd ~ 返回用戶目錄
[root@localhost ~]# cd ~tom
[root@localhost tom]# pwd
/home/tom
[root@localhost etc]# cd ~
[root@localhost ~]#
[root@localhost etc]# cd
[root@localhost ~]# pwd
/root
//直接輸入cd 也可返回當前用戶目錄
- cd ~tom 進入tom家目錄
[root@localhost ~]# cd ~tom
[root@localhost tom]#
- cd -返回上次目錄
[root@localhost ~]# cd /etc
[root@localhost etc]# cd -
/root
[root@localhost ~]# cd -
/etc
- cd .. 返回上級目錄
[root@localhost /]# cd /etc/sysconfig/
[root@localhost sysconfig]# cd ..
[root@localhost etc]#
管道符過濾文件
- cat anaconda-ks.cfg |grep rootpw過濾文件anaconda-ks.cfg中有關rootpw行
[root@localhost ~]# cat anaconda-ks.cfg |grep rootpw
rootpw --iscrypted $6$15KaJSMJ1CnXnZP6$i.4EoTpZwTUTcZhK0oYRIjgyP9UTYbXsq//IV4xIiaB.2RfwtJP7SzhiAN4KcrAZP1ABjRIPx9pdl7vXdHoJk.
- [root@localhost ~]# cat anaconda-ks.cfg |grep rootpw > qwq 過濾文件並打印大qwq文件中
[root@localhost ~]# cat anaconda-ks.cfg |grep rootpw > qwq
[root@localhost ~]# ls
anaconda-ks.cfg qwq
[root@localhost ~]# cat qwq
rootpw --iscrypted $6$15KaJSMJ1CnXnZP6$i.4EoTpZwTUTcZhK0oYRIjgyP9UTYbXsq//IV4xIiaB.2RfwtJP7SzhiAN4KcrAZP1ABjRIPx9pdl7vXdHoJk.
rm 刪除文件
- rm 刪除文件
[root@localhost ~]# ls
aa anaconda-ks.cfg qwq
[root@localhost ~]# rm qwq
rm:是否刪除普通文件 "qwq"?y
[root@localhost ~]# ls
aa anaconda-ks.cfg
- rm -r 遞歸刪除,刪除文件目錄必須用
[root@localhost ~]# ls
aa anaconda-ks.cfg
[root@localhost ~]# rm -r aa
rm:是否進入目錄"aa"? y
rm:是否進入目錄"aa/b"? y
rm:是否刪除目錄 "aa/b/c"?y
rm:是否進入目錄"aa/b/d"? y
rm:是否刪除目錄 "aa/b/d/e"?y
rm:是否進入目錄"aa/b/d/f"? y
rm:是否刪除目錄 "aa/b/d/f/g"?y
rm:是否刪除目錄 "aa/b/d/f"?y
rm:是否刪除目錄 "aa/b/d"?y
rm:是否刪除目錄 "aa/b"?y
rm:是否刪除目錄 "aa"?y
- -f 強制刪除,不詢問
[root@localhost ~]# mkdir -p a/b/c/d/f/c
[root@localhost ~]# ls
a anaconda-ks.cfg
[root@localhost ~]# rm -rf a
[root@localhost ~]# ls
anaconda-ks.cfg
stat : 顯示文件或文件系統的狀態
[root@localhost ~]# stat qwq
文件:"qwq"
大小:126 塊:8 IO 塊:4096 普通文件
設備:fd00h/64768d Inode:100663379 硬鏈接:1
權限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
環境:unconfined_u:object_r:admin_home_t:s0
最近訪問:2019-09-07 14:41:58.769032865 +0800
最近更改:2019-09-07 14:41:58.769032865 +0800
最近改動:2019-09-07 14:41:58.769032865 +0800
創建時間:-
touch 創建空文件或者更新時間戳
[root@localhost ~]# touch qwq
[root@localhost ~]# stat qwq
文件:"qwq"
大小:126 塊:8 IO 塊:4096 普通文件
設備:fd00h/64768d Inode:100663379 硬鏈接:1
權限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
環境:unconfined_u:object_r:admin_home_t:s0
最近訪問:2019-09-07 14:41:58.769032865 +0800
最近更改:2019-09-07 14:41:58.769032865 +0800
最近改動:2019-09-07 14:41:58.769032865 +0800
創建時間:-
alias 命令別名
- alias 命令別名(臨時別名重啟后失效)
[root@localhost ~]# alias cdent='cd /etc/sysconfig/network-scripts'
[root@localhost ~]# cdent
[root@localhost network-scripts]# pwd
/etc/sysconfig/network-scripts
- 命令別名
[root@localhost ~]# vi .bashrc
# .bashrc
# User specific aliases and functions //用戶命令別名當前用戶有效
alias cdnet='cd /etc/sysconfig/network-scripts'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions // 公用命令別名所有用戶有效
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
~
~
".bashrc" 12L, 223C