本记录来自腾讯云实验 https://cloud.tencent.com/developer/labs/lab/10000
已连接到实验云主机
登录:ssh [email protected] -p 22
密码:ncuswbwiXA0@
系统:CentOS 7.2 64 位
已连接到实验云主机
登录:ssh [email protected] -p 22
密码:drjzyW0#^^#%
系统:CentOS 7.2 64 位
已连接到实验云主机
登录:ssh [email protected] -p 22
密码:uwNTOGZHXX5#
系统:CentOS 7.2 64 位
已连接到实验云主机
登录:ssh [email protected] -p 22
密码:rbszRPL58&^~
系统:Ubuntu 16.04.1 LTS 64 位
本记录来自腾讯云实验 https://cloud.tencent.com/developer/labs/lab/10000
目录操作
任务时间:5min ~ 10min
创建目录
使用 mkdir 命令创建目录
mkdir $HOME/testFolder
切换目录
使用 cd 命令切换目录
cd $HOME/testFolder
使用 cd ../ 命令切换到上一级目录
cd ../
移动目录
使用 mv 命令移动目录
mv $HOME/testFolder /var/tmp
删除目录
使用 rm -rf 命令删除目录
rm -rf /var/tmp/testFolder
查看目录下的文件
使用 ls 命令查看 [/etc] 目录下所有文件和文件夹
ls /etc
/etc 目录默认是 *nix 系统的软件配置文件存放位置
文件操作
任务时间:5min ~ 10min
创建文件
使用 touch 命令创建文件
touch ~/testFile
执行 ls
命令, 可以看到刚才新建的 testFile 文件
ls ~
复制文件
使用 cp 命令复制文件
cp ~/testFile ~/testNewFile
删除文件
使用 rm 命令删除文件, 输入 y
后回车确认删除
rm ~/testFile
查看文件内容
使用 cat 命令查看 .bash_history 文件内容
cat ~/.bash_history
过滤, 管道与重定向
任务时间:5min ~ 10min
过滤
过滤出 /etc/passwd 文件中包含 root
的记录
grep 'root' /etc/passwd
递归地过滤出 /var/log/ 目录中包含 linux
的记录
grep -r 'linux' /var/log/
管道
简单来说, Linux 中管道的作用是将上一个命令的输出作为下一个命令的输入, 像 pipe 一样将各个命令串联起来执行, 管道的操作符是 |
比如, 我们可以将 cat 和 grep 两个命令用管道组合在一起
cat /etc/passwd | grep 'root'
过滤出 /etc 目录中名字包含 ssh
的目录(不包括子目录)
ls /etc | grep 'ssh'
重定向
可以使用 > 或 < 将命令的输出重定向到一个文件中
echo 'Hello World' > ~/test.txt
运维常用命令
任务时间:5min ~ 10min
ping 命令
对 cloud.tencent.com 发送 4 个 ping 包, 检查与其是否联通
ping -c 4 cloud.tencent.com
netstat 命令
netstat 命令用于显示各种网络相关信息,如网络连接, 路由表, 接口状态等等
列出所有处于监听状态的tcp端口
netstat -lt
查看所有的端口信息, 包括 PID 和进程名称
netstat -tulpn
ps 命令
过滤得到当前系统中的 ssh 进程信息
ps -aux | grep 'ssh'
完成实验
目录操作
-
创建目录
使用 mkdir 命令创建目录
mkdir $HOME/testFolder
- 切换目录
使用 cd 命令切换目录
cd $HOME/testFolder
使用 cd ../ 命令切换到上一级目录
cd ../
[root@VM-24-20-centos ~]# cat /etc/passwd | grep 'root'
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@VM-24-20-centos ~]# ls /etc|grep 'ssh'
ssh
[root@VM-24-20-centos ~]# echo 'Hello World'> test.txt
[root@VM-24-20-centos ~]# ls
miniconda3 testNewFile
Miniconda3-py38_4.8.2-Linux-x86_64.sh test.txt
[root@VM-24-20-centos ~]# cat test.txt
Hello World
[root@VM-24-20-centos ~]# ping -c 4 cloud.tencent.com
PING cloud-gz.tencent-cloud.com (193.112.234.28) 56(84) bytes of data.
64 bytes from 193.112.234.28 (193.112.234.28): icmp_seq=1 ttl=57 time=0.957 ms
64 bytes from 193.112.234.28 (193.112.234.28): icmp_seq=2 ttl=57 time=0.969 ms
64 bytes from 193.112.234.28 (193.112.234.28): icmp_seq=3 ttl=57 time=0.978 ms
64 bytes from 193.112.234.28 (193.112.234.28): icmp_seq=4 ttl=57 time=0.927 ms
--- cloud-gz.tencent-cloud.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 0.927/0.957/0.978/0.042 ms
[root@VM-24-20-centos ~]# netstat -lt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
[root@VM-24-20-centos ~]# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 924/sshd
udp 0 0 10.104.24.20:123 0.0.0.0:* 1317/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 1317/ntpd
udp6 0 0 ::1:123 :::* 1317/ntpd
udp6 0 0 fe80::5054:ff:fe7b::123 :::* 1317/ntpd
[root@VM-24-20-centos ~]# ps aux | grep 'ssh'
root 924 0.0 0.4 112924 4324 ? Ss 14:12 0:00 /usr/sbin/sshd -D
root 2721 0.0 0.5 155112 5844 ? Ss 14:17 0:00 sshd: root@pts/0
root 3749 0.0 0.5 154736 5584 ? Ss 14:19 0:00 sshd: root@pts/1
root 3838 0.0 0.5 154740 5360 ? Ss 14:20 0:00 sshd: root@notty
root 3841 0.0 0.2 72252 2856 ? Ss 14:20 0:00 /usr/libexec/openssh/sftp-server
root 14004 0.0 0.5 154736 5580 ? Ss 14:38 0:00 sshd: root@pts/2
root 14020 0.0 0.5 154740 5360 ? Ss 14:38 0:00 sshd: root@notty
root 14055 0.0 0.2 72252 2868 ? Ss 14:38 0:00 /usr/libexec/openssh/sftp-server
root 20576 0.0 0.0 112812 972 pts/0 R+ 14:53 0:00 grep --color=auto ssh