Linux学习笔记

1 科普知识

  • 操作系统的作用:向下控制硬件向上支持软件

  • 虚拟机软件:它是能够虚拟取出来计算机的一个软件

2 CentOS系统 (GNU)

  • ubuntu操作系统是属于Linux操作系统的一种 是linux的发行版本

  • linux系统中:

    • 有一个总的目录<根目录 />

    • home目录:用户的家目录

      在linux在 ctrl + shift 是复制
  • 快捷键

    ctrl + c            停止进程
    ctrl + l            清屏,等同于clear
    善用tab 键           提示(更重要的是防止敲错)
    上下键               查找执行过的命令  

Xshell的使用

Xshell的配置和使用:
.配置Xshell的基本属性,例如:改变配色方案New White,放大字体,配置工具中鼠标和键盘的快捷键

在Xshell中 使用输入 指令rz 可以打开本地文件 指令sz是导出文件

下载tree

yum install tree #下载树
​
tree /root #显示root目录层次
​
​
[root@hadoop100 ~]# tree /root
/root
├── 2.cfg
├── anaconda-ks.cfg
├── b
├── c
├── foler
│   └── file
├── info
├── myboot.zip
├── temp.tar.gz
├── \345\205\254\345\205\261
│   └── info
├── \346\250\241\346\235\277
├── \350\247\206\351\242\221
├── \345\233\276\347\211\207
├── \346\226\207\346\241\243
├── \344\270\213\350\275\275
├── \351\237\263\344\271\220
└── \346\241\214\351\235\242
    ├── in
    └── initial-setup-ks.cfg
​

3.linux命令

windows是  看ip地址 ipconfig
linux是    看ip地址 ifconfig
​
1. 文件/目录相关
​
   1.ls 列出当前文件夹下的内容
​
   2.pwd 查看当前所在目录
​
   3.cd 切换目录
   . 当前目录 .. 上级目录 cd ~ 切换到主目录 cd - 在最近两次操作目录间横跳
   4.touch 创建文件
​
   5.mkdir 新建目录
​
   6.rm 删除文件
   rm -r 目录名 删除目录 rm -f 强制删除,无该文件也无需提醒 rm -r * 删除当前目录下所有文件和目录
​
   7.cp 复制文件
​
   8.mv 移动文件
​
2. 文件内容相关
​
   1.grep 搜索文本 文件名 搜索文本内容
   -n 显示行号; -v 不包括该内容的 ; ^a查找以a开头的行; a$ 查找以a结尾的行
​
   2.cat 显示文件完整内容
​
   3.more 分屏显示文件内容
​
   4.less 分屏显示文件内容,上下键控制翻页
​
   5.head 打印文件中的前n行
​
   6.tail 打印文件中的末尾几行
   **显示10~15行内容** tail 文件名 +10| head +5
​
   7.find
   `find 目录 -name 搜索字符` 搜索名字为xxx的文件 可以使用通配符
   `find 目录 -size 数据块` 搜索大小为xxx的文件,1数据块=0.5kB
   +n 大于 -n 小于 n等于
   组合条件:-o 或者;-a 并且
   find \ -size +163840 -a -size -204800 查找根目录下大于80MB小于100MB的文件
   `find 目录 -group xxx` 查询所属组为xxx的文件
   `find 目录 -user xxx` 查询所属者为xxx的文件 
​
   8.wc
   wc 文件 -l 统计文件的行数
   wc 文件 -w 统计文件的单词数
   wc 文件 -c 统计文件的字节数
​
3. 进程与内存相关
​
   1.top 动态实时显示cpu、内存、进程使用情况
​
   2.ps 列出进程
   ps -ef | grep xxx 查看xx进程,可以获得pid
   ps -a 列出所有运行中的进程
   pgrep -l xxx 查看xx进程的pid
   netstat -atnp| grep xxx 查询pid
​
   3.kill 杀死进程
   kill -9 pid 强制杀死某进程
​
   4.netstat
   netstat -atnp | grep xxxx 查看端口号/状态的进程pid
   查看端口占用情况 lsof -i
   查看指定端口占用情况 lsof -i:端口号
​
   5.free 显示当前内存使用情况
​
   6.df 以字节形式显示磁盘使用情况

4.Linux目录

bin 是存放直接可以使用的命令
sbin 存放的是系统管理员可以使用的命令
lib  库目录
lib64  64位相关的库目录
usr  存放用户的所用的数据
boot 存在启动的时候所需要的文件
dev  设备目录,管理设备的
etc  系统管理所需要的配置文件
home 每一个普通用户的主目录的
root 超级管理员的目录
opt  可选目录,就是当前linux 给第三方软件包的目录
media 识别可移动的媒体设备,挂载点
mnt   另外一个media目录,挂载点
proc  进程目录
run   运行目录,当前系统运行以后的所有信息
srv   service跟系统服务相关的东西
sys   系统硬件信息的相关文件
tmp   临时目录
var   可变目录,存放不断变化的文件,一般放日志

5.文件编辑器

vi/vim 是什么

