您的位置:首页 > 其它

第二周学习笔记2

2016-07-25 21:05 274 查看
让普通用户不能登录服务器

getent passwd xxx 查看对应账户的信息




touch /etc/nologin 设置后普通账户在CLI模式下无法登录
rm -f /etc/nologin 恢复普通用户登录
ltrace 查看系统调用
strace 查看库调用

reset修复乱码

touch 'data + %d'.log

touch f1 f2 f3 = touch f{1,2,3}

touch f{1,2,3,4}.{txt.log}

试验

[root@centos7 tmp]# cd /testdir/
[root@centos7 testdir]# ls
[root@centos7 testdir]# touch f{1,2,3,4}.{txt,log}
[root@centos7 testdir]# ls
f1.log f2.log f3.log f4.log
f1.txt f2.txt f3.txt f4.txt
[root@centos7 testdir]#

查看帮助的方法

whatis:查看命令简要作用,依赖于专有数据库, 显示命令的简短描述

whatis rm

[root@centos7 ~]# whatis rm
rm (1) - remove files or directories
rm (1p) - remove directory entries

没装whatis数据库的时候就不会显示上面的命令

创建whatis数据库
wahtis = man -f
apropos = man -k

makewhat centos6
mandb centos7

man -f rm = whatis rm

查看命令的基本用途

help cd type help hash pwd echo

man bash

内部命令
cd:改变当前shell的工作目录

内置命令,help查看命令详细用法
-d:简单描述命令
-m:man格式的方式来显示
-s:显示命令的大概的用法语法
内部命令获取帮助方法:
# help COMMAND
# man bash 能查看内部命令的所有帮助
内部命令: type pwd cd help hash echo

外部命令:--help 显示用法总结和参数列表,大多数命令可以使用
其中:命令使用格式
[]:可选
<>:变量
...:表示一个列表
a|b:二选一
-abc:-a -b -c

练习:

显示当前日期,格式:2016-08-08

root@centos7 testdir]# date -d now +%F
2016-07-26
或者
[root@centos7 testdir]# date +%Y/%m/%d
2016/07/26

显示前天是星期几

[root@centos7 ~]# date -d '-2day' +%F
2016-07-24

设置当前日期为2008-08-0808:08

date 0808082008.08

clock -s 硬件时间同步

date 其他命令

date +%Y/%m/%d
date +%H:%M

date -d now
date -d yesterday
date -d yesterday +%F

[root@centos7 Desktop]# date -d yesterday
Sun Jul 24 10:18:39 CST 2016
[root@centos7 Desktop]# date -d yesterday +%F
2016-07-24
[root@centos7 Desktop]# date -d '-2 day' +%F
2016-07-23

root@centos7 Desktop]# date +%j 当前是一年中的第几天
207
[root@centos7 Desktop]# date +%s
1469413377 1970-1-1 unix诞生日
[root@centos7 Desktop]# date -u 格林尼治时间
Mon Jul 25 02:23:13 UTC 2016

manual 手册
手册放在 /usr/share/man
cd /usr/share/man
ls ls*
ls
chapter 章节 man页面分为不同的章节

which passwd 查看passwd文件路径

whereis passwd 由一些特定目录寻找文件文件名

ls -l /etc/passwd 查看文件列表

file /bin/passwd 查看文件类型

whatis passwd= man -f passd 查看passwd命令章节号

man 章节内容

1章节 普通用户 牢记
2章节 管理员
3章节 c库调用
4章节 设备文件及特殊文件
5章节 配置文件格式 牢记
6章节 游戏
7章节 杂项
8章节 管理类命令 牢记
9章节 linux内核

查看man手册页
SYNOPSIS摘要
[]:可选内容
<>: 必选内容
a|b:二选一
...: 同一内容可出现多次

/keyword 搜索
#/user 光标当前位置向下搜索
?keywork 光标当前位置向上搜索
n同向 上一个
N反向 下一个

man -k passwd =apropos passwd 列出所有匹配的页面
man -f passwd =whatis passwd 搜索章节
man -a passwd: 列出passwd相关所有章节

man帮助的文件放在/usr/share/man

centos6:man的配置文件 /etc/man.config
centos7:man的配置文件 /etc/man_db.conf

man命令的操作方法:使用less命令实现
Space, ^V, ^f, ^F: 向文件尾翻屏
b, ^B: 向文件首部翻屏
d, ^D: 向文件尾部翻半屏
u, ^U: 向文件首部翻半屏
RETURN, ^N, e, ^E or j or ^J: 向文件尾部翻一行y or ^Y or ^P or k or ^K:向文件首部翻一行
q: 退出
#:跳转至第#行
1G: 回到文件首部
G:翻至文件尾部

/KEYWORD:
以KEYWORD指定的字符串为关键字,从当前位置向文件尾部搜索;不区分字符大小写;
n: 下一个
N:上一个
?KEYWORD:
以KEYWORD指定的字符串为关键字,从当前位置向文件首部搜索;不区分字符大小写;
n: 跟搜索命令同方向,下一个
N:跟搜索命令反方向,上一个

练习

字符终端登录时,显示当前登录终端号,主机名和当前时间

分析
cat /etc/issue 目录默认状态
\S
Kernel \r on an \m
issue内的各代码意义
\d 本地端时间的日期
\l 显示第几个终端接口
\m 显示硬件的等级
\n 显示主机的网络名称
\O 显示domain name
\r 操作系统的版本(相当于uname -r)
\t 显示本地端时间的时间
\S 操作系统的名称
\v 操作系统的版本
答案:
vi /etc/issue
\S(terminal: \l)
Date: \d \t
Kernel \r on an \m

今天17:30自动关机

shutdown -P 17:30 & 后台执行17:30分关机的任务

shutdown -c 取消
虽然 shutdown/reboot/halt等指令均已经在关机前进行了sync 这个工具的呼叫,不过为了放心,还是多做几次才好。
[root@centos7 ~]# syn

sosreport 求助报告

history 命令行历史 最多纪录1000条

rm -f .bash_history 删除历史保存目录
history -c 清空历史记录
exit
history -a 记录消失

别名存放地方 .bashsrc

HISTIGNORE=‘passwd:cat’ 历史中隐藏敏感信息

IGNOREDUPS 连续重复的命令只显示一条在历史中

HISTSIZE 1
33 echo $HISTSIZE
34 history
35 HISTSIZE 10
36 HISTSIZE=10
37 history
38 logout
39 history
[root@centos7 ~]# HISTSIZE=5
root@centos7 ~]# history
36 history
37 logout
38 history
39 HISTSIZE=5
40 history
重复执行 ctrl p !! !-1 上键

!?go 执行最近带go的命令
!sos 搜索带sos的最近执行的命令

ctrl r 搜索
[root@centos7 /]# cat /etc/issue
\S
Kernel \r on an \m
STOP!!! THIS IS MY ROOM
[root@centos7 /]# ll !$ ll 后面的参数是 !$ 表示 /etc/issue

还可以 ll 按住alt 再按.
还可以 ll 按住esc 点.

$表示最后一个参数 ,^表示第一个参数 *表示所有 :2 表示上一个命令的第2个命令例如 ll !:2

别名 alias ls

运行别名的三个方法 /bin/ls \ls 'ls'

unalias ls 取消别名 只是临时取消

alias > 内部命令 >hash > 外部命令 优先级比较
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: