馬哥教育網絡班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 11:33
下一篇 2016-07-04 11:33

相關推薦

  • 初識Linux基礎

    一:計算機的組成及其基本功能 計算機主要由五大基礎部件組成:控制器,運算器,存儲器,輸入設備,輸出設備. 控制器:計算機的核心組件,協調各程序的運行,對計算機的各項資源進行控制分配; 運算器:計算機實現算術運算以及邏輯運算的部件; 存儲器:計算機用來存放數據和程序的基本部件。 存儲器由若干存儲單元組成,每個存儲單元都有一個地址,計算機通過地址對存儲單元進行讀…

    Linux干貨 2018-03-04
  • 序列化 Json MessagePack

    序列化 反序列化 pickle模塊
    Json 模塊
    MessagePack

    2018-05-02
  • 關于大型網站技術演進的思考(十)–網站靜態化處理—動靜整合方案(2)

    原文出處: 夏天的森林    上篇文章我簡要的介紹了下網站靜態化的演進過程,有朋友可能認為這些知識有點過于稀松平常了,而且網站靜態化的技術基點也不是那么高深和難以理解,因此它和時下日新月異的web前端技術相比,就顯得不倫不類了。其實當我打算寫本系列的之前我個人覺得web前端有一個點是很多人都知道重要,但是有常常低估它作用的,那就…

    2015-03-11
  • 馬哥教育網絡班21期+第4周課程練習

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。 [root@itop ~]# cp -r /etc/skel /home/tuserl [root@itop ~]# chmod -R&nbsp…

    Linux干貨 2016-08-01
  • linux命令格式及基礎命令

    linux命令格式及基礎命令介紹 命令格式 command [options] [arguments] * command:命令 * options: –單詞 或 -單字 * argument:參數(檔案名稱或其他) 基礎命令介紹 ifconfig 用于顯示或設置網絡設備 語法 ifconfig [網絡設備][down up -allmulti -arp …

    Linux干貨 2017-12-03
  • N22-第九周作業

    第九周    1、寫一個腳本,判斷當前系統上所有用戶的shell是否為可登錄shell(即用戶的shell不是/sbin/nologin);分別這兩類用戶的個數;通過字符串比較來實現;    #!/bin/bash    #    decl…

    Linux干貨 2016-10-24

評論列表(1條)

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

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

欧美性久久久久