Linux(RedHat)学习之路1.0

来源:互联网 发布:mac连wifi需要wpa2密码 编辑:程序博客网 时间:2024/06/03 14:09

shell命令基础

1、shell是什么?

用户和内核之间的接口
命令解释器

2、shell命令的格式

命令 选项 参数
ls -l /etc/fstab
3、shell的一些使用
历史命令:上下键
补全功能:tab键
中断命令:ctrl+c
清屏:ctrl+L

目录和文件操作命令

1、rhel7的目录结构
绝对路径:从“/”开始,唯一
相对路径:不唯一(灵活)
当前工作目录

2、三个基础命令
cd,切换路径
[root@localhost ~]# cd ;回到登录用户的家目录
[root@localhost ~]#表示的含义
root:登录用户名
@:at
localhost:主机名
~:家目录,root用户家目录/root,普通用户家目录/home/loginname
#:root账户的提示符,普通用户提示符为$

[root@localhost ~]# cd  /var/tmp    ;切换到指定目录[root@localhost tmp]# cd  ..      ;回到上一级目录

pwd,查看当前所在路径

[root@localhost ~]# cd /var/tmp[root@localhost tmp]# pwd

ls,列表文件

[root@localhost ~]# cd  /bin[root@localhost bin]# ls               ;列表当前目录内容[root@localhost ~]# ls   /etc         ;列表指定目录内容

3、文件操作命令
新建、拷贝、删除、移动(改名)
①touch,新建空文件
格式:
touch 文件列表

[root@localhost ~]# touch  a.txt[root@localhost ~]# touch  b.txt c.txt[root@localhost ~]# ls

②cp,拷贝

[root@localhost ~]# cp   a.txt   /home/       ;拷贝不改名   [root@localhost ~]# cp   b.txt   /home/bb.txt         ;拷贝同时改名[root@localhost ~]# ls   /home/

③rm,删除, rm - remove files or directories

[root@localhost ~]# rm     /home/a.txt    [root@localhost ~]# ls   /home/[root@localhost ~]# rm  -f  /home/bb.txt          ;没有交互提示, -f, --force 

④mv,移动

[root@localhost ~]# ls[root@localhost ~]# mv  c.txt    /home/[root@localhost ~]# ls[root@localhost ~]# ls    /home/[root@localhost ~]# mv   a.txt    aa.txt     ;改名,在相同路径下[root@localhost ~]# ls

文本操作命令

1、查看文件内容
cat、more、less 、head、tail

2、vim编辑器

用户和组

用户管理:
三类用户及uid:
root:0
系统用户:1-999
普通用户:1000-60000

1、相关文件
①/etc/passwd(记录用户基本信息,熟知7段含义)

[root@server ~]# head -1 /etc/passwdroot:x:0:0:root:/root:/bin/bash

root:用户的登录名
x:密码占位
0:uid -u
0:gid -g
root:全名 -c
/root:用户的家目录(主目录、私有目录) -d
/bin/bash:登录shell,不允许登录,/sbin/nologin -s

②/etc/shadow(一般了解)
!锁定

命令:
①添加用户
useradd [-option] username
-G,附加组(补充组、额外组)

[root@server ~]# useradd  us1[root@server ~]# useradd  -u 30000  us2[root@server ~]# tail -1  /etc/passwd

②删除用户
userdel -r username ;-r同时删除用户家目录

[root@server ~]# userdel -r us2[root@server ~]# tail -1  /etc/passwd

③修改用户属性

[root@server ~]# usermod  -s /sbin/nologin us1[root@server ~]# tail -1  /etc/passwd

④设置用户密码

[root@server ~]# passwd  us1

组管理
1、文件:/etc/group

[root@server ~]# tail    /etc/group

2、命令
①groupadd

[root@server ~]# groupadd testgrp[root@server ~]# tail -1 /etc/group

②groupdel

[root@server ~]# groupdel testgrp[root@server ~]# tail  -1  /etc/group

权限管理

1、核心
目录和文件
2、谁用?
三种角色:
属主u(文件的所有者,只有一个)user
属组g(文件所属的组)group
其他人o(无关)other
3、怎么用?
读r(read)
写w(write)
执行x(execute)
4、查看文件/目录的权限(ls -l)
[root@server ~]# ls -l /etc/passwd
- rw- r– r–. 1 root root 1047 Sep 28 11:16 /etc/passwd
① ② ③ ④ ⑤ ⑥ ⑦ ⑧
①:类型,-为普通文件,d为目录
②:权限
③:文件数(inode)
④:属主
⑤:属组
⑥文件大小(B)
⑦创建/修改时间
⑧文件/目录名

练习

1.添加一个用户,账号为testgdlc,初始口令为123456;
要求该用户的主目录为/home/share
要求该用户的基本组为root
要求该用户的shell为/bin/tcsh;
要求把该用户加到mail组和news组中;

cat /etc/group | grep rootcat /etc/group | grep mailcat /etc/group | grep newsgroupadd newsuseradd -d /home/share -g root -s /bim/tcsh -G mail,news testgdlctail -1 /etc/passwdid testgddlc

Linux(RedHat)学习之路2.0

原创粉丝点击