linux关机命令_Linux基于centOS 7.6常见的Linux命令
一、linux關機命令:
1.shutdown命令安全地將系統關機(推薦)參數說明:
[-r] 重啟計算器。
[-h] 關機后關閉電源〔halt〕。
[-c] cancel current process取消目前正在執行的關機程序。
[-time] 設定關機〔shutdown〕前的時間。
shutdown -h now = 立刻關機
shutdown -h 時間 = 時間關機
shutdown -r now = 立即重啟
shutdown -h 10 = 十分鐘后關機
2.簡提一下 halt 也可單獨使用,也可達到關機的效果,但halt命令是其實halt就是調用shutdown -h。halt執行時,殺死應用進程,執行sync系統調用,內核停止,可能導致linux系統的死機,需要重啟。
3.poweroff 會發送一個 ACPI 信號來通知系統關機。(別人告訴的)
4. init 進程一共分為7個級別, 0和6分別代表關閉和重啟
二、linux重啟命令:
reboot 執行重啟命令,其他的我也不知道還能說些什么。
三、linux查詢所在位置路徑:pwd
[root@www network-scripts]# pwd
/etc/sysconfig/network-scripts
四、linux切換目錄:cd
[root@www network-scripts]# cd -
/root
[root@www ~]#
[root@www network-scripts]# cd ..
[root@www sysconfig]#
[root@www sysconfig]# cd
[root@www ~]#
五、linux創建目錄文件:mkdir
參數:-p 遞歸創建
[root@www /]# mkdir 123
[root@www /]# mkdir -p /123/123
六、linux以樹形結構展示目錄結構:tree
參數:-L :指定層數 -d:只顯示目錄
[root@lizhiming ~]# tree -d /boot
/boot
├── efi
│?? └── EFI
│?? └── centos
├── grub
└── grub2
├── fonts
├── i386-pc
└── locale
七、linux查看命令:ls
參數:-l :長格式顯示 -a :顯示所有文件 -d :顯示目錄
[root@www /]# ls -l 123
total 0
drwxr-xr-x. 2 root root 6 Oct 16 18:31 123
[root@www /]# ls -d 123
123
[root@www /]# ls -a
. 123 backup boot dev home lib64 mnt proc run server sys usr
.. application bin data etc lib media opt root sbin srv tmp var
八、linux復制命令:cp
注釋:111是目錄文件,222是文本
參數:- r 遞歸 -i 是否覆蓋確認 -a 相當于dpr -p保持文件或目錄樹形
[root@www 123]# ls
111 222
[root@www 123]# cp 222 /456/999
[root@www 123]# cd /456
[root@www 456]# ls
999
[root@www 456]# cp -r /123/111 /456/888
[root@www 456]# ls
888 999
九、linux刪除命令:rm
參數:- r 遞歸 - f 強制 兩個一起用你可以刪掉世界(很暴力很血腥,危險的命令)
[root@www /]# rm -rf /123 /456
1
十、linux更改命令別名:alias
刪除別名:unalias
[root@www /]# alias ls='echo 看個錘子啊,笨蛋不配看內容'
[root@www /]# ls
看個錘子啊,笨蛋不配看內容
[root@www /]# unalias ls
[root@www ~]# ls
anaconda-ks.cfg
十一、linux移動命令:mv
參數:- t 把所用源參數移動到目錄中
在相同路徑目錄中使用相當于改名,在不同路徑中相當于移動
[root@www 123]# ls
888
[root@www 123]# mv /123/888 777
[root@www 123]# ls
777
[root@www 123]# mv /123/888 777
[root@www 123]# ls
777
[root@www 123]# mv /123/777 /456/777
[root@www 123]# ls
[root@www 123]# cd /456
[root@www 456]# ls
777
十二、linux打印輸出命令:echo
參數:-h 不換行 - e 支持轉義 t 代表top n 代表回車
[root@www /]# echo 8
8
十三、linux創建文件或更新文件時間戳:touch
[root@yu yuxi]# touch 123
[root@yu yuxi]# ll
total 0
-rw-r--r--. 1 root root 0 Oct 21 19:18 123
[root@yu yuxi]# touch 123
[root@yu yuxi]# ll
total 0
-rw-r--r--. 1 root root 0 Oct 21 19:19 123
十四、linux創建查看文件內容:cat
參數: -n 顯示行號
[root@yu yuxi]# cat 123
123
123
123
[root@yu yuxi]# cat -n 123
1 123
2 123
3 123
十五、linux輸出頭部 / 尾部部分文件:head / tail
參數:-n 行數
[root@yu yuxi]# head -n 4 123
1
2
3
4
[root@yu yuxi]# tail -n 4 123
27
28
29
30
十六、linux替換或刪除字符:tr
注意:只是把文件內容輸出出來,而不是改變文件內容
[root@yu yuxi]# cat 123
999999888888
[root@yu yuxi]# tr '9' '1' < 123
111111888888
[root@yu yuxi]# cat 123
999999888888
十七、linux查找文件里符合條件的字符串:grep
linux中常用的文本(awk,sed,grep)處理工具之一
首先談一下grep命令的常用格式為:grep [選項] ”模式“ [文件]
grep家族總共有三個:grep,egrep,fgrep
參數:
簡單應用:
[root@yu yuxi]# grep -A 2 '15' 123
15
16
17
[root@yu yuxi]# grep -C 2 '15' 123
13
14
15
16
17
[root@yu yuxi]# grep -B 2 '15' 123
13
14
15
[root@yu yuxi]# grep -n '15' 123
15:15
[root@yu yuxi]# grep '15' 123
15
[root@yu yuxi]# grep '1' 123
1
10
11
[root@yu yuxi]# grep -o '1' 123
1
1
1
[root@yu yuxi]# grep -w '1' 123
1
[root@yu yuxi]# egrep -v "^[1-9]$|[1-2][0-9]" 123
30
十八、linux查看文件類型:file
[root@yu yuxi]# file /usr/bin/cp
/usr/bin/cp: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=d5e29bd19107fc7c0a75cffa392da6ac299add6d, stripped
十九、linux:創建創建軟硬鏈接:ln
參數:- s 創建軟連接
[root@yu shangke]# ln -s /yuxi/shangke/123.txt /yuxi/xuexi/ruanlianjie.txt
[root@yu xuexi]# ll -i
352 lrwxrwxrwx. 1 root root 21 Oct 21 21:12 ruanlianjie.txt -> /yuxi/shangke/123.txt
[root@yu xuexi]# ln /yuxi/shangke/123.txt /yuxi/xuexi/lianjie.txt
[root@yu xuexi]# ll -i
16814069 -rw-r--r--. 2 root root 4 Oct 21 21:06 lianjie.txt
16814069 -rw-r--r--. 2 root root 4 Oct 21 21:06 123.txt
二十、linux:查命令所在路徑:which
[root@yu xuexi]# which cp
alias cp='cp -i'
/usr/bin/cp
二十一、 查找目錄下文件:find
參數:
參數 用途
- name 按文件名查找
- type 按文件類型查找(后面接文件類型參數,例如:目錄 d 文件 f
- exec 對搜索結果在處理
- mtime 按修改時間查找
簡單應用:
[root@yu xuexi]# find / -name cp
/usr/bin/cp
[root@yu xuexi]# find /yuxi/ -type f
/yuxi/xuexi/ruanlianjie.txt
/yuxi/shangke/123.txt
二十二、從標準輸入執行命令:xargs
這只是最基礎參考,命令的九牛一毛,詳解百度搜索xargs命令
參數:
[root@yu shangke]# cat 123.txt |xargs -n 3
1 2 3
4 5 6
7 8 9
二十三、查看用戶身份uid/gid:id
[root@yu shangke]# id
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
二十四、查看當前用戶/添加普通用戶:whoami / uesradd
創建用戶就不演示了
[root@yu shangke]# whoami
root
二十五、查看文件屬性:stat
[root@yu shangke]# stat /etc
File: ‘/etc’
Size: 8192 Blocks: 24 IO Block: 4096 directory
Device: 803h/2051d Inode: 16777281 Links: 79
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:etc_t:s0
Access: 2019-10-21 19:43:39.253795426 +0800
Modify: 2019-10-21 18:28:20.106983252 +0800
Change: 2019-10-21 18:28:20.106983252 +0800
Birth: -
二十六、顯示系統時間和日期:date
參數:- s 修改時間 - d 只能過去或未來格式
[root@yu shangke]# date
Mon Oct 21 21:51:25 CST 2019
二十七、 查看運行等級:runlevel
[root@yu shangke]# runlevel
N 3
二十八、切換運行級別:init
[root@yu ~]# init 5
[root@yu ~]# runlevel
3 5
[root@yu shangke]# init 0
[root@yu shangke]# init 6
二十九、修改主機名:hostname
[root@yu ~]# hostname yu
[root@yu ~]# hostnamectl set-hostname yu
三十、壓縮打包:tar
三十一、查看文件系統:df
參數:- i inode 信息 - h 查看block信息
[root@yu ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 1.6G 17G 9% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 1014M 127M 888M 13% /boot
/dev/sr0 4.3G 4.3G 0 100% /yuxi/guazai
tmpfs 98M 0 98M 0% /run/user/0
[root@yu ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda3 9436672 59319 9377353 1% /
devtmpfs 121762 373 121389 1% /dev
tmpfs 124487 1 124486 1% /dev/shm
tmpfs 124487 702 123785 1% /run
tmpfs 124487 16 124471 1% /sys/fs/cgroup
/dev/sda1 524288 326 523962 1% /boot
/dev/sr0 0 0 0 - /yuxi/guazai
tmpfs 124487 1 124486 1% /run/user/0
三十二、點:source
source命令是bash shell的內置命令,點命令,就是個點符號,是source的另一名稱
當前腳本中配置的變量也將作為腳本的環境,source(或點)命令通常用于重新執行剛修改的初始化文檔,比如 . bash_profile 和 . profile 等等
三十三、查看磁盤文件UUID信息:blkid
[root@yu ~]# blkid
/dev/sr0: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sda1: UUID="cc698e40-163f-4464-826e-a80ab50d682a" TYPE="xfs"
/dev/sda2: UUID="e103cc3e-541d-4a08-ac0e-8d9d88f3050f" TYPE="swap"
/dev/sda3: UUID="320e8964-efc4-4d25-96c6-4696a91f96bb" TYPE="xfs"
三十四、指定某個網卡激活啟動/關閉:ifdown/ifup
[root@yu ~]# ifdown ens33 && ifup ens33
Device 'ens33' successfully disconnected.
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
三十五、查看服務是否開啟:telnet
telnet命令通常用來遠程登錄,但也可以確定遠程服務的狀態,比如確定遠程服務器的某個端口是否能訪問。
[root@yu ~]# telnet 10.0.0.200 22
Trying 10.0.0.200...
Connected to 10.0.0.200.
三十六、檢查及刪除文本文件中重復出現的行列 / 文本文件內容加以排序:uniq / sort
sort幾個常用參數:
注意uniq命令只能篩選兩行在一起的數據,分開無法篩選,篩選前先排序
[root@yu xuexi]# cat 1
1
haha
2
haha
3
haha
4
haha
[root@yu xuexi]# sort -n 1 |uniq -c
4 haha
1 1
1 2
1 3
1 4
三十七、外國人在廁所學統計:wc(統計,用于計算數字)
參數: - l 只顯示行數
[root@yu xuexi]# wc -l 1.txt
8 1.txt
三十八、查看硬件信息大禮包
三十九、刪除執行中的程序:kill
強行殺死進程(很暴力很血腥,危險的命令)
[root@yu xuexi]# kill -KILL pts/1
四十、顯示目錄或文件的大小:du
參數:- h 人類能看懂的形式顯示出來
注:顯示指定的目錄或文件所占用的磁盤空間
[root@yu xuexi]# du -h /yuxi/xuexi/
8.0K /yuxi/xuexi/
四十一、顯示當前進程 (process) 的狀態:ps
[root@yu ~]# ps
PID TTY TIME CMD
37758 pts/0 00:00:00 bash
37780 pts/0 00:00:00 ps
總結
以上是生活随笔為你收集整理的linux关机命令_Linux基于centOS 7.6常见的Linux命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: redis序列化_SpringBoot整
- 下一篇: bootstrap table格式化字符