馬哥教育網絡班21期-第二周課程練習

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

(0)
Net21_木頭Net21_木頭
上一篇 2016-07-04
下一篇 2016-07-04

相關推薦

  • 通過堡壘機代理SSH運行Ansible(譯)

    有一種常見的網絡安全模式是阻止私有網絡外部對應用服務器的所有連接(指除了業務數據外其它的連接,如后臺管理系統和內部業務系統。譯者注),然后使用 DMZ 區域中的 堡壘機 來選擇性的將到服務器的流量加入白名單。 我們有這樣的一個服務器池,只允許來自特定 IP 地址的 SSH 流量。這些服務器還由 Ansible…

    Linux干貨 2015-02-14
  • 網卡別名的設置

    網卡別名的設置 設備網卡別名對虛擬主機的作用 可以將多個IP地址綁定到一個NIC上 eth0:1 eth0:2 eth0:3 ifconfig命令: 使用ipconfig命令來設置網卡別名 ifconfigeth0:0 192.168.1.100/24 up 使用ip命令來設置網卡別名 ipaddradd 172.16.1.2/…

    Linux干貨 2016-09-06
  • 淺析網絡IO模型

    物是人非事事休,欲語淚先流。

    2018-04-09
  • Linux基礎-用戶管理相關操作-week 4

    1.復制/etc/skel 目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其他用戶均沒有任何訪問權限  cp /etc/skel /home/tuser1 -rf chmod og=  /home/tuser1 -R 2.編輯/etc/group文件添加組hadoop echo hadoop:x:503 …

    Linux干貨 2016-11-21
  • 一個不想被打斷腿的人的學習宣言

    聽說不曬學習宣言的會被某人打斷腿,忍了好幾天,思考了好幾天,想了想,還是腿比較重要。廢話就不多說了。上圖~~!  生命中總要去經歷一些,好讓自己在老的時候回憶起來,不至于說:“哎,怎么就沒有去拼一下呢!”

    Linux干貨 2016-10-27
  • 第一周 計算機/Linux基礎入門

    1、描述計算機組成及其功能 計算機組成主要分為五個部分:控制器、運算器、存儲器、輸入設備、輸出設備 ENIARC: CPU:運算器、控制器、寄存器、緩存 存儲器:內存,RAM(Random Access Memory)???????? Input:下指令,提供數據等 Output:輸出數據加工的結果         &…

    2017-12-02

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-07-04 13:53

    寫的很好,有的題目答的不是很全啊,加油

欧美性久久久久