VI是Unix操作系统和类Unix操作系统中最通常的文件编辑器
VIM编辑器是从VI发展出来的一个性能更强大的文件编辑器。可以主动的以字体颜色辨别语法的正确性,方便程序设计.VIM和VI编辑器完全兼容

测试数据准备

拷贝/etc/profile 数据到/root 目录下

cp /etc/profile/root
cd /root/

1.普通模式操作

vim/vi 文本名字 #进行文件
输入 i 进入编辑模式
按 Esc 退出编辑模式
按 u 进行回退到
输入 : 进入命令模式
:w #把更改的操作进行保存
:q #退出文件
​
yy光标放置的行进行复制,按p用来对yy复制的进行粘贴
8yy 复制光标下来的八行,按p用来对yy复制的进行粘贴
​
dd 对光标放置的行进行删除
8dd 对光标放置的8行进行删除
​
y$ 对光标开始的最后一个的一行进行复制
y^ 对光标之前的所有字符的一行进行复制
​
d$ 对光标开始的最后一个的一行进行复制
d^ 对光标之前的所有字符的一行进行复制
​
yw 复制一个词
dw 删除一个词
​
s 删除一个词
​
shift + u 进行替换
​
shift + $ 当前行的行头
shift + ^ 当前行的行位
​
w 当前词的词头
e 当前词的词尾
b 上一个词的词头
​
gg 回到文档的开头
GG 回到文档的结尾
4GG 到第四行
​
:set nu 显示行的编号
:set nonu 不显示行编号

shift + 行数 + gg 跳转到对应的行

2.插入模式

按 i 进入插入模式 当前光标前
a   当前光标后
o   当前光标行的下一行
I   当前所在行最前
A   光标所在行最后
O   当前光标行的上一行

3.命令模式

:set nu 显示行的编号
:set nonu 不显示行编号
:q 退出文档
:wq 保存并退出
:q! 不保存直接退出
/要查找的词  n 查找下一个 N 往上查找
:noh    取消高亮显示
:s/old/new  替换当前行匹配到的第一行old为new
:s/old/new/g    替换当前第一行匹配到的所有old为new
:%s/old/new     替换文档中每一行匹配到的第一个old为new
:%s/old/new/g   替换文档中匹配到的所有old为new

6.网络配置和系统管理操作

DHCP动态分配ip地址
​
VMware 提供了三种网络连接模式
​
桥接模式
虚拟机直接连接外部物理网络模式,主机起到了网桥的作用。这种模式下,虚拟机可以直接访问外部网络,并对外部网络是可见的
​
NAT模式
虚拟机和主机构建了一个专用的网络,并通过虚拟网络地址转换(NAT)设备对IP进行转换。虚拟机通过共享主机IP可以访问外部网络,但外部网络无法访问虚拟机
​
主机模式
虚拟机只与主机共享一个专用网络,与外部网络无法通信

1)查看虚拟网络编辑器

2)看主机和虚拟机是否ping通

1.主机ping虚拟机

用ifconfig 查看虚拟机的ip地址
ens33
eth0 都为网卡名

2.虚拟机ping主机

修改静态ip

# vim /etc/sysconfig/network-scripts/ifcfg-ens33 

修改完后重启启动服务

# service network restart

修改主机名

1先在虚拟机中修改

2.在主机中修改

3.修改host文件

修改完后再替换掉主机etc目录下的host文件

7.远程登录

输入ssh root@hadoop100
再输入yes
再输入密码即可
​
输入 #exit 退出系统

使用Xshell可以直接远程登录

Xftp 7 可以远程传输文件

8.系统管理

Linux中的进程和服务

计算机中,一个正在执行的的程序或者命令,被叫做"进程"(process)
启动之后一只存在、常驻内存的进程,一般被称作为"服务"(service)

service 服务管理(CentOS 6 版本-了解)

基本语法
service 服务名 start|stop|restart|status

systemctl(CentOS 7 版本-重点掌握)

systemctl restart network
​
查看服务的方法:/usr/lib/systemd/system
​
输入setup 可以直接进入图形化配置界面,自己开关服务

用图形界面来开关服务

关机重启命令

shutdown 一分钟后关机
shutdown -c 取消关机
shutdown now 立刻关机
shutdown 15:28 在15:28分关机

9.Linux命令

帮助命令

9.1.1 man 获得帮助信息

1)基本语句

man [命令或者配置文件] (功能描述:获得帮助信息)
​
可以先用type 判断它 是否为内置命令
如果不是在用 man 命令
​
eg:    man ls

9.1.2 help获取shell内置命令的帮助信息

1)基本语法

help 命令 (功能描述:获取shell的内置命令的帮助信息)

9.1.3 type 用来判断命令是否为内置命令

1)基本语法

type 命令

文件目录类

9.2.1 pwd 显示当前工作目录的绝对路径

1)基本语法

pwd         (功能描述:显示当前工作目录的绝对路径)
​
pwd -P      抛开软链接,直接显示真实链接

9.2.2 cd命令

