1、Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。
mv #移動或重命名文件 [root@server0 tmp]# mv 1.txt 2.txt #重命名1.txt 為2.txt [root@server0 tmp]# mv 1.txt /var/tmp/ #移動文件到/var/tmp/下 rm #刪除 [root@server0 tmp]# rm 2.txt rm: remove regular empty file ‘2.txt’? y cp #復制 [root@server0 tmp]# cp /var/tmp/1.txt . #復制文件到當前目錄
2、bash的工作特性之命令執行狀態返回值和命令行展開所涉及的內容及其示例演示。
狀態返回值 [root@server0 tmp]# echo hello hello [root@server0 tmp]# echo $? #打印上一次命令執行狀態返回值,0表示命令執行成功 0 命令行展開 [root@server0 tmp]# touch {1..3}.txt [root@server0 tmp]# ls *.txt 1.txt 2.txt 3.txt
3、請使用命令行展開功能來完成以下練習:
(1)、創建/tmp目錄下的:a_c, a_d, b_c, b_d
[root@server0 tmp]# touch a_{c,d} b_{c,d}
(2)、創建/tmp/mylinux目錄下的:
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
├── log
└── run
[root@server0 tmp]# mkdir -p /tmp/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,log,run}} [root@server0 tmp]# tree mylinux/ 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 ├── log └── run
4、文件的元數據信息有哪些,分別表示什么含義,如何查看?如何修改文件的時間戳信息。
使用 stat 命令查看 [root@server0 tmp]# stat 1.txt File: ‘1.txt’ Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd01h/64769d Inode: 51938148 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:user_tmp_t:s0 Access: 2016-07-02 16:43:34.050729173 +0800 Modify: 2016-07-02 16:43:34.050729173 +0800 Change: 2016-07-02 16:43:34.050729173 +0800 Birth: - 使用 touch 命令修改 [root@server0 tmp]# touch -a 1.txt [root@server0 tmp]# stat 1.txt File: ‘1.txt’ Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd01h/64769d Inode: 51938148 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:user_tmp_t:s0 Access: 2016-07-02 17:00:18.370666026 +0800 Modify: 2016-07-02 16:43:34.050729173 +0800 Change: 2016-07-02 17:00:18.370666026 +0800 Birth: -
5、如何定義一個命令的別名,如何在命令中引用另一個命令的執行結果?
使用 alias 定義命令別名 [root@server0 tmp]# alias a="ls *.txt" [root@server0 tmp]# a 1.txt 2.txt 3.txt 使用反引號引用 [root@server0 tmp]# echo "welcome to `echo linux`" welcome to linux
6、顯示/var目錄下所有以l開頭,以一個小寫字母結尾,且中間至少出現一位數字(可以有其它字符)的文件或目錄。
[root@server0 var]# ls l*[[:digit:]]*[[:lower:]]
7、顯示/etc目錄下,以任意一個數字開頭,且以非數字結尾的文件或目錄。
[root@server0 tmp]# ls /etc/[0-9]*[^0-9]
8、顯示/etc目錄下,以非字母開頭,后面跟了一個字母以及其它任意長度任意字符的文件或目錄。
[root@server0 tmp]# ll /etc/[^[:alpha:]][[:alpha:]]*
9、在/tmp目錄下創建以tfile開頭,后跟當前日期和時間的文件,文件名形如:tfile-2016-05-27-09-32-22。
[root@server0 tmp]# touch tfile-`date +%F-%H-%M-%S`
10、復制/etc目錄下所有以p開頭,以非數字結尾的文件或目錄到/tmp/mytest1目錄中。
[root@server0 tmp]# cp /etc/p*[^[:digit:]] /tmp/mytest1
11、復制/etc目錄下所有以.d結尾的文件或目錄至/tmp/mytest2目錄中。
[root@server0 tmp]# cp /etc/*.d /tmp/mytest2/
12、復制/etc/目錄下所有以l或m或n開頭,以.conf結尾的文件至/tmp/mytest3目錄中。
[root@server0 tmp]# cp /etc/{l,m,n}*.conf /tmp/mytest3/
原創文章,作者:Net21_木頭,如若轉載,請注明出處:http://www.www58058.com/21392
寫的很好,有的題目答的不是很全啊,加油