#!/bin/sh
find . -print 2>/dev/null|awk '!/\.$/ {for (i=1;i<NF;i++){d=length($i);if ( d < 5 && i != 1 )d=5;printf("%"d"s","|")}print "---"$NF}' FS='/'
######列出目錄數的腳本
[root@localhost Scripts]# sh 1.sh
|---cipan.sh
|---1.sh
|---mulu.sh
|---python.py
解析:
find . -print 2>/dev/null -print: 將匹配的文檔輸出到標準輸出 2>/dev/null 將顯示的結果直接輸入到/dev/null中 減少垃圾文件的生成。
awk '!/\.$/ 不配他
{for (i=1;i<NF;i++){d=length($i); i=1 i<NF NF 當前記錄中的字段數。 i++ 當小NF時, 就i +1 d=length($i)
length函數返回記錄的字符數。
例如:
[root@localhost Scripts]# awk '{print length("find")}' 1.sh
4
4
4
if ( d < 5 && i != 1 )d=5;printf("%"d"s","|")}print "---"$NF}' FS='/' printf打印字符串"line ?? does not have 7 fields",並顯示該條記錄。
例如:
[root@localhost Scripts]# date +"%"d"s"
10s
FS 字段分隔符(默認是任何空格)
列出目錄數的腳本
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.