linux关机命令_Linux基于centOS 7.6常见的Linux命令

7818b781ca5e8869433b8788c22d1f00.png

一、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

67fce442205577037616dfd916dd0885.png

八、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

参数:

7a84e75e11c72161a1976a617b1e1bc1.png

简单应用:

[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命令

参数:

1b25af39b592b951a8de6ad5f61e2a33.png

[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

26aed4b0351e7de3ae0464d1013f83bc.png

三十一、查看文件系统: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命令只能筛选两行在一起的数据,分开无法筛选,筛选前先排序

6d72f338d51c881a40e2e07e72f46748.png

[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

三十八、查看硬件信息大礼包

6d72f338d51c881a40e2e07e72f46748.png

三十九、删除执行中的程序: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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值