做网站除了广告还有什么收入的,橙色网站设计,h5网站开发软件,重庆有什么好玩的地方景点介绍目录 思维导图
搜索查看查找类
find 从指定目录查找文件
head 与 tail 查看行
cat 查看内容
more 查看大内容
grep 过滤查找
history 查看已经执行过的历史命令
wc 统计文件
du 查看空间
管道符号 | 配合命令使用
上机练习 4
解压安装类
zip unzip 压缩解压
tar …目录 思维导图
搜索查看查找类
find 从指定目录查找文件
head 与 tail 查看行
cat 查看内容
more 查看大内容
grep 过滤查找
history 查看已经执行过的历史命令
wc 统计文件
du 查看空间
管道符号 | 配合命令使用
上机练习 4
解压安装类
zip unzip 压缩解压
tar 压缩解压
Yum 包管理
用户权限类
基本介绍
用户及用户组
用户和组的相关文件
rwx 权限详解
chmod 修改权限
chown 修改文件所有者
上机练习 5
自主发挥
vim 编辑更完整版 思维导图 搜索查看查找类
find 从指定目录查找文件 -name 查询方式 按照指定的文件名查找模式查找文件 -mtime n 查找 n 天以前被修改过的所有文件。 -exec执行指令假设 find 指令的回传值为 True就执行该指令 -size 文件大小 按照指定的文件大小查找文件 find /root -name *.pdf find /root -name *.pdf -a -size 1M find /root -mtime 7 #七天前被修改过的文件 find /root -name *.sql -exec ls -l {} \; #查找文件并以 ls -l 形式显示 find /root -name *.pdf -exec rm -f {} \; head 与 tail 查看行 head -n 文件名 不加默认开头十行 tail -n 文件名 不加默认结尾十行 head 3.txt tail 3.txt head -n 3 3.txt #只显示前三行 tail -n -3 3.txt #只显示后三行 cat 查看内容 cat英文全拼concatenate命令用于连接文件并打印到标准输出设备上。 -n 显示行号包括空行 -b 跳过空白行编号 -s 将所有的连续的多个空行替换为一个空行压缩成一个空行 cat 1.log 2.log cat -sb test.log more 查看大内容 more 分屏查看文件敲空格查看下一页 grep 过滤查找 以行为单位进行查找显示结果为满足的行 -c 统计满足的行数 -v 反转不包含 grep p 1.txt 单文件搜索包含 p 的行 grep P 1.txt b.txt 多文件搜索 grep -v p 1.txt 单文件搜索不包含 p 的行 grep -c p 1.txt #统计出现多少行 grep n$ 1.txt #现实以 n 结尾的行 grep ^n 1.txt #现实以 n 开头的行 history 查看已经执行过的历史命令 history history 5 最近五个命令 wc 统计文件 查看文件的字节数 wc -c t2.txt 查看文件的行数 wc -l t2.txt du 查看空间 du -h 人性化方式带单位 du -s 只统计每个参数所占用空间总的大小 du -sh /etc 管道符号 | 配合命令使用 管道符 | 表示将前一个命令的处理结果输出传递给后面的命令处理 和 指令 输出重定向(覆盖写), 追加追加写 示例 ls -l | grep -c ^d ls -l | grep ^d | wc -l history | grep -c ls history | grep ls | grep s$ ttt.txt cat a.txt b.txt ttt.txt cat a.txt b.txt | grep s ttt.txt 上机练习 4 上机练习 4 1. 将 /etc/passwd 文件拷贝到 /root/ 目录下并改名为 ptest mv /etc/passwd /root/ cd /root mv passwd ptest 2. 查看 ptest 的前八行数据 head -n 8 ptest 3. 过滤查看 ptest 文件中包含 root 的行 grep root ptest 4. 查看 /home 目录占用空间 du -sh /home 5./root 中新建文件 test.log 插入内容如下 directory-client gnome-apps gnome-desktop cd /root touch test.log vim test.log i 插入 ESC :wq! 6. 将 test.log 和 ptest 合并到 /root 目录下的 test1.log cd /root cat test.log ptest test1.log 7. 将 /root 目录下的 ptest 加上行号输出到 test2.log cat -sb ptest test2.log 8. 查找并显示根目录下大于 1M 的 png 文件 find /root -name *.png -a -size 1M 9. 统计系统上使用 ls 命令的次数 history | grep -c ls 10. 将 /root/ptest 中出现了 root 的行存储到 test.txt 文件 grep root /root/ptest test.txt 11. 根据名称查找 /root 下的 txt 文件 find /root -name *.txt 12. 查找整个 linux 系统下大于 20M 的文件 (n 大于 -n 小于 n 等于 ) find / -type f -size 20M 13. 查找 /root/xxx/yyy/zzz 下所有 .txt 文件并把他们删掉 find /root/xxx/yyy/zzz -name *.txt -exec rm -f {} \; 14. 统计 ptest 文件的字节数 wc -c /root/ptest 15. 统计 ptest 文件以 s 开头的行的数量 grep ^s ptest |wc -l 解压安装类
zip unzip 压缩解压 # 压缩文件和目录 zip 文件名.zip 将要压缩的内容 # 解压缩文件 unzip 文件名.zip 常用选项 -r递归压缩即压缩目录 -d目录 指定解压后文件的存放目录 zip test.zip -r a/b 注绝对路径压缩会带前面的路径文件夹 unzip linux.x64_11gR2_database_1of2.zip -d /opt/app/database/ tar 压缩解压 -z 调用 gzip 程序进行压缩或解压 -c 创建Create.tar 格式的包文件 -x 解开.tar 格式的包文件 -C /解压时指定释放的目标文件夹 指定目录 -v 输出详细信息Verbose -f 表示使用归档文件一般都要带上表示使用 tar,放在最后 压缩tar [选项] ... 归档文件名压缩包名字 源文件或目录 解压tar [选项] ... 归档文件名 [-C 目标目录] tar -zcvf abc123.tar.gz abc.txt 123.txt 压缩成 abc123.tar.gz 的命令 tar -zcvf abc123.tar.gz m tar -zxvf abc123.tar.gz -C test/ 解压到指定目录 Yum 包管理 Yum 是一个 Shell 前端软件包管理器。基于 RPM 包管理能够从指定的服务器自 动下载 RPM 包并且安装可以自动处理依赖性关系并且一次安装所有依赖的软件包。 查询 yum 服务器是否有需要安装的软件 yum list | grep xxx 查询指定的 yum 包信息 yum info xxx 安装指定的 yum 包 yum install xxx 卸载指定的 yum 包 yum remove xxx 查看已安装的软件包 yum list installed yum install ntpdate # 安装网络对时 用户权限类
基本介绍 登录时尽量少用 root 帐号登录因为它是系统管理员最大的权限避免操作 失误。可以利用普通用户登录登录后再用 su - 用户名命令来切换 用户及用户组 类似于角色系统可以对有共性的多个用户进行统一的管理。 新增用户组 groupadd xiaoshou 添加用户 useradd xiaomei 添加用户时加上组 useradd -g xiaoshou xiaomei 指定/修改密码 passwd xiaomei 查询用户信息 id xiaomei 切换用户 su - xiaomei 查看当前用户 whoami 修改用户的组 usermod -g 用户组 用户名 删除用户 userdel xiaomei (exit 退出后再删除) 删除组 groupdel xiaoshou 用户和组的相关文件 /etc/passwd 文件 用户user的配置文件记录用户的各种信息 每行的含义用户名:口令:用户标识号:组标识号:注释性描述:主目录:登录 Shell /etc/group 文件 组(group)的配置文件记录 Linux 包含的组的信息 每行含义组名:口令:组标识号:组内用户列表 rwx 权限详解 [ r ]代表可读(read): 可以读取 [ w ]代表可写(write): 可以修改 [ x ]代表可执行(execute):可以被执行 -rwxrw-r--. 1 root root 1213 Feb 2 09:39 abc 10 个字符确定不同用户能对文件干什么 第一个字符代表文件类型文件( - ),目录( d ),链接( l ) 第一组 rwx : 文件拥有者的权限是读、写和执行 第二组 rw- : 与文件拥有者同一组的用户的权限是读、写但不能执行 第三组 r-- : 不与文件拥有者同组的其他用户的权限是读不能写和执行 可用数字表示为: r4,w2,x1 因此 rwx4217 chmod 修改权限 通过 chmod 指令可修改文件或目录的权限 -R 表示递归里面的所有文件及目录 、-、 变更权限 u:所有者 g:所有组 o:其他人 a:所有人(u、g、o 的总和) chmod urwx,grx,ox 文件目录名 chmod ow 文件目录名 chmod a-x 文件目录名 $ chmod ux file 给 file 的属主增加执行权限 $ chmod 751 file $ chmod urwx,grx,ox file 上例的另一种形式 $ chmod 444 file 同上例 $ chmod a-wx,ar file 同上例 $ chmod -R ur directory 递归地给 directory 目录下所有文件和子 目录的属主分 配读的权限 chown 修改文件所有者 chown [-R] 所有者 文件或目录 -R 表示递归里面的所有文件及目录 chown test02 /root/test.txt chown -R 用户:组 /usr/local/mysql chown meimei:students 1.txt 上机练习 5 1.将 /root/xxx 压缩成 a.tar.gz tar -zcvf a.tar.gz 2. 将 a.tar.gz 解压到/root/ceshi/ -zxvf a.tar.gz -C /root/ceshi/ 3. 增加用户组 students groupadd students 4. 添加新用户 kunkun 及 meimei 并直接加到 students 组 useradd -g students kunkun useradd -g students meimei 5. 指定 kunkun 密码, 然后切换到这个用户 passwd kunkun su - kunkun 6. 到该用户的家目录新建一个 student.txt root 账号chmod 777 /home/ su - kunkun touch /home/student.txt 7. 查询并写入该用户的用户信息到 student.txt, 退出 exit 管理员账号su - kunkun id kunkun/home/student.txt 8. 使用 root 账号新建文件 1.txt 及 2.txt 对文件/root/1.txt 为所有用户分 配读写执行权限 touch {1..2}.txt chmod a-x /root/1.txt 9. 对文件/root/2.txt 设置权限为 rwxr-xr-- chmod 754 /root/2.txt 10. 对文件/root/2.txt 设置属组权限增加写的权限 chmod gw /root/2.txt 11. 给/root/1.txt 文件修改 kunkun 用户及 students 用户组权限 chown kunkun:students /root/1.txt 12. /root/下创建文件夹 open里面批量创建文件 open1.log...open100.log mkdir /root/open touch open{1..100}.log 13. 对文件夹 open 设置为 meimei 用户及 students 用户组权限 chown meimei:students /root/open 14. 对文件夹 open 设置权限为 rwxr-xr-x chmod 755 /root/open 15. 查看/etc/group 及/etc/passwd 文件内容重定向到/root/open.txt 中 touch open.txt cat /etc/group /etc/passwd/root/open.txt 16. 删除用户 kunkun 和 meimei查看/etc/passwd 的后 3 行数据追加到 /root/open.txt 中 userdel kunkun userdel meimei tail -n -3 /etc/passwd /root/open.txt 17. 删除用户组查看/etc/group 的后 3 行数据追加到/root/open.txt 中 groupdel students tail -n -3 /etc/group /root/open.txt 18. 删除 home 下两个用户的文件夹及里面的内容 rm -rf /home/kunkun rm -rf /home/meimei 19. 神仙妖怪大战使用拼音来化名例如shaseng 为沙僧 ●建立两个组 (神仙, 妖怪)建立用户 (悟空, 八戒, 沙僧)把悟空和八戒放 入妖怪沙僧放入神仙 groupadd god groupadd monster useradd -g monster Wukong useradd -g monster Bajie useradd -g god Shasheng ●设置三个用户的密码 passwd Wukong passwd Bajie passwd Shasheng (这里设置密码要求太严苛了我就懒得设了) ●用悟空在自己的家目录下建立一个文件 monkey.txt该文件要输出 i am a monkey chmod 777 /home/ su - Wukong touch /home/monkey.txt vim monkey.txt i 输入 ESC :wq! ●用 root 账号给八戒一个对悟空文件夹及内容可以 rwx 的权限 chown Bajie /home/Wukong ●八戒修改 monkey.txt 加入一句话( i am a pig ) su - Bajie vim /home/Wukong/monkey.txt ●测试一下沙僧对该文件有没有权限访问 su - Shasheng more /home/Wukong/monkey.txt ●把沙僧放入妖怪组 usermod -g monster Shasheng ●让沙僧修改该文件 monkey.txt加入一句话 (我是沙僧我是妖怪!) chown Shasheng /home/Wukong su - Shasheng vim /home/Wukong/money.txt o 输入 ESC :wq! 自主发挥 建立一个学习小组加上组员。 groupadd BringHonor useradd -g BringHonor HuYingJing useradd -g BringHonor QinYuXiao useradd -g BringHonor ShiHaiHong useradd -g BringHonor MoDeYu vim 编辑更完整版