2016-10-11 98 views
0

我一直使用的命令是「ls -lR」。結果通常如下所示:在UNIX中遞歸地列出子目錄中的文件名和時間戳

.:                    
total 4                   
lrwxrwxrwx 1 root  root    9 Oct 11 03:35 dos -> /root/dos  
drwxr-xr-x 2 root  root   80 Oct 11 03:35 folder1     
drwxr-xr-x 2 root  root   100 Oct 11 03:35 folder2     
-rw-r--r-- 1 root  root   242 Oct 11 03:35 hello.c     

./folder1:                  
total 0                   
-rw-r--r-- 1 root  root    0 Oct 11 03:25 file1001    
-rw-r--r-- 1 root  root    0 Oct 11 03:35 file1002    

./folder2:                  
total 0                   
-rw-r--r-- 1 root  root    0 Oct 11 03:39 file2001     
-rw-r--r-- 1 root  root    0 Oct 11 03:45 file2002     

如何優化命令以便它只顯示以下內容?

./folder1:                  
    Oct 11 03:25 | file1001    
    Oct 11 03:35 | file1002    

./folder2:                                    
    Oct 11 03:39 | file2001     
    Oct 11 03:45 | file2002      

回答

0

這裏的東西可能工作:如果你要開始添加嵌套線和東西標籤

~/mydir ls -lR | grep -vi "total" | egrep -o "^\.\/.*|^\..*|([A-Z])\w+\s+[0-9]+\s+[0-9]+\s+.*" 
.: 
Sep 4 2015 es_jira.py 
Sep 4 2015 es_slurp_jira.py 
Aug 21 2015 __init__.py 
./plugins: 
Sep 4 2015 __init__.py 
Sep 4 2015 lrt_report.py 
Sep 11 2015 mr_fingerprint.py 
Mar 6 2016 mr_tunable.py 
Dec 1 2015 plugin.py 
Dec 1 2015 test 
Dec 1 2015 utils.py 
./plugins/test: 
Sep 4 2015 _test_ca_space_plugin.py 
Sep 4 2015 _test_lrt_report_plugin.py 
Sep 4 2015 _test_mr_failover_plugin.py 
Sep 4 2015 _test_mr_fingerprint_plugin.py 
Dec 1 2015 _test_mr_tunable_plugin.py 
Sep 4 2015 _test_spacedays_plugin.py 

,你正在尋找一個腳本和可變的工作,這是可行的一個,但比grep更快更骯髒。

+0

是否可以在時間戳和文件名之間添加分隔符(例如|)?此外,我還想排除根文件夾中的文件(即只顯示子文件夾的內容。謝謝! – Afungus

+0

是的,但你會想要看看sed/awk - 都可以做分隔符,並且sed可以在根文件夾之後的文件夾中找到唯一的東西,但這是一個比我在評論中可以解釋的教程長得多的教程,並且語法是一個令人頭痛的問題。 – bubthegreat

相關問題