歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> 第二周學習筆記2

第二周學習筆記2

日期:2017/3/3 11:12:05   编辑:Linux技術
讓普通用戶不能登錄服務器
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 > 外部命令 優先級比較
Copyright © Linux教程網 All Rights Reserved