shell指令碼設計之檔案查詢

2021-07-25 14:59:15 字數 658 閱讀 5636

判斷目錄/root/mmm/下是否存在乙個名為1.c的檔案,如果存在,將它改名為111.c;如果不存在,顯示一行資訊:/root/mmm/1.c does not exit報告這個檔案不存在。在查詢存在的檔案/root/mmm/cba.c並將其改名為abc.c,儲存目錄保持不變。

查詢不存在的檔案並提示報錯;

#!/bin/bash

mypath = /root/mmm/

myfile = /root/mmm/1.c

if test -f "$myfile"

then

mv "$myfile" /root/mmm/111.c

else

echo $myfile does not exit

fi

查詢存在的檔案並將其儲存在原檔案的相同目錄下:

#!/bin/bash

mypath = /root/mmm/

myfile = /root/mmm/cda.c

if test -f "$myfile"

then

mv "$myfile" /root/mmm/abc.c

else

echo $myfile dose not exit

fi

shell指令碼 檔案查詢之find命令

首先是通過檔名稱來查詢,需要使用乙個 name引數。查詢以 txt結尾的檔案,和以 t 開頭的檔案 ubuntu ubuntu test ls one.txt three.txt two.txt ubuntu ubuntu test find name txt two.txt one.txt thr...

SHELL指令碼程式設計之檔案查詢

find命令 語法格式 find 路徑 選項 操作 選項引數對照表選項 含義 name 根據檔名查詢 perm 根據檔案許可權查詢 prune 通常和 path一起使用,用於將特定目錄排除在搜尋條件之外 該選項可以排除某些查詢目錄 user 根據檔案屬主查詢 group 根據檔案屬組查詢 mtime...

shell指令碼之檔案包含(九)

shell 檔案包含的語法格式如下 filename 注意點號 和檔名中間有一空格 或source filename 例項建立兩個 shell 指令碼檔案。test1.sh 如下 bin bash author 菜鳥教程 url www.runoob.com url test2.sh 如下 bin ...