linux 日期 通配符,Linux常用基础命令下(grep,history,du,date,通配符,alias,rm,mv,cp)
grep工具 查找文本內容 ? 用途:輸出包含指定字符的行
格式? grep? [選項] ? '查找字符串' ? ? ? 目標文件
[root@guowei ~]# cat sed.txt
MacBook-Pro:tmp maxincai$ cat test.txt
my cat's name is betty
This is your dog
my dog's name is frank
This is your fish
my fish's name is george
This is your goat
my goat's name is adam
[root@guowei ~]# grep T sed.txt #查看包含T字符的行,其中也可以寫成 grep 'T'
This is your dog
This is your fish
This is your goat
[root@guowei ~]# grep -i T sed.txt #-i 不區分大小寫
MacBook-Pro:tmp maxincai$ cat test.txt
my cat's name is betty
This is your dog
This is your fish
This is your goat
my goat's name is adam
[root@guowei ~]# grep -v This sed.txt # -v 取反 也就是查看不包含This字符的行
MacBook-Pro:tmp maxincai$ cat test.txt
my cat's name is betty
my dog's name is frank
my fish's name is george
my goat's name is adam
[root@guowei ~]# grep ^Mac sed.txt #查看以Mac開頭的行 ^word 以某個字符開頭
MacBook-Pro:tmp maxincai$ cat test.txt
[root@guowei ~]# grep ge$ sed.txt #查看以ge結尾的行 word$ 以某個字符結尾
my fish's name is george
[root@guowei ~]# cat zhushi.txt
# shan you mu xi mu you zhi
xin yue jun xi jun bu zhi
[root@guowei ~]# grep ^$ zhushi.txt #匹配空行
[root@guowei ~]# grep ^# zhushi.txt #匹配注釋行,shell默認的#為注釋
# shan you mu xi mu you zhi
[root@guowei ~]# grep -v ^$ zhushi.txt | grep -v ^# #匹配不是空行也不是注釋的行
xin yue jun xi jun bu zhi
history? 歷史命令 管理/調用曾經執行過的命令
[root@guowei ~]# history #列出曾經執行過的命令
1 yum repolist all
2 yum list all
...
240 vim love.sh
241 ls
242 history
[root@guowei ~]# !241 #執行歷史命令中的第241條命令
ls
1611con hell.sh love1.sh share zhushi.txt 視頻 下載
anaconda-ks.cfg initial-setup-ks.cfg love.sh test 公共 圖片 音樂
c-language log-20190802.tar.gz sed.txt windows 模板 文檔 桌面
[root@guowei ~]# !vim #執行最近一次以vim開頭的命令
vim love.sh
[root@guowei ~]# vim /etc/profile
...
44
45 HOSTNAME=`/usr/bin/hostname 2>/dev/null`
46 HISTSIZE=1000 #修改記錄的最大條數
...
[root@guowei ~]# history -c #清空歷史命令
[root@guowei ~]# history
1 history
du統計文件占用的空間 ?? du? [選項] ? 目錄或者文件
[root@guowei ~]# du love.sh #統計love.sh所占用的空間大小
8love.sh
[root@guowei ~]# du -s love.sh #只統計每個參數所占用的空間大小
8love.sh
[root@guowei ~]# du -sh love.sh #提供易讀容量單位(k,M等)
8.0Klove.sh
date? 查看/調整系統日期時間
[root@guowei ~]# date
2019年 08月 06日 星期二 11:07:48 CST
[root@guowei ~]# date +%F
2019-08-06
[root@guowei ~]# date +%R
11:08
[root@guowei ~]# date +"%Y-%m-%d %H:%M:%S" #%Y%m%d" 間隔字符可以隨意
2019-08-06 11:09:00
[root@guowei ~]# date +"%Y%m%d %H%M%S"
20190806 110915
[root@guowei ~]# date +"%Y/%m/%d %H-%M-%S"
2019/08/06 11-09-38
[root@guowei ~]# date -s"2019-8-6" #可以設置時間和日期
2019年 08月 06日 星期二 00:00:00 CSTCMOS
[root@guowei ~]# clock -w #將時間寫入硬件中
通配符針對不確定的文檔名稱,以特殊字符表示? *? 任意多個字符 ? ? 單個字符
[a-z]:多個字符或連續范圍中的一個,若無則忽略(識別[0-9])
{a,min,xy}:多組不同的字符串,全匹配
[root@wei ~]# ls /dev/tty{2[0-9],30} #列出dev設備中,tty20至tty30的設備
/dev/tty20 /dev/tty26
/dev/tty21 /dev/tty27
/dev/tty22 /dev/tty28
/dev/tty23 /dev/tty29
/dev/tty24 /dev/tty30
/dev/tty25
[root@wei ~]# ls /dev/tty{2?,30}
/dev/tty20 /dev/tty26
/dev/tty21 /dev/tty27
/dev/tty22 /dev/tty28
/dev/tty23 /dev/tty29
/dev/tty24 /dev/tty30
/dev/tty25
alias 別名? 簡化復雜的命令
alias? [別名名稱] ? ? ? ? ? 查看已設置的別名
alias? 別名名稱='實際執行的命令行' ? ? ? ? 定義新的別名
unalias ? ? [別名名稱] ? ? ? 取消已設置的別名
[root@wei ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
...
[root@wei ~]# hn
bash: hn: 未找到命令...
[root@wei ~]# alias hn='hostname'
[root@wei ~]# hn
wei
[root@wei ~]# unalias hn
[root@wei ~]# hn
bash: hn: 未找到命令...
為真機設置永久的別名 ? ? ? /root/.bashrc
rm 刪除? rm——remove
格式:rm [選項]... ? 文件或目錄
-r 、-f :遞歸刪除(含目錄)、強制刪除
注意:rm -rf? 慎用
mv 移動/重命名 ? mv ——move
格式:mv? 原文件... ?? 目標路徑
重命名:路徑不變的移動
[root@wei ~]# mv love1.sh test
[root@wei ~]# ls test/
a love1.sh
cp? 復制? cp——copy
格式:cp [選項]...? 源文件... ?? 目標路徑
-r? 遞歸 ,復制目錄時必須有此選項
復制時重名文檔 在本次操作中,臨時取消別名
復制支持兩個以上參數,永遠把最后一個參數作為目標,其他參數全部作為源
復制的時候,可以重新命名,目標路徑下文檔的名字
[root@wei ~]# cp love.sh love2.sh
[root@wei ~]# ls
1611con love2.sh zhushi.txt 下載
anaconda-ks.cfg love.sh 公共 音樂
總結
以上是生活随笔為你收集整理的linux 日期 通配符,Linux常用基础命令下(grep,history,du,date,通配符,alias,rm,mv,cp)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux如何格式化u盘并挂载,Linu
- 下一篇: linux识别新加存储盘,Linux下新