# ip a //查看虚拟机ip
# route -n //查看网关
# systemctl restart network //重启网络服务
# ping www.jd.com //通信测试
windows中查看ip:win+r,输入cmd,命令框输入ipconfig
1.文件查看
# ls [list 列出] 列出当前目录下所有的文件 # ls -a [-a all 显示所有的文件,包含隐藏文件,在linux中以"."开头的文件为隐藏文件] # ls -lh (ll -h) [-h human-readable 让文件的大小以人类易读的方式显示,-h和-l要一块使用] # ls -lt (ll -t) [-t time 以时间顺序排序,最新的文件在上边 默认以文件名排序] # ls -ld (ll -d) [-d directory 目录] # ls --help [help 帮助,查看帮助信息] # ls -l = # ll 文件查看补充内容[统配符] * 代表零个或多个任意字符 ?代表一个任意字符
2.文件创建(普通文件)
命令格式 touch filename [filename1 filename2 ..] 创建单个文件 # touch 2103.txt //创建普通文件 2103.txt 同时创建多个文件 # touch 2103-1.txt 2103-2.txt 2103-3.txt 同时创建多个文件 # touch 2103-{5..10}.txt # ll 2103-*.txt ...... # touch 2103-{a..d}.txt {5..10} 代表5--10 {5,6,7,8,9,10} {a..d} 代表 a--d {a,b,c,d} 该顺序与ascii码表有关 命令规范 1、文件名由字母、数字、下划线、- 组成 2、不能以数字作为文件名的开头 Linux里面一切皆文件
3.目录创建
mkdir # 创建目录 make directories Create the DIRECTORY(ies), if they do not already exist. 创建目录,如果不存在 命令格式 mkdir dirname [dirname1 dirname2 ...] 创建单个目录 # mkdir 21 //创建一个名称是21的目录 # ls # 21 [我们发现普通文件一半是黑色,目录一半是蓝色, 但不是绝对] 创建多个目录 # mkdir 21-2 21-3 21-4 .. # ls 21-2 21-3 21-4 目录创建也可以使用统配 # 创建层级目录 # mkdir -p a/b/c -p make parent directories as needed 如果有需要就创建父目录 查看创建过程 # mkdir -pv b/c/d mkdir: 已创建目录 "b" mkdir: 已创建目录 "b/c" mkdir: 已创建目录 "b/c/d" -v print a message for each created directory 打印每一个目录的创建信息
5.目录切换
cd 切换目录 changde directory # pwd //查看自己当前所处的位置 /root # cd /etc/sysconfig/network-scripts/ //切换路径到 /etc/sysconfig/network-scripts/ # pwd /etc/sysconfig/network-scripts/ ------ 特殊的切换 # cd . //未进行切换 因为.代表当前路径 # cd .. //返回上一级目录 [root@tiger-ack network-scripts]# pwd /etc/sysconfig/network-scripts [root@tiger-ack network-scripts]# cd .. [root@tiger-ack sysconfig]# pwd /etc/sysconfig # cd ~ //切换到用户的家目录 ~代表当前用户的家目录 [~可以省略] [root@tiger-ack sysconfig]# pwd /etc/sysconfig [root@tiger-ack sysconfig]# cd ~ [root@tiger-ack ~]# pwd /root #cd - //回到上一次所在的目录 [root@tiger-ack network-scripts]# pwd /etc/sysconfig/network-scripts [root@tiger-ack network-scripts]# cd [root@tiger-ack ~]# pwd /root [root@tiger-ack ~]# cd - /etc/sysconfig/network-scripts [root@tiger-ack network-scripts]# cd - /root [root@tiger-ack ~]# cd - /etc/sysconfig/network-scripts [root@tiger-ack network-scripts]# cd - /root --------------- 注意绝对路径和相对路径 从/路径开始称为绝对路径 /usr/local/src /etc/sysconfig/network-scripts /root /tmp 从非/路径开始称为相对路径 .. ./src ../tmp yum -y install tree 安装软件包 tree tree /dirname 查看目录的层级结构 tree -L 1 /dirname 查看目录下一层的结构
6.文件移动及改名
mv move [移动 改名] Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY 把文件从源位置[src]移动到目标位置[dest]改名, 移动文件从原位置到目标目录 1. 移动 # mv a.txt /tmp //把文件a.txt移动到目标目录 /tmp 2. 改名 # mv a.txt a.ttxt //把文件a.txt改名为a.ttxt 3. 移动并改名 # mv /tmp/a.txt 2103.txt //把文件a.txt从/tmp移动到当前目录并改名为 2103.txt 4. 对多个文件进行移动 # mv a1.txt a2.txt a3.txt a4.txt a5.txt /tmp/ //把a1-a5.txt从当前目录移动到 /tmp 最后一个必须是目录,mv默认命令后到最后一个参数前中间的都是要移动的 5. 对多个文件和目录进行移动 # mv /tmp/1a.txt /tmp/a2.txt /tmp/a3.txt /tmp/dir /root/ 把多个文件和目录移动到/root,如果目录下有文件也会一并移动 ----- 其他 # pwd 显示当前所处的位置 . 代表当前目录 .. 代表上一级目录 reboot 重启 init 0 关机 shutdown -h now 关机 shutdown -h 10 10分钟后关机
7.文件删除
rm remove 删除 rm filename [file1 file2 file3] 删除文件 rm -f filename 删除文件且不询问 # rm -f dir1 //对于删除目录 需要加上-r参数 rm: cannot remove ‘dir1’: Is a directory # rm -rf dirname 删除目录 常用命令 # rm -rf 删除某一个目录下所有文件 -f force 强制 -r recursive 层级 删除目录和它的子文件
8.文件复制
cp copy 复制 cp src dest # 复制单个文件 # cp a.txt /tmp //将文件 a.txt 复制到目录 /tmp 下 # 复制多个文件 # cp abc1.txt abc2.txt abc3.txt abc4.txt /tmp/ //将多个文件复制到目录/tmp下 cp复制多个文件时,最后一个参数必须是目录,默认是将cp后到最后一个目录前的其他所有文件作为src,最后一个目录作为dest # 复制目录 # cp -r Video /tmp/ //复制目录Video到tmp下 [-r recursive递归 -f force强制] # cp -rf Video /tmp/ # cp -rf Video/* /tmp //复制目录video下所有文件和目录到tmp下