美文网首页
Linux学习笔记-1

Linux学习笔记-1

作者: 秦小生 | 来源:发表于2018-11-16 16:27 被阅读8次
感觉自己一直以来学习东西都是一半一半的,所以整理个学习笔记算是督促自己吧。

PS:学习是通过实验楼学习的。

1、Linux命令

1.1 Linux中命令格式:

command [options] [arguments] #中括号代表可选的,即有些命令不需要选项也不需要参数
选项是调整命令执行命令的开关,选项的不同决定了命令结果的不同。
参数是指命令的作用对象。

1.2 man命令

manmanul的缩写,我们可以通过man man来查看man命令的帮助
帮助文档包含:

1 Executable programs or shell commands(用户命令帮助) 
2 System calls (系统调用帮助)  
3 Library calls (库函数调用帮助)  
4 Special files (usually found in /dev)  
5 File formats and conventions eg /etc/passwd(配置文件帮助)  
6 Games  
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)  
8 System administration commands (usually only for root)  
9 Kernel routines [Non standard]

解释如下:

1 Executable programs or shell commands(用户命令帮助) 
2 System calls (系统调用帮助)  
3 Library calls (库函数调用帮助)  
4 Special files (usually found in /dev)  
5 File formats and conventions eg /etc/passwd(配置文件帮助)  
6 Games  
7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)  
8 System administration commands (usually only for root)  
9 Kernel routines [Non standard]

man命令可以结合grep命令和管道,可以多关键字查找:

man -k key1 | grep key2 | grep key3 | ...
1.3 cheat命令

cheat命令是在GNU通用公共许可证下,为Linux命令行用户发行的交互式备忘单应用程序。它提供显示Linux命令使用案例,包括该命令所有的选项和简短但尚可理解的功能。
 使用cheat命令作弊还是可以的。
 安装参考:Cheat—— 给Linux初学者和管理员一个终极命令行"备忘单"

1.4 与查找相关的核心命令

find,locate,grep,whereis,which都是与查找相关的核心命令。

find查找一个文件或者目录在系统的位置
locate是神速版的find(Windows中有个Everything和locate类似)
grep可以对文件进行全文检索,支持正则表达式
whereis which 告诉你使用的命令工具安装在什么地方
1.5 有趣的命令

banner命令是一个可以输出图形字符的命令。
 安装放式如下:

$ sudo apt-get update
$ sudo apt-get install sysvbanner

效果图:
自我想象-_--||

2、用户以及文件权限管理

 2.1 查看用户

 通过终端输入命令who am i或者who mom likes

$ who am i
root                     pts/0              2018-11-16 15:13 (61.158.149.87)
#[伪终端用户的用户名]   [pts代表伪终端 0是终端序号]  [当前伪终端的启动时间]

root用户是系统最高用户,拥有至高无上的权限。一般登陆都是通过普通用户登陆系统的。

 2.2 创建用户

 创建用户需要root权限或者是直接登陆root账户添加用户(当然你需要知道密码)
 创建hanmimi用户

jm:~/ sudo adduser hanmimi

su <user>可以切换到user用户,不过需要用户名和密码,sudo <cmd>可以以高权限运行cmd命令,但是需要当前用户在sudo用户组,并且需要知道root用户的密码。
切换到hanmimi用户

root:~/ su -l hanmimi

退出当前用户,可以直接输入exit然后敲击回车。退出终端操作也是这样。

hanmimi:~/ exit
 2.3 用户组

 查看用户所在的用户组-1

$: groups lilei
lilei  :  lilei
#[第一列是用户名称]  {第二列是用户所属的用户组名称]

 查看用户所在的用户组-2

$ cat /etc/group | sort
# | sort 表示将读取的文本进行一个字典排序再输出
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:
cdrom:x:11:
mail:x:12:postfix
man:x:15:
dialout:x:18:
floppy:x:19:
games:x:20:
tape:x:30:
video:x:39:
ftp:x:50:
lock:x:54:
audio:x:63:
nobody:x:99:
users:x:100:
utmp:x:22:

太多了过滤掉它:

$ cat /etc/group | grep -E 'lilei'
lilei:x:1000:
 2.4 添加用户到sudo用户组

通过一条命令usermod -a -G sudo 用户名

$ greoups lilei
$ usermod -a -G sudo lilei

相关文章

网友评论

      本文标题:Linux学习笔记-1

      本文链接:https://www.haomeiwen.com/subject/vuoufqtx.html