一、安装
授权:
GPL: 通用公共许可
Linux 安装:
1.复制iso镜像.
2.创建虚拟机.(组装)注意:安装位置
3.将镜像放入到虑拟光驱
4.开机
命令提示符: [root@localhost ~]#
[当前登录的用户@主机名 宿主目录]#
宿主目录: 存放当前用户环境变量的目录
5.关机命令: #init 0 重启#init 6
二、vim模式
vim的基本操作:
vim: 文本编辑器(word)
vim工作模式: 1)命令模式: 键盘上的所有操作都理解为vim的内部命令去执行
2)输入模式: 所有的按键操作都当作内容输入
3)末行模式:用于退出文本编辑
末行<-:--命令--i-->输入
<--ESC--
末行模式下: :w 文件名 :q! :wq :set nu
命令模式下; x 删除光标对应的字母 u 撤销 /字符 查找对应字符
dd 删除当前行 (ndd) yy复制当前行 p 粘贴
:%s/old/new/g 将全文中的old换成new
三、常用命令
不会看帮助,报错看日志
命令 [选项] [参数]
选项: 是对命令执行的要求
参数: 是命令操作的对象
选项和参数 根据需要可以不加
管理和重定向:
管道:将前面命令的输出做为后面命令的输入
[root@localhost ~]# ls /etc/ | wc -l //统计一下当前目录下有多少文件(行)
重定向:
改变系统的正常输出方向,不在屏幕显示.
> 输出重定向 [root@localhost ~]# ls /etc/ > file1 //将前面命令输出写到file1里
>> 追加重定向
[root@localhost ~]# tail -1 /etc/passwd //查看文件最后一行
[root@localhost ~]# head -1 /etc/passwd //查看文件的第一行
[root@localhost ~]# tail -1 /etc/passwd >> file1 //追加重定向,不覆盖
2> 错误重定向 可以追加错误重定向 2>>
[root@localhost mnt]# touch a //新建文件a
[root@localhost mnt]# ls
a hgfs
[root@localhost mnt]# ls a b
ls: cannot access 'b': No such file or directory
a
[root@localhost mnt]# ls a b > file1
ls: cannot access 'b': No such file or directory
[root@localhost mnt]# ls a b 2> file1
a
文件类型常用命令
1.pwd 显示当前工作目录
2.cd 切换工作目录
#cd . //一个点为当前目录 #cd .. 两个点为上级目录 没有三个点
相对路径 文件开头
绝对路径 /开头
3.ls 显示目录内容
-a 显示所有文件包括隐藏文件.
-l 以长格式显示文件 (包括权限)
-d:显示目录本身的属性
在linux中隐藏文件都是以.开头的
linux中的文件不区分后缀名
* 通配所有(不包含隐藏文件) .* 星号前加点可以显示隐藏文件
? 通配单个字符
4.alias 定义别名
[root@localhost mnt]# alias aa="ls -al" 定义别名aa 相当于把ls -al的功能给了aa
5.mkdir 创建新目录
-p 递归创建目录
# mkdir -p /a/a1/a2
6.du 统计文件大小
wc 可以显示文件的行数、字数和字节数
-h 以人性化的方式显示文件大小
-s 显示当前对象的总体大小
[root@localhost mnt]# du /etc/ -sh
30M /etc/
[root@localhost mnt]# du /etc/ -h
7.touch 新建文件,以及更新文件时间.
NTP: 网络时钟服务器 用于统一所有设备的时间
LDAP: 轻量级目录服务 允许组织创建和管理自己的目录
8.file 查看文件类型
[root@localhost mnt]# tar zcvf test.tar.gz /etc 创建压缩文件
root@localhost mnt]# file test.tar.gz
test.tar.gz: gzip compressed data, last modified: Tue Mar 12 18:48:48 2024, from Unix, original size -952842816
[root@localhost mnt]# file a
a: empty //a:空的
[root@localhost mnt]# file /mnt
/mnt: directory //mnt:目录文件
9.cp 复制文件及目录
[root@localhost mnt]# ls
a aa b c d file1 hgfs test.tar.gz
[root@localhost mnt]# cp a file2
[root@localhost mnt]# ls
a aa b c d file1 file2 hgfs test.tar.gz
[root@localhost mnt]# cp aa bb //aa为目录
cp: -r not specified; omitting directory 'aa'
[root@localhost mnt]# cp -r aa bb
[root@localhost mnt]# ls
a aa b bb c d file1 file2 hgfs test.tar.gz //aa bb 为目录
10.rm 删除文件或者目录
[root@localhost mnt]# ls
a aa b bb c d file1 file2 hgfs test.tar.gz
[root@localhost mnt]# rm a
rm: remove regular empty file 'a'? y
[root@localhost mnt]# rm -f b
[root@localhost mnt]# rm aa
rm: cannot remove 'aa': Is a directory
[root@localhost mnt]# rm -f aa
rm: cannot remove 'aa': Is a directory
[root@localhost mnt]# rm -rf aa
[root@localhost mnt]# ls
bb c d file1 file2 hgfs test.tar.gz
11.mv 移动文件或者目录
相当于剪切
mv 源文件 目标目录
[root@localhost mnt]# ls
bb file1 file2 hgfs test.tar.gz
[root@localhost mnt]# mv file1 file3
[root@localhost mnt]# ls
bb file2 file3 hgfs test.tar.gz
[root@localhost mnt]# mv bb aa
[root@localhost mnt]# ls
aa file2 file3 hgfs test.tar.gz
[root@localhost mnt]#
12.ln 为文件或目录建立链接(Link)
-s 创建软链接 不可以对目录,删除源文件会出现报错,文件名变成红色
不带-s选项创建硬链接,于复制相同,删除源文件不会受到影响。
[root@localhost mnt]# ln file2 a
[root@localhost mnt]# ls -l
total 4612
-rw-r--r--. 2 root root 0 Mar 12 14:52 a //硬链接
-rw-r--r--. 2 root root 0 Mar 12 14:52 file2
[root@localhost mnt]# ln -s file2 b
[root@localhost mnt]# ls -l
total 4612
-rw-r--r--. 2 root root 0 Mar 12 14:52 a
lrwxrwxrwx. 1 root root 5 Mar 12 15:43 b -> file2 //软链接
-rw-r--r--. 2 root root 0 Mar 12 14:52 file2
[root@localhost mnt]# rm -f file2
[root@localhost mnt]# ls -l
total 4612
-rw-r--r--. 1 root root 0 Mar 12 14:52 a //不受影响
lrwxrwxrwx. 1 root root 5 Mar 12 15:43 b -> file2 //警告提示
四、文件内容命令
1.cat 查看文件内容
[root@localhost ~]# cat /etc/passwd
2.more 全屏方式 分页显示内容
less 分屏方式分页显示内容,可往回翻页
[root@localhost ~]# less /etc/passwd //按q退出
[root@localhost ~]# more /etc/passwd
3.head 查看文件的开头内容(默认前10行)
-n 显示前n行
[root@localhost ~]# head /etc/passwd
[root@localhost ~]# head -1 /etc/passwd
4.tail 查看文件的结尾部分内容(默认最后10行)
-n 显示后n行
-f 实时跟踪文件
[root@localhost ~]# tail /etc/passwd
[root@localhost ~]# tail -2 /etc/passwd[root@localhost ~]# tail -f /etc/passwd 实时跟踪文件,然后再打开一个新终端运下命令
例:[root@localhost ~]# tail -f /var/log/messages
[root@localhost ~]# systemctl restart sshd //在另一个终端,输入命令打开服务
按ctrl + c 结束跟踪
按ctrl + shift + t 打开新终端
5.grep 在文件中查找并显示包含指定字符串的行
-i 不区分大小写
-v 反转查找
“^……”表示以……开头,“……$”表示以……结尾 “^$”表示空行
[root@localhost ~]# grep is /usr/share/doc/diffutils/NEWS | grep -iv ^user |grep -v "^$" >/root/file1
6.归档及压缩文件
tar命令 :
.gz : 压缩 #tar zcvf 压缩后的文件名 需要被压缩目录
解压 #tar zxvf 需要被解压的文件 -C 指定解压后的路径
.bz2 : 压缩 #tar jcvf 压缩后的文件名 需要被压缩目录
解压 #tar jxvf 需要被解压的文件 -C 指定解压后的路径
[root@localhost mnt]# tar zcvf etc.tar.gz /etc
[root@localhost mnt]# file etc.tar.gz
[root@localhost mnt]# tar jcvf etc.tar.bz2 /etc
[root@localhost mnt]# file etc.tar.bz2
[root@localhost mnt]# tar jxvf etc.tar.bz2 -C /media/
[root@localhost mnt]# tar zxvf etc.tar.gz -C /media/