cd /root/桌面/        绝对路径
cd ../视频            相对路径   ../表示返回上一层目录
cd -                 返回上一次的目录
cd                   直接回到主文件夹
cd ..                返回上一级

9.2.3 ls命令

ls -a       全部的文件,连同隐藏档(开头为.的文件) 一起列出来(常用)
ls -l       长数据串列出,包含文件的属性与权限等等数据  等于 ll
ls -i 文件   查看文件的索引
ls -lh      显示文件的大小

9.2.4 mkdir 创建一个新的目录

mkdir [选项] 要创建的目录
​
[root@hadoop100 ~]# mkdir a
[root@hadoop100 ~]# ls
a  anaconda-ks.cfg  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面
​
[root@hadoop100 ~]# mkdir b c   直接生成两个目录
[root@hadoop100 ~]# ls
a  anaconda-ks.cfg  b  c  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面

9.2.5 rmdir 删除一个空的目录

rmdir  要删除的空目录
​
[root@hadoop100 ~]# rmdir b
[root@hadoop100 ~]# ls
a  anaconda-ks.cfg  c  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面
​
​

9.2.6 touch 创建空文件

touch  文件名称     可以不带后缀 
​
root@hadoop100 ~]# touch hello
[root@hadoop100 ~]# ls
a  anaconda-ks.cfg  c  hello  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@hadoop100 ~]# vim hello
​
vim hello4  可以直接创建文件,但是不能创建空文件    可以创建后然直接输入  :wq 保存退出
​

9.2.7 cp 复制文件或者目录

cp 文件 复制到的地址
​
复制文件  cp initial-setup-ks.cfg /home/yling/hello          #如果存在这个是直接覆盖该文件
                                                            如果不是相当于复制到并重命名
​
[root@hadoop100 ~]# cp initial-setup-ks.cfg /home/yling/hello
[root@hadoop100 ~]# ls /home/yling
hello  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面
​
cp -r 目录 复制到的地址
​
复制目录 cp -r a /home/yling    
​
[root@hadoop100 ~]# mkdir b
[root@hadoop100 ~]# cp initial-setup-ks.cfg a
[root@hadoop100 ~]# cp -r a /home/yling
[root@hadoop100 ~]# ls /home/yling
a  hello  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@hadoop100 ~]# ls /home/yling/a
initial-setup-ks.cfg
​

9.2.8 rm删除文件或者目录

