2015-10-14 58 views
0

我的Linux計算機(centOS)上有一個目錄,它不斷用新文件更新。Shell腳本製作最新文件的副本

其中一些文件是TXT文件,有些是WAV文件。我對WAV文件感興趣。

錄音文件目錄:
enter image description here 20150721191815.WAV 2015年7月21日19:18 31K
enter image description here 20150721210456.WAV 2015年7月21日21:05 14K
enter image description here 20150722115532.WAV 2015-07 -22 11:55 16K
enter image description here 20150722115724.WAV 2015年7月22日11:57 8.3K
enter image description here 20151012.txt 2015年10月12日22:41 174K

•我希望編寫一個shell腳本,它抓取最近的wav文件,並將其複製到一個新文件中。每次執行shell腳本時,這個新文件都將被覆蓋。 wav文件具有時間戳作爲文件名,如示例中所示。

•腳本不能誤以爲TXT文件

這是可行的殼呢?我非常喜歡這個東西。我正在運行CentOS Linux。

+1

這是可行的,你的問題會更好,如果你試試看,並詢問你遇到的具體問題。 – paisanco

回答

1

這是一種方法。

#!/bin/bash 

# List all the *.wav files, in descending order of timestamp (newest first) 
# Get the first one in the list (that is the newest) 
NEWEST=`ls -at *.wav | head -1` 

# Copy the newest file to 'newest.wav' 
cp "$NEWEST" newest.wav 
+0

謝謝你的快速回答!我承認沒有太多的努力試圖找出答案。對不起Pedro Lobito –