Linux常用基础必备命令

目录

使用指定网卡进行Ping操作

查看系统信息

查看时间

系统的关机、重启及登出

目录的创建、删除、复制

文件的创建、删除、复制

查看系统用户的登录信息

显示历史命令

apt管理软件

运行级别

修改开机界面

网络配置


使用指定网卡进行Ping操作

小摘要:

[client@server2 ~]$ ping  -I  本机指定网卡名或网卡的IP地址  目标地址

1. 查看ping的帮助

[client@server2 ~]$ ping --help
ping:无效选项 -- -
Usage: ping [-aAbBdDfhLnOqrRUvV64] [-c count] [-i interval] [-I interface]
            [-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
            [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
            [-w deadline] [-W timeout] [hop1 ...] destination
Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
             [-l preload] [-m mark] [-M pmtudisc_option]
             [-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
             [-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline]
             [-W timeout] destination
[client@server2 ~]$ 

2. 查看man帮助,找到 -I interface 这一项。

[client@server2 ~]$ man ping
  -I interface
              interface is either an address, or an interface name.  If inter‐
              face  is  an address, it sets source address to specified inter‐
              face address.  If interface in an interface name, it sets source
              interface  to specified interface.  For IPv6, when doing ping to
              a link-local scope address, link specification (by the '%'-nota‐
              tion in destination, or by this option) is required.


3. 使用  -I  选项实现指定网卡(可以是IP地址或者是网卡名)进行ping操作

[client@server2 ~]$ ping -I ens33 www.baidu.com
PING www.wshifen.com (104.193.88.77) from 192.168.1.11 ens33: 56(84) bytes of data.
64 bytes from 104.193.88.77 (104.193.88.77): icmp_seq=2 ttl=128 time=171 ms
64 bytes from 104.193.88.77 (104.193.88.77): icmp_seq=3 ttl=128 time=165 ms
^C
--- www.wshifen.com ping statistics ---
3 packets transmitted, 2 received, 33% packet loss, time 2004ms
rtt min/avg/max/mdev = 165.467/168.531/171.595/3.064 ms
[client@server2 ~]$ ping -I 192.168.1.100 www.baidu.com
PING www.wshifen.com (104.193.88.123) from 192.168.1.100 : 56(84) bytes of data.
64 bytes from 104.193.88.123 (104.193.88.123): icmp_seq=1 ttl=128 time=161 ms
^C
--- www.wshifen.com ping statistics ---
2 packets transmitted, 1 received, 50% packet loss, time 1001ms
rtt min/avg/max/mdev = 161.649/161.649/161.649/0.000 ms
[client@server2 ~]$ 

查看系统信息

1. 查看内核版本

uname -r    
cat /proc/version

2. 查看系统发行版本

lsb_release -a     #列出版本信息,适用所有版本
cat /etc/issue     #适用所有版
cat /etc/redhat -release     #适用于red hat

查看时间

1. 查看系统日期

root@server:~# date
2020年 05月 08日 星期五 13:14:07 CST

2. 查看日历

root@server:~# cal 2020

系统的关机、重启及登出

1. 关闭系统

shutdown -h now     #关机后关闭电源(halt),立即关机
shutdown -h 16:00     #绝对时间关机,shutdown+c取消
shutdown -h +5     #相对时间关机
shutdown +5 "System will shutdown after 5 minutes"    #指定时间关机,同时送出警告信息给登录用户
shutdown -r now     #重新启动
reboot     #重启
halt     #立即关机
poweroff     #立刻关机
init 0     #立即关机
init 6     #重启
telinit 0
shutdown -c    #取消按预定时间关闭系统

2. 重启

shutdown -r now
reboot
init 6

3. 注销

logout

目录的创建、删除、复制

1. 进入目录

cd    #进入个人的主目录
cd ..    #返回上一级目录
cd -    #返回上次所在目录    

2. 查看目录

pwd    #显示工作路径
ls    #查看目录中的文件
ls -l    #显示文件和目录的详细资料
ls -a    #显示隐藏文件
ls *[0-9]*    #显示包含数字的文件名和目录
tree    #树形结构

3. 创建目录

mkdir 目录名
mkdir 目录名 目录名

4. 删除目录

rm -r 目录名    #删除目录及以下内容
rmdir 目录名    #删除空目录

5. 复制目录

cp dir/* .    #复制一个目录下的所有文件到当前工作目录
cp -a dir1 dir2 #复制目录dir1并改名为dir2

文件的创建、删除、复制

1. 创建文件

touch file1

2. 删除文件

rm file1

3. 复制文件

cp file1 file2

4. 搜索文件

find / -name file    #从“/”开始搜索文件
find / -user

查看系统用户的登录信息

root@server:~# who
root    tty2    2020-05-13 16:57
root@server:~# who am i
root    tty2    2020-05-13 16:57
root@server:~# whoami
root
root@server:~#

显示历史命令

history [n]

apt管理软件

apt,即Advanced Packaging Tool,高级包管理工具。

apt-get update     #查询升级
apt-get upgrade -y     #执行升级
apt-get install 软件包名     #安装软件
apt-get remove 软件包名     #软件移除
apt-cache search 软件包名     #搜索软件包
apt-cache depends 软件包名     #显示该件包的依赖信息

运行级别

1. 运行级别

00:关机
1:rescue模式
2-4:多用户模式
5:图形界面
6:重新启动
Ubuntu18.04系统的默认运行级别是5
CentOS8.1的默认运行级别是5

2. 切换运行级别

init n     # n 为0~6

3. 显示运行级别

runlevel

修改开机界面

systemctl get-default     #查看当前界面
systemctl set-default graphical.target     #重启后进入图形界面,对应运行级别5
systemctl set-desault multi-user.target    #重启后进入多用户的字符界面,对应运行级别2~4

网络配置

ip addr show ens33     #查看网卡
cat /etc/sysconfig/network-scripts/ifcfg-ens33     #查看网卡网络配置
vim /etc/sysconfig/network-scripts/ifcfg-ens33     #编辑网络配置

管理用户

1. 创建用户

sudo adduser 用户名    (创建用户同时设置密码)
sudo useradd 用户名




 

持续更新中。。。

猜你喜欢

转载自blog.csdn.net/qq_44932745/article/details/105901942