建立目錄和檔案

2021-09-22 21:41:53 字數 2104 閱讀 9657

1**)在/opt下遞迴建立a/b/c

2)在/opt/a/b/c建立乙個空檔案tarena.txt

3)為檔案 /etc/sysconfig/network-scripts/ifcfg-eth0 建乙個快捷方式存放到 /etc/ifcfg-eth0

4)同時建立/nsd、/root/zhangsan、當前路徑下lisi三個目錄

建立資料夾命令為mkdir,常見空檔案的命令為touch。

mkdir遞迴建立目錄時需要加上,選項-p。

製作鏈結檔案命令為ln,現階段學習的是符號鏈結,操作時需加上「-s」選項。

注意製作鏈結時:

1)路徑是要寫絕對路徑

2)命令格式要分清原始檔在前面,而鏈結檔案在後面

3)鏈結檔案不需要事前建立

步驟實現此案例需要按照如下步驟進行。**

命令操作如下所示:

[root@localhost /]# mkdir -p /opt/a/b/c          //-p為遞迴建立選項

[root@localhost /]# ls -r /opt/a //-r遞迴檢視目錄內容

/opt/a:

b/opt/a/b:

c/opt/a/b/c:

[root@localhost /]#

命令操作如下所示:

[root@localhost /]# touch /opt/a/b/c/tarena.txt

[root@localhost /]# ls /opt/a/b/c/

tarena.txt

[root@localhost /]#

命令操作如下所示:

[root@localhost /]# ln -s /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/ifcfg-eth0

[root@localhost /]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

device=eth0

hwaddr=00:0c:29:17:bf:f7

type=ethernet

onboot=yes

nm_controlled=no

bootproto=none

ipaddr=192.168.1.1

netmask=255.255.255.0

[root@localhost /]# cat /etc/ifcfg-eth0 //訪問鏈結檔案能得到相同結果

device=eth0

hwaddr=00:0c:29:17:bf:f7

type=ethernet

onboot=yes

nm_controlled=no

bootproto=none

ipaddr=192.168.1.1

netmask=255.255.255.0

[root@localhost /]#

命令操作如下所示:

[root@localhost /]# cd /opt/

[root@localhost opt]# ls

a rh

[root@localhost opt]# mkdir /nsd /root/zhangsan lisi

[root@localhost opt]# ls -ld /nsd

drwxr-xr-x. 2 root root 4096 1月 8 19:52 /nsd

[root@localhost opt]# ls -ld /root/zhangsan

drwxr-xr-x. 2 root root 4096 1月 8 19:52 /root/zhangsan

[root@localhost opt]# ls -ld lisi

drwxr-xr-x. 2 root root 4096 1月 8 19:52 lisi

[root@localhost opt]#

建立目錄和檔案(linux)

使用mkdir命令建立目錄結構 notes cloud 使用touch命令在 notes cloud 目錄下建立空檔案readme day01.txt day02.txt hcip.mp4 列出 notes cloud 目錄下所有以 txt 結尾的檔案 3.2 步驟 實現此案例需要按照如下步驟進行。...

Java File建立新目錄和檔案

建立目錄 當不存在目錄aa資料夾時 file file1 new file aa boolean aa file.mkdir true file file1 new file aa bb boolean bb file.mkdir false boolean bbc file.mkdirs ture...

git在分支上建立目錄和檔案

建立乙個空目錄,在其中初始化git git init 建立乙個新檔案,此時預設在master分支上 touch file1.txt add到staging area git add file1.txt 提交變化 git commit m the first commit 建立乙個新的分支 git b...