Linux自学总结
1. 改变目录
cd /home 跳转到根目录home文件夹下
ls 当前目录信息
ll 当前目录详情
2.创建文件
touch /home/add 在根目录home文件夹下创建add文件
3.创建文件夹
mkdir /home/add 在根目录home文件夹下创建add文件夹
mkdir -p /home/add/add/add/add 当创建的目录没有上一级时,自动创建
4.复制
cp /home/add /home/other 复制add到home的other
cp -r /home/add /home/other add下如果存在多个文件 -r 递归都复制
5.移动
mv /home/add /home/other 移动add到home的other
mv /home/add /home/other 移动add到home改名为other
6.删除
rm -rf /home/add 删除home下的add
rm -rf /home/add* 删除home的匹配add的文件
7.查看
cat /1.txt 查看1.txt的文件
head -3 /1.txt 只看文件头前3行
head -6 /1.txt 只看文件头前6行
tail -3 /1.txt 只看文件后3行
more /1.txt 回车(下一行)/空格(翻页)可以查看其余内容
grep c /1.txt 查询关键词c
8.修改
ls -a > /list.txt 把目录下的结果 输入到 list.txt
cat /1.txt > /2.txt 把查看1.txt的结果输入到2.txt
gedit /1.txt 打开记事本进行修改
gedit /3.txt 如果文件不存在则创建txt文件
< VIM >
vim /1.txt 按i(o a 插入位置不同)进入编辑模式,编辑后esc返回命令行模式:wq退出编程
按yy复制p黏贴,d删除代码,u之前的操作,x删除当前的字。
:q! 退出没有提示
:set nu 设置行号
:set nonu 取消设置行号
:set list 设置控制字符
:set nolist 取消设置控制字符
v 进入可视化
y选取复制
p 黏贴
shift g回到最后一行
g回到第一行
输入:/admin(要搜索的内容) 回车 就是搜索 n就匹配搜索的结果
查找替换:
1,5 s/111/2222/g 从1-5行的 111替换成2222
另存为文件:
:w /另存为的文件的名字.txt
当文件存在临时文件时候,
ls -a / 查看文件
使用rm -rf删除
相对路径、绝对路径
绝对路径:cd 根/home/abc/1.txt
相对路径: cd ./abc
mkdir /home/{dir111,dir222} 在home下面创建目录dir111和dir222
mkdir -pv /home/{qiangfeng/{dir1,11},nizhan} pv(递归创建加显示结果)
创建目录 /home/qiangfeng /home/qiangfeng/dir1 /home/qianfeng/11 /home/nizhan
root:ZlVgS/... : : 0 : 99999 : 7 : : :
1 2 3 4 5 6 7 8 9
1:用户名
2:密码加密值
3:最后一次修改时间
4.最小的间隔(0代表当天可以改密码)
5.密码最大的时间间隔,9999无限期
6.警告时间(7天) 在5选项里面的时间内警告你
7:不活动时间(28,用户不等了系统,超过28禁用你)
8:失效时间(30,到了30天,你的账号就不能用了。)
9.??
9.创建用户
useradd user01 添加user01这个账号
id user02 查看是否有user02这个账号
10.修改用户
passwd user01 设置user01的密码
新的密码:(输入内容回车)
whoami (查看当前的用户是谁)
user01@localhost ~ touch 1.txt (文件在home的user01用户下面)
useradd user02 -u 1504 //创建用户user02 指定uid为1504
useradd user03 -d /user03 //创建用户user03 指定加目录,进入user03的账户后,根目录为/user03useradd userdel -r user03 //删除user03和目录
usermod -s /sbin/nologin niuniu //修改牛牛这个用户的属性,设置不能登录
11.修改用户组
groupadd group1 //添加group1用户组
groupadd net -g 2000 //添加net用户组 并制定 ip为 2000
groupdel jr //删除jr 用户组
cat /etc/group //查看组的列表
su - root //切换到root 输入密码登录成功,exit退出账号
useradd xulei -g wheel 创建提权账号
sudo useradd tst1 //提权输入密码后 创建成功
sudo userdel tst1 //提权加sudo删除成功
12.用户权限
chmod u+r 1.txt
命令 对象加减权限 文件或者目录
对象(u/g/o/a)赋值符号(+/-/=)权限类型(r/W/x)
u用户 g组 o其他 r4读 w2写 x1执行
[root@localhost tmp]# ls -l
总用量 0
drwxr-xr-x. 2 root root 6 9月 2 11:35 dir1
-rw-r--r--. 1 root root 0 9月 2 11:33 file1
1 2 3 4 5 6 7
1: -rw- r-- r--
属主 属于组 其他人
rwx rwx rwx
u g o
2:链接
3:属主
4:属组
5:大小
6:创建时间
7:文件名
chmod a=rx file1 //让文件夹file1 all 都有 rx的权限
chmod u=r file // 给予file授予,属主读,读的权利,没有写和执行
chmod g=rwx file1 //给予file授予,属组读,写和执行的权限
chmod 0-rwx file1 //给予file授予,属其他用户,没有读写和执行的权限
创建 file1.txt文件内容如下
echo "hello world"
read -p "please input name:" name
echo "haha $name dabenda"
chmod u+x file1.txt //给予file授予,属其他用户,没有读写和执行的权限
执行:./file1.txt
hello world
please input name:erdan
系统输出:haha erdan dabenda
数字授权:
chmod 760 file1.txt //用户读写执行,组读写,其他无
chmod 777 fle1.txt //用户读写执行,组写执行,其他读写执行
chmod 007 fle1.txt //用户无,组无,其他读写执行
groupadd hr 创建hr这个组
chown aaa.hr /tmp/file1.txt //修改file.txt这个文件的主人为 aaa和hr
drwxr-xr-x. 2 root root 6 9月 2 11:35 dir1
-rw-r--r--. 1 aaa hr 81 9月 2 16:29 file1.txt
setfacl -m u:alice:rwx file1.txt //给alice授予 file1.txt的 rwx权限
setfacl -m O::rw file1.txt //给其他other授予 file1.txt的 rw权限
getfacl /home/test.txt
查看test.txt的权限
setfacl -x u:alice file1.txt //删除alice的file1.txt的权限
setfacl -b file1.txt//删除file1.txt的所有ACL权限
watch -n1 'ls -1 /home/test.txt' //每个一秒监控 test.txt的文件
13.进程管理
ps //查看当前进程
ps aux(axu) | grep vim
root 45969 0.1 0.5 151796 5368 pts/0 S+ 17:48 0:00 vim file1.txt
root 45994 0.0 0.0 112676 984 pts/2 R+ 17:48 0:00 grep --color=auto vim
ps aux --sort %cpu //排序查看cpu的进程
ps -ef //查看进程的父子关系pid ppid 不能关闭的程序可以找父进程进行关闭
top
1.top - 13:54:14 up 1:24, 3 users, load average: 0.01, 0.08, 0.24
2.Tasks: 177 total, 2 running, 175 sleeping, 0 stopped, 0 zombie
3.%Cpu(s): 19.1 us, 4.2 sy, 0.0 ni, 76.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
4.KiB Mem : 999696 total, 318120 free, 326048 used, 355528 buff/cache
5.KiB Swap: 2097148 total, 1639028 free, 458120 used. 474580 avail Mem
一:top - 13:54:14 up1:24, 3 users, load average: 0.01, 0.08, 0.24
程序名 -系统时间 运行时间 登录用户数 cpu 负载均衡 1分钟内 10分钟内 15内
二:Tasks: 177 total, 2 running, 175 sleeping, 0 stopped, 0 zombie
总进程数 行数 睡眠数 停止数0 僵死数
三:%Cpu(s): 19.1 us, 4.2 sy, 0.0 ni, 76.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
cpu使用占比 us用户 system系统 ni优先级 id空闲 wa等待 hi硬件 si软件 st虚拟机
四:KiB Mem : 999696 total, 318120 free, 326048 used, 355528 buff/cache
物理内存K 总共0.9G(给的1G) free空闲 0.3G userd使用0.3g cache缓存硬盘内容0.33g
五:KiB Swap: 2097148 total, 1639028 free, 458120 used. 474580 avail Mem
(交换分区)虚拟内存k 1.9g 1.5G 0.4g 0.4G
top -d 1 //每一秒刷新
top -d 1 -p 10126 //查看指定进程的
top -d 1 -p 10126,1 //查看10126和1进程的
ps auv | grep vim //查看vim进程的list
top -d 1 -p 16711 //用list下面的pid,在查出16711的进程详情
kill -15 加pid // 正常退出
kill -9 加pid //最好别使用 内存删除 杀死
14.硬盘管理
ll /dev/sd* //展示对应的磁盘
lsblk //以树状列出所有块设备
1.fdisk /dev/sdb
2.n (开始分区)
3.p (主分区)
4.分区号选择1
5.敲回去
6.W(回写)
7.partprobe /dev/sdb 或者lsblk查看
持续更新中