1、 linux 上的文件管理類命令都有哪些, 其常用的使用方法及相關示例演示
cat concatenate file and print ont the standard output
cat [OPTION]…[FILE]… eg :cat /etc/passwd
-E, –show-ends
display $ at end of each line 顯示出換行符$
-n, –number
number all output lines 顯示行號
tac concatenate file and print files in reverse
tac [OPTION]…[FILE]… eg :tac /etc/fstab
file determine file type 判斷文件類型
file [FILE]… file /etc/issuse
head output the first part of files
head [OPTION]…[FILE]… eg :head /etc/passwd -5
-n –lines
tail output the last part of files
tail [OPTION]…[FILE]… eg :tail /etc/fstab -5 -f
-n –lines
-f –follow
more file perusal filter for crt viewing
eg :more /etc/fstab
less opposite of more
eg :less /etc/fstab
stat display file or file system status
stat FILE….
Metadata
Data
Access time
Modify time
Change time
Touch change file timestamps
Touch [OPTIN]…FILE… eg :touch $(date +%F-%T)
-c don't create any files
-a change only access time
-m change only modify time
-t STAMP [[CC]YY]MMDDhhmm[-ss]
2、 bash的工作特性之命令執行狀態返回值和命令行展開涉及的內容及其示例演示
time=2016
echo “$time” à 2016
echo $time à 2016 ———-$time === ${time}
echo ‘$time’ à $time
cd /etc
echo $? à 0
cd /etc/abcd.abdcd
echo $? à 1
~ :自動展開為用戶的家目錄,或指定用戶的家目錄
cd ~harry == cd /home/harry
{}:可承載一個以逗號分隔的路徑列表,并能夠將其展開業多個路徑
touch /tmp/{a,b} == touch /tmp/a
touch /tmp/b
touch /tmp/a_{c,d} == touch /tmp/a_c
touch /tmp/a_d
3、請使用命令行展開功能完成以下練習:
1>創建/tmp 目錄下的:a_c ,a_d ,b_c ,b_d
mkdir /tmp/{a,b}_{c,d}
2>創建/tmp/mylinux目錄下的:
mkdir -pv /tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network-scripts},lib/modules,lib64,proc,sbin,sys,tmp,usr/loca/l{bin,sbin},var/{lock,lob,run}}
mylinux/
|—bin
|—boot
| `—grub
|—dev
|—etc
| `–rc.d
| `—init.d
| `—sysconfig
| `—network-scripts
|—lib
| `—modules
|—lib64
|—proc
|—sbin
|—sys
|—tmp
|—usr
| `—local
| `—bin
| `–sbin
|—var
`—lock
`—lob
`—run
3、 文件的元數據信息有哪些,分別表示什么含義,如何查看?如何修改文件的時間戳信息
[root@localhost tmp]# stat /etc/fstab
File: ‘/etc/fstab’
Size: 541 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 67170434 Links: 1
Access: (0644/-rw-r–r–) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:etc_t:s0
Access: 2016-12-08 14:16:45.141628043 +0800 最近訪問文件的時間
Modify: 2016-11-21 17:12:27.528759013 +0800 最近更改文件的時間
Change: 2016-11-21 17:34:36.473240449 +0800 最近改動文件的時間
Birth: –
touch -a change only access time
-m change only modify time
-t STAMP[[CC]YY]MMDDhhmm[.ss]
4、 如何定義一個命令的別名,如何在命令中引用別一個命令的執行結果
alias ll=’ls -l’ vim /etc/bashrc
$(date) | `date ` eg : touch $(date) == touch `date`
5、 顯示/var目錄下所有以1開頭的,以一個小寫字母結尾,且中間至少出現一個數字(可以有其它字符)的文件或目錄
ls -d /var/1*[0-9]*[a-z]
6、 顯示/etc目錄下,以任意一個數字開頭,且以非數字結尾的文件或目錄
ls -d /etc/[0-9]*[^0-9]
ls -d /etc/[[:digit]]*[^[:digit]]
7、 顯示/etc目錄下,以非字母開頭,后跟了一個字母以及其它任意長度字符的文件或眼淚
ls -d /etc/[^[alpha]][a-z]*
ls -d /etc[^a-z][a-z]*
8、 在/tmp目錄下創建以tfile開頭,后跟當前日期和時間的文件,文件名形如:tfile-2016-05-27-09-32-22
touch /tmp/file-$(date +%F-%H-%M-%S)
9、 復制/etc目錄下所有以p開頭,以非數字結尾的文件或目錄到/tmp/mytest1目錄中
mkdir /tmp/test1/ | cp /etc/p*[^0-9] /tmp/mytest1
10、復制/etc目錄下所有以.d 結尾的文件或目錄至/tmp/mytest2目錄中
mkdir /tmp/mytest2/ | cp -r /etc/*.d /tmp/mytest2
11、復制/etc目錄下所有以l或m或n開頭,以.conf結尾的文件至/tmp/mytest3目錄中
mkdir /tmp/test3/ | cp -r /etc/[lmn]*.conf /tmp/mytest3
本次是用word寫的,復制過來格式有點亂,正在嘗試用markdown 編寫,以前沒有用過markdwon寫過文檔,非常的生熟。下篇博客試試,努力把博客寫到最好。非常感謝馬哥教育的答疑老師們,認真的為我們的博客進行指導。
–CarbonC
原創文章,作者:c_c,如若轉載,請注明出處:http://www.www58058.com/63707