运行级别
运行级别配置文件,位于/etc/inittab
切换运行级别:init 5 切到图形界面
忘记root密码
不能远程修改,因为没开机;你没法远程ssh连接,此种情况是你在机房开机的时候才可以修改的,既然机子都在你手里,认为就是你的电脑可以修改密码。当然电脑被偷了,那没招了…
文件夹指令ls、cd
用的比较多,笔记简单点
pwd,显示当前所在绝对路径
ls 显示当前文件夹的内容。
ls -a 显示当前文件夹内容,包括隐藏的;
ls -l 以列表形式显示文件夹内容
ls -al 可以结合使用
cd 切换
cd /home/chenliang 切换到这个目录
cd …/ 切换到上级目录
cd ~ 切换到当前用户的home目录,root就切换到/root ,其他用户切换到/home/chenliang。这是举例
帮助指令man、help
man ls 查看ls命令用法
help ls 查看ls命令用法
目录指令mkdir、rm
创建目录:mkdir /home/dog
创建多级目录:mkdir -p /home/xxx/ddd
删除rm,rm -rf
文件指令touch
touch hello.txt 创建空文件;
touch 1.txt 2.txt 创建多个空文件;
拷贝指令cp
拷贝单个文件:cp aaa.txt aaa 拷贝aaa.txt到aaa文件夹
拷贝文件夹:cp -r test/ ok/
强制覆盖:\cp -r test/ ok/ 当目标目录下有相同文件,会提示是否覆盖,\cp会强制覆盖,不提示;
删除rm
rm -r 删除文件夹
rm -rf 删除文件夹不提示
rm 删除文件
f=force=强制
移动文件(剪切)或者重命名mv
mv aaa.txt bbb.txt 改名
mv aaa.txt /root/ 移动
命令查看文件cat、more、less
只读,查看文件无法修改,这不同于vim和vi
cat aaa.txt
cat -n aaa.txt 显示行号
cat -n aaa.txt | more 显示行号,分页显示;俺空格键切换到下一页
补充:more指令可以全屏看文件内容,不做笔记了,感觉我就用cat吧;
看日志的时候用less看,这个也是全屏显示,但是是分页加载,打开速度快;
重定向和追加>、>>
>符号表示重定向
>>符号表示追加
举例:
cd /home
ls -l > ddd.txt
把/home目录ls -l展示的列表,覆盖写入ddd.txt,如果ddd.txt不存在,则创建ddd.txt
cal >> ddd.txt
把日历图追加到ddd.txt,内容为之前的/home目录列表,和这次追加的cal;
注意>是覆盖,>>是追加
echo输出、head查看头部、tail查看尾部
echo 可以输出
echo hello world
echo $PATH
head查看文件前边的行
head /etc/profile 默认看前10
head -n 5 /etc/profile 看前5
tail 查看文件尾部的行
tail /etc/profile 默认看后10行
tail -n 5 看后5行
tail -f 实时监控
ln 软连接、history 查看历史命令
创建软连接
ln -s /root lintToRoot
删除软连接,别带斜杆
rm -rf linkToRoot
查看执行的指令历史:
history
history 10 #查看历史指令最后10条
执行第47条指令
!47
时间相关date、cal
date命令
查看系统时间
date
date "+%Y %m %d %H %M %S" #加号不能省略,其余%Y表示年,依次表示年月日 时分秒,中间可以加字符连接
date "+%Y-%m-%d %H:%M:%S"
设置时间:
date -s “2020/03/01 17:49:40”
或者 date -s “2020-03-01 17:49:40”
cal命令
cal #查看当月日历
cal 2020 # 查看2020年日历
搜索查找相关find、
find
find /root -name ddd.txt
find / -size +20M
find /root -user root
find 支持通配符;例如查找根目录下文件名问hello.开头的文件:
find / -name hello.*
locate
uodatedb
locate hello.txt
grep指令和管道符
将hello.txt文件交给grep指令处理,这是管道符的作用
参数-n:显示行号
参数-i:忽略大小写
[root@localhost home]# cat /home/hello.txt |grep -ni YES
2:yes
3:yes1111
7:yesaaa
8:YES
[root@localhost home]# cat /home/hello.txt |grep -n yes
2:yes
3:yes1111
7:yesaaa
[root@localhost home]# cat /home/hello.txt |grep -i yes
yes
yes1111
yesaaa
YES
压缩gzip、解压gunzip
[root@localhost home]# ls
chenliang hello.txt
[root@localhost home]# gzip hello.txt
[root@localhost home]# ls
chenliang hello.txt.gz
[root@localhost home]# gunzip hello.txt.gz
[root@localhost home]# ls
chenliang hello.txt
补充:可以一次性压缩多个
gzip hello.txt world.txt
压缩
tar解压缩
tar -zcvf