rm [选项]
​
删除文件   rm sdsd
​
[root@hadoop100 ~]# ls
a  anaconda-ks.cfg  b  c  initial-setup-ks.cfg  sdsd  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@hadoop100 ~]# rm sdsd
rm:是否删除普通空文件 "sdsd"?y
​
删除目录
​
rm -f 文件        强制删除
​
[root@hadoop100 ~]# touch sjdjsj
[root@hadoop100 ~]# rm -f sjdjsj
​
rm -r 目录        删除目录
[root@hadoop100 ~]# rm -r a
rm:是否进入目录"a"? y
rm:是否删除普通文件 "a/initial-setup-ks.cfg"?y
rm:是否删除目录 "a"?y
​
​
rm -rf 目录       直接强制删除
​
rm -rf /*       直接删库,删除根目录下的所有东西
​
​

9.2.9 mv 移动文件和目录或重命名

重命名   mv initial-setup-ks.cfg  2.cfg   直接将文件重命名
​
[root@hadoop100 ~]# ls
anaconda-ks.cfg  b  c  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@hadoop100 ~]# mv initial-setup-ks.cfg 2.cfg
[root@hadoop100 ~]# ls
2.cfg  anaconda-ks.cfg  b  c  公共  模板  视频  图片  文档  下载  音乐  桌面
​
mv 文件  移动到的目录
​
移动文件  mv initial-setup-ks.cfg /home/yling
​
anaconda-ks.cfg  b  c  initial-setup-ks.cfg  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@hadoop100 ~]# mv initial-setup-ks.cfg /home/yling
mv:是否覆盖"/home/yling/initial-setup-ks.cfg"? y
​

9.2.10 cat 查看文件内容

cat [选项] 想要查看的文件
cat -n 选项   显示所有行和行号,包括空行

9.2.11 more 文件内容分屏查看器

more 要查看的文件
​
按q 直接退出查看

9.2.12 less 分屏显示文件内容

less 要查看的文件

9.2.13 echo

echo 输出内容到控制台
​
echo [选项][输入内容]
​
[root@hadoop100 ~]# echo hello,world
hello,world
​
[root@hadoop100 ~]# echo "helllo     world"       用字符串形式的可以直接输出空格
helllo     world
​
​
​
-e为转义字符
[root@hadoop100 ~]# echo -e "helllo\nsdsdsd"    用-e转义字符,使用\n可以将数据换行输出
helllo
sdsdsd
​

ls -l > 文件 (功能描述:列表的内容写入文件a.txt中(覆盖写))
ls -al >> 文件(功能描述:列表的内容追加到文件a.txt的末尾)
cat 文件1 > 文件2 (功能描述:将文件1的内容覆盖到文件2)
echo "内容" >> 文件 (功能描述:将文件1的内容追加到文件2)
​
​
[root@hadoop100 ~]# ll > info
[root@hadoop100 ~]# ls
2.cfg  anaconda-ks.cfg  b  c  info  公共  模板  视频  图片  文档  下载  音乐  桌面
[root@hadoop100 ~]# cat info
总用量 8
-rw-r--r--. 1 root root 1767 7月  18 21:41 2.cfg
-rw-------. 1 root root 1683 7月  17 18:15 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 7月  18 21:35 b
drwxr-xr-x. 2 root root    6 7月  18 21:13 c
-rw-r--r--. 1 root root    0 7月  18 22:00 info
drwxr-xr-x. 2 root root    6 7月  17 18:54 公共
drwxr-xr-x. 2 root root    6 7月  17 18:54 模板
drwxr-xr-x. 2 root root    6 7月  17 18:54 视频
drwxr-xr-x. 2 root root    6 7月  17 18:54 图片
drwxr-xr-x. 2 root root    6 7月  17 18:54 文档
drwxr-xr-x. 2 root root    6 7月  17 18:54 下载
drwxr-xr-x. 2 root root    6 7月  17 18:54 音乐
drwxr-xr-x. 2 root root   44 7月  17 19:04 桌面
[root@hadoop100 ~]# echo "sdkskd" >> info
[root@hadoop100 ~]# cat info
总用量 8
-rw-r--r--. 1 root root 1767 7月  18 21:41 2.cfg
-rw-------. 1 root root 1683 7月  17 18:15 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 7月  18 21:35 b
drwxr-xr-x. 2 root root    6 7月  18 21:13 c
-rw-r--r--. 1 root root    0 7月  18 22:00 info
drwxr-xr-x. 2 root root    6 7月  17 18:54 公共
drwxr-xr-x. 2 root root    6 7月  17 18:54 模板
drwxr-xr-x. 2 root root    6 7月  17 18:54 视频
drwxr-xr-x. 2 root root    6 7月  17 18:54 图片
drwxr-xr-x. 2 root root    6 7月  17 18:54 文档
drwxr-xr-x. 2 root root    6 7月  17 18:54 下载
drwxr-xr-x. 2 root root    6 7月  17 18:54 音乐
drwxr-xr-x. 2 root root   44 7月  17 19:04 桌面
sdkskd
​

9.2.14 head 显示文件头部内容

head 文件 (功能描述:查看文件头的10行内容)
​
head -n 5 文件    (功能描述:查看文件头5行内容,5可以是任意行数)

9.2.15 tail 显示文件尾部内容

tail 文件     (功能描述:查看文件尾部10行内容)
tail -n 5 文件  (功能描述:查看文件尾部5行内容,5可以是任意行数)
tail -f 文件   (功能描述:实时追踪该文档的所有更新)
​
tail -f 文件 实现对日志的实时监控

9.2.16 >输出重定向和 >>追加

ls -l > 文件 (功能描述:列表的内容写入文件a.txt中(覆盖写))
ls -al >> 文件(功能描述:列表的内容追加到文件a.txt的末尾)
cat 文件1 > 文件2 (功能描述:将文件1的内容覆盖到文件2)
echo "内容" >> 文件 (功能描述:将文件1的内容追加到文件2)

9.2.17 ln 软链接

软链接也称为符号链接,类似于windows里的快捷方式,有自己的数据块,主要存放了链接其他文件的路口

ln -s  [原文件或目录][软链接名]  (功能描述:给原文件创建一个软链接)
​
[root@hadoop100 ~]# cd /home/yling
[root@hadoop100 yling]# ln -s /root/info myInfo
[root@hadoop100 yling]# ls
a  hello  initial-setup-ks.cfg  myInfo  公共  模板  视频  图片  文档  下载  音乐  桌面
​

9.2.18 删除软链接

rm -rf 软链接名
rm -rf 软链接名/                       这个相当于删除原文件 但是不会删除软链接,但是软链接已经失效了
​

9.2.19 history查看已经执行过的历史命令

1)基础语法
history         (功能描述:查看已经执行过历史命令)
​
[root@hadoop100 myFile]# history
​
[root@hadoop100 myFile]# history 10      过去的十条命令
​
[root@hadoop100 myFile]# history -c     删除过去的历史命令
​
​
set +o history  #设置操作命令不记录进日志

时间日期类

9.3.1 date 显示当前时间

date
​
[root@hadoop100 myFile]# date
2022年 07月 18日 星期一 23:12:01 CST
​
​
date +%Y     (功能描述:显示当前年份)
​
date +%m     (功能描述:显示当前月份)
​
date +%d     (功能描述:显示当前是哪一天)
​
date "+%Y-%m-%d%H:%M:%S"  (功能描述:显示年月日时分秒)
​
​
[root@hadoop100 myFile]# date +%Y
2022
[root@hadoop100 myFile]# date +%m             
07
[root@hadoop100 myFile]# date +%d             
18
[root@hadoop100 myFile]# date "+%Y-%m-%d %H:%M:%S"
2022-07-18 23:17:18
​

9.3.2 date显示非当前时间

date -d '1 days ago'    (功能描述:显示前一天时间)
date -d '-1 days ago'   (功能描述:显示明天时间)
​
​
[root@hadoop100 myFile]# date -d '1 days ago'
2022年 07月 17日 星期日 23:20:22 CST
[root@hadoop100 myFile]# date -d '-1 days ago'
2022年 07月 19日 星期二 23:20:33 CST
​
​
[root@hadoop100 ~]# date -d "1 hours ago"
2022年 07月 19日 星期二 11:51:19 CST
​

9.3.3 date设置系统时间

date -s   字符串时间  
​
如 date -s "2017-06-19 20:52:18"
  直接设置更改系统时间
​
hwclock -s   #通过硬件时钟配置系统时间
​

9.3.4 cal查看日历

[root@hadoop100 myFile]# cal
      七月 2022     
日 一 二 三 四 五 六
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
​
​
[root@hadoop100 myFile]# cal -3         #查看三月的日历
      六月 2022             七月 2022             八月 2022     
日 一 二 三 四 五 六  日 一 二 三 四 五 六  日 一 二 三 四 五 六
          1  2  3  4                  1  2      1  2  3  4  5  6
 5  6  7  8  9 10 11   3  4  5  6  7  8  9   7  8  9 10 11 12 13
12 13 14 15 16 17 18  10 11 12 13 14 15 16  14 15 16 17 18 19 20
19 20 21 22 23 24 25  17 18 19 20 21 22 23  21 22 23 24 25 26 27
26 27 28 29 30        24 25 26 27 28 29 30  28 29 30 31         
                      31      
​
​
[root@hadoop100 myFile]# cal -m      #把星期一放到第一天
      七月 2022     
一 二 三 四 五 六 日
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
​

用户管理命令

9.4.1 useradd 添加新用户

useradd 用户名          (功能描述:添加新用户)
useradd -g 组名 用户名   (功能描述:添加新用户到某个组)
​
[root@hadoop100 ~]# useradd yangzl1
[root@hadoop100 ~]# ls /home/
yangzl1  yling
​
​
对用户名进行重命名
mv yangzll yangzlll
​
[root@hadoop100 home]# ls
yangzl1  yling
[root@hadoop100 home]# mv yangzl1 yangzlll
[root@hadoop100 home]# ls
yangzlll  yling
​

9.4.4 passwd设置用户密码

修改用户密码
passwd tony
​
[root@hadoop100 home]# passwd tony
更改用户 tony 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
抱歉,密码不匹配。
新的 密码:
无效的密码: 密码未通过字典检查 - 过于简单化/系统化
重新输入新的 密码:
抱歉,密码不匹配。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

9.4.3 id查看用户是否存在

[root@hadoop100 ~]# id tony
uid=1002(tony) gid=1002(tony) 组=1002(tony)
#uid 是userid 
#gid 是用户组id
#组  

9.4.4 cat /etc/passwd 查看创建了哪些用户

[root@hadoop100 ~]# cat /etc/passwd

可以直接修改uid

这些用户是单独创建出来,用来运行相应的系统用户 (称为伪用户)

9.4.5 su切换用户

su 用户名


切换到yling用户
[root@hadoop100 ~]# su yling
[yling@hadoop100 root]$ cd
[yling@hadoop100 ~]$ pwd
/home/yling

切换到root
[root@hadoop100 ~]# su yling
[yling@hadoop100 root]$ su root
密码:
[root@hadoop100 ~]# 

9.4.6 who查看登录用户信息

显示最外层的用户
[root@hadoop100 ~]# who am i
root     pts/0        2022-07-19 21:18 (192.168.203.1)
​
显示当前用户
[root@hadoop100 ~]# su yling
[yling@hadoop100 root]$ who am i
root     pts/0        2022-07-19 21:18 (192.168.203.1)
[yling@hadoop100 root]$ whoami
yling

9.4.7 userdel 删除用户

9.4.8 sudo 设置普通用户具有root权限

#现在sudoers文件下配置权限
[root@hadoop100 ~]# vim /etc/sudoers

修改完后输入wq! 强制修改保存退出

接下来使用sudo命令来赋予管理员权限
​
​
[root@hadoop100 ~]# su tiny
[tiny@hadoop100 root]$ sudo ls
[sudo] tiny 的密码:
2.cfg  anaconda-ks.cfg  b  c  foler  info  公共  模板  视频  图片  文档  下载  音乐  桌面
​

9.4.9 userdel删除用户

删除用户,但是用户的文件夹还是会存在,但是没有数据了
[root@hadoop100 ~]# userdel tony
[root@hadoop100 ~]# ls /home
tiny  tony  yangzlll  yling
[root@hadoop100 ~]# id tony
id: tony: no such user
​
直接连用户的文件夹一起删除
[root@hadoop100 ~]# userdel -r tony 

9.4.10 usermod 修改用户

usermod -g 用户组 用户名
​
[root@hadoop100 ~]# usermod -g meifa tiny
[root@hadoop100 ~]# id tiny
uid=2334(tiny) gid=2335(meifa) 组=2335(meifa)
​

用户组管理命令

9.5.1 groupadd新增组

groupadd 组名
​
[root@hadoop100 ~]# groupadd meifa
​
查看组文件
[root@hadoop100 ~]# cat /etc/group
​

9.5.2 groupdel 删除组

[root@hadoop100 ~]# groupdel tiny

9.5.3 groupmod 修改组

修改组名
groupmod -n haircut meifa

9.5.4 cat /etc/group查看创建了哪些组

查看组文件
[root@hadoop100 ~]# cat /etc/group

9.5.5 将用户添加到用户组

groupadd bigdata
useradd -g bigdata xiaoming  #添加小明到bigdata组
useradd -g bigdata xiaowang  #添加小王到bigdata组

文件权限类

9.6.1 文件属性

用ll命令查看文件属性
[root@hadoop100 ~]# ll
总用量 12
-rw-r--r--. 1 root root 1767 7月  18 21:41 2.cfg
-rw-------. 1 root root 1683 7月  17 18:15 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 7月  18 21:35 b
drwxr-xr-x. 2 root root    6 7月  18 21:13 c
drwxr-xr-x. 2 root root   18 7月  18 22:54 foler
-rw-r--r--. 1 root root  688 7月  18 22:54 info
drwxr-xr-x. 2 root root    6 7月  17 18:54 公共
drwxr-xr-x. 2 root root    6 7月  17 18:54 模板
drwxr-xr-x. 2 root root    6 7月  17 18:54 视频
drwxr-xr-x. 2 root root    6 7月  17 18:54 图片
drwxr-xr-x. 2 root root    6 7月  17 18:54 文档
drwxr-xr-x. 2 root root    6 7月  17 18:54 下载
drwxr-xr-x. 2 root root    6 7月  17 18:54 音乐
drwxr-xr-x. 2 root root   44 7月  17 19:04 桌面
​

9.6.2 chmod 改变权限

正在上传…重新上传取消

修改方式变更权限

chmod[{ugoa}{+-=}{rwx}] 文件或者目录

chmod a+x ./* #直接在当前目录下修改全部文件的执行权限
[root@hadoop100 yling]# chmod a+x 2.cfg
[root@hadoop100 yling]# ll
总用量 12
-rwxr-xr-x. 1 root  root  1767 7月  20 20:23 2.cfg
drwxr-xr-x. 2 root  root    34 7月  18 21:32 a
-rw-r--r--. 1 root  root  1767 7月  18 21:27 hello
-rw-r--r--. 1 root  root  1767 7月  17 21:57 initial-setup-ks.cfg
lrwxrwxrwx. 1 root  root    11 7月  18 22:55 myFile -> /root/foler
lrwxrwxrwx. 1 root  root    10 7月  18 22:52 myInfo -> /root/info
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 公共
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 模板
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 视频
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 图片
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 文档
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 下载
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 音乐
drwxr-xr-x. 2 yling yling   29 7月  17 18:47 桌面
​
u:所有者
g:所属组
o:其他人
a:所有人
+:多增加权限
-:减少权限
=:直接覆盖

9.6.3 chown 改变所有者

chown  用户 文件
​
root@hadoop100 yling]# chown yling 2.cfg
[root@hadoop100 yling]# ll
总用量 12
-rwxr-xr-x. 1 yling root  1767 7月  20 20:23 2.cfg
drwxr-xr-x. 2 root  root    34 7月  18 21:32 a
-rw-r--r--. 1 root  root  1767 7月  18 21:27 hello
-rw-r--r--. 1 root  root  1767 7月  17 21:57 initial-setup-ks.cfg
lrwxrwxrwx. 1 root  root    11 7月  18 22:55 myFile -> /root/foler
lrwxrwxrwx. 1 root  root    10 7月  18 22:52 myInfo -> /root/info
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 公共
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 模板
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 视频
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 图片
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 文档
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 下载
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 音乐
drwxr-xr-x. 2 yling yling   29 7月  17 18:47 桌面
​
chown -R 用户 目录  #递归修改用户所有者

9.6.4 chgrp 改变所属组

chgrp 用户 文件
​
[root@hadoop100 yling]# chgrp yling 2.cfg
[root@hadoop100 yling]# ll
总用量 12
-rwxr-xr-x. 1 yling yling 1767 7月  20 20:23 2.cfg
drwxr-xr-x. 2 root  root    34 7月  18 21:32 a
-rw-r--r--. 1 root  root  1767 7月  18 21:27 hello
-rw-r--r--. 1 root  root  1767 7月  17 21:57 initial-setup-ks.cfg
lrwxrwxrwx. 1 root  root    11 7月  18 22:55 myFile -> /root/foler
lrwxrwxrwx. 1 root  root    10 7月  18 22:52 myInfo -> /root/info
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 公共
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 模板
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 视频
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 图片
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 文档
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 下载
drwxr-xr-x. 2 yling yling    6 7月  17 18:19 音乐
drwxr-xr-x. 2 yling yling   29 7月  17 18:47 桌面
​
chgrp -R 用户 目录  #递归修改用户所有组

搜索查询类

9.7.1 find查找文件或者目录

find指令将从指定目录向下递归地遍历其各个子目录,将满足条件的文件显示在终端
​
​
find [搜索范围][选项]
​
find 目录 -name 搜索字符` 搜索名字为xxx的文件 可以使用通配符
   `find 目录 -size 数据块` 搜索大小为xxx的文件,1数据块=0.5kB
   +n 大于 -n 小于 n等于
   组合条件:-o 或者;-a 并且
   find \ -size +163840 -a -size -204800 查找根目录下大于80MB小于100MB的文件
   `find 目录 -group xxx` 查询所属组为xxx的文件
   `find 目录 -user xxx` 查询所属者为xxx的文件 
​
​
#查找后缀为cfg的文件
​
[root@hadoop100 ~]# find -name "*.cfg"
./anaconda-ks.cfg
./.config/yelp/yelp.cfg
./.local/share/telepathy/mission-control/accounts.cfg
./.local/share/telepathy/mission-control/accounts-goa.cfg
./桌面/initial-setup-ks.cfg
./2.cfg
​
#查找user为yling的目录
root@hadoop100 ~]# find /home -user yling
​
​
​

9.7.2 locate快速定位文件路径

先执行updatedb 更新数据库
locate 搜索的文件
​
[root@hadoop100 ~]# updatedb
[root@hadoop100 ~]# locate 2.cfg
/etc/grub2.cfg
/home/yling/2.cfg
/root/2.cfg
​

9.7.3 grep 过滤查找及"|"管道符

grep 选项 查找内容 源文件
​
#在cfg文件中查找boot且显示出他的行号
​
[root@hadoop100 ~]# grep -n boot anaconda-ks.cfg 
8:# Run the Setup Agent on first boot
9:firstboot --enable
17:network  --bootproto=dhcp --device=ens33 --ipv6=auto --activate
28:xconfig  --startxonboot
29:# System bootloader configuration
30:bootloader --location=mbr --boot-drive=sda
​

压缩和解压类

9.8.1 gzip/gunzip压缩

gzip 文件         (功能描述:压缩文件,只能将文件压缩为*.gz文件)
gunzip 文件.gz        (功能描述:解压缩文件命令)

只能压缩文件不能压缩目录

不能保留原文件

同时多个文件会产生多个压缩包

9.8.2 zip/unzip压缩

zip -r  XXX.zip  目录               #递归压缩目录
unzip -d  目录 XXX.zip                  #解压压缩文件到指定目录
​
​
[root@hadoop100 ~]# zip -r myboot.zip foler
  adding: foler/ (stored 0%)
  adding: foler/file (stored 0%)
[root@hadoop100 ~]# ls
2.cfg  anaconda-ks.cfg  b  c  foler  info  myboot.zip  公共  模板  视频  图片  文档  下载  音乐  桌面
​
​
[root@hadoop100 ~]# unzip -d /tmp myboot.zip
Archive:  myboot.zip
   creating: /tmp/foler/
 extracting: /tmp/foler/file         
​

9.8.3 tar 打包

tar [选项] XXX.tar.gz     (功能描述:打包目录,压缩后的文件格式.tar.gz)
​
​
-c          产生.tar打包文件
-v          显示详细信息
-f          指定压缩后的文件名
-z          打包同时压缩
-x          解包.tar文件
-C          解压到指定目录
​
​
#打包多个文件,并且压缩
[root@hadoop100 ~]# tar -zcvf temp.tar.gz 2.cfg anaconda-ks.cfg  b c
2.cfg
anaconda-ks.cfg
b/
c/
[root@hadoop100 ~]# ls
2.cfg  anaconda-ks.cfg  b  c  foler  info  myboot.zip  temp.tar.gz  公共  模板  视频  图片 
​
​
#解包到指定目录
[root@hadoop100 ~]# tar -zxvf temp.tar.gz -C /tmp
2.cfg
anaconda-ks.cfg
b/
c/
​

磁盘查看和分区类

9.9.1 查看文件的目录占用的磁盘空间

du 目录/文件    (功能描述:显示目录下每个子目录的磁盘使用情况)
​
du -sh
​
-h       以人们较易阅读的GBytes,MBytes,KBytes 等格式自行显示
-a       不仅查看子目录大小,还要包括文件
-c       显示所有文件和子目录大小后,显示总和
-s       只显示总和
​

9.9.2 df 查看磁盘空间使用情况

df 选项 (功能描述:列出文件系统的整体磁盘使用量,检查文件系统的磁盘空间占用情况)
​
df -h  #以人们较易阅读的GBytes,MBytes,KBytes 等格式自行显示
​
[root@hadoop100 ~]# df -h
文件系统        容量  已用  可用 已用% 挂载点
devtmpfs        471M     0  471M    0% /dev
tmpfs           487M     0  487M    0% /dev/shm
tmpfs           487M  8.5M  478M    2% /run
tmpfs           487M     0  487M    0% /sys/fs/cgroup
/dev/sda3        15G  4.9G   11G   33% /
/dev/sda1      1014M  169M  846M   17% /boot
tmpfs            98M   40K   98M    1% /run/user/0
/dev/sr0        4.4G  4.4G     0  100% /run/media/root/CentOS 7 x86_64
​

9.9.3 lsblk 查看设备挂载情况

lsblk      (功能描述:查看设备挂载情况)
​
​
[root@hadoop101 公共]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   20G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0    4G  0 part [SWAP]
└─sda3   8:3    0   15G  0 part /
sr0     11:0    1  4.4G  0 rom  /run/media/root/CentOS 7 x86_64
​
​
[root@hadoop101 ~]# lsblk -f    #查看uuid
NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
sda                                                      
├─sda1 xfs          96154bd3-c15c-4a71-b8c6-1da69ef2180a /boot
├─sda2 swap         59d1f711-fa77-4dfd-98b0-1d9cf994152e [SWAP]
└─sda3 xfs          a656c57e-acc6-436d-a782-44ae1ee3605d /
sr0                                                     
​

9.9.4 mount/umount 挂载/卸载

linux中每个分区都是用来组成整个系统的一部分,它在用一种叫做"挂载"的处理方法,它整个文件系统的文件和目录,并将一个分区和目录联系起来,要载入的那个分区将使它的存储空间在这个目录下获得
​
[root@hadoop101 ~]# mount /dev/cdrom /mnt/cdrom
挂载光盘
​
​

9.9.5 fdisk分区

fdisk -l   (功能描述:查看磁盘分区详情)
fdisk 硬盘设备名   (功能描述:对新增的硬盘进行分区操作)

进程管理类

9.10.1 ps查看当前系统进程状态

基本语法:ps aux |grep xxx   (功能描述:查看系统中所有进程)
ps -ef |grep xxx   (功能描述:可以查看父子进程之前的关系)
​
a    列出带有终端的所有用户的进程
x    列出当前用户的所有进程,包括没有终端的进程
u    面向用户友好的显示风格
-e   列出所有进程
-u   列出某个用户关联的所有进程
-f   显示完整格式的进程列表
​
​
ps -ef | less
​
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 12:49 ?        00:00:01 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
root          2      0  0 12:49 ?        00:00:00 [kthreadd]
root          4      2  0 12:49 ?        00:00:00 [kworker/0:0H]
root          5      2  0 12:49 ?        00:00:00 [kworker/u256:0]
root          6      2  0 12:49 ?        00:00:00 [ksoftirqd/0]
root          7      2  0 12:49 ?        00:00:00 [migration/0]
​
​
UID是指用户  PID指进程   
TTY 刚进程在哪个终端运行的,对于CentOS来说,tty1是图形化终端,tty2-tty6是本地的字符界面终端,pts/0-255代表虚拟终端
​
CMD 如何使用该命令
​
​
​
​
如果想看查看进程的CPU占用率的话和内存占用率,可以使用aux
如果想查看进程的父进程ID可以使用ef
​
​
[root@hadoop100 ~]# ps -ef |grep sshd
root       1056      1  0 12:49 ?        00:00:00 /usr/sbin/sshd -D
root       2507   1056  0 12:53 ?        00:00:00 sshd: root@pts/1
​

9.10.2 kill终止进程

kill [选项] 进程号  (功能描述:通过进程号杀死进程)
killall  进程名称   (功能描述:通过进程名称杀死进程,也支持通配符,这在系统因负载过大而变得很慢时很有用)
kill -9  5120
​
killall firefox    #通过进程名杀死进程
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux学习笔记是关于学习Linux操作系统的记录和总结。在学习Linux时,你可能会遇到以下几个方面的内容。 首先,Linux是一个面向网络服务的操作系统,因此你可以随意更换桌面系统。Linux有多种不同的桌面系统供你选择。这意味着你可以根据自己的喜好和需求,选择适合自己的桌面环境。 其次,在Ubuntu中,root用户默认是被锁定的,因此你无法直接使用root权限进行操作。但是,你可以使用sudo命令来提升权限,以执行需要root权限的操作。通过sudo命令,普通用户可以在需要时暂时获得root权限,以便进行需要的操作。 此外,如果你需要修改内核为bash,可以使用vim编辑器打开/etc/passwd文件进行修改。在Linux系统中,vim是一种常用的文本编辑器,类似于Windows的记事本。通过编辑/etc/passwd文件,你可以修改用户的登录shell为bash。 总结起来,Linux学习笔记记录了学习Linux操作系统的过程和经验,包括选择适合自己的桌面环境、使用sudo提升权限以及通过vim编辑器修改/etc/passwd文件等。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Linux学习笔记](https://blog.csdn.net/m0_65379736/article/details/125700177)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值