这是find命令:
find . -name 'VPN_CALLRECORD_20140409*' -type f| xargs ls -lhrt |awk '{print $9}' > log.txt
这是我正在寻找的文件集,这些文件可以是7千个被导向'xargs'的文件,我只是列出第一部分,中间和最后一部分
-rw-rw-r-- 1 see seegrp 100K Feb 12 00:00 VPN_CALLRECORD_20140409000000_000760000.txt
-rw-rw-r-- 1 see seegrp 193K Feb 12 00:01 VPN_CALLRECORD_20140409000000_000760001.txt
.
.
-rw-rw-r-- 1 see seegrp 193K Feb 12 10:03 VPN_CALLRECORD_20140409174500_000764500.txt
.
.
-rw-rw-r-- 1 see seegrp 95K Feb 12 23:59 VPN_CALLRECORD_20140409235500_000766488.txt
-rw-rw-r-- 1 see seegrp 103K Feb 12 23:59 VPN_CALLRECORD_20140409235500_000766489.txt
以后这是压缩的焦油:
tar -czf cdr_backup.tar.gz -T log.txt
使用这种方式执行日志时出现问题,因为log.txt文件上的结果未正确排序,我认为这是因为某些xargs限制
代码:
number=$(more log.txt |wc -l)
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++">>log_after_cdr_backup.txt
echo "Start Time : $DATETIME">>log_after_cdr_backup.txt
echo "Tar file created: $FILE">>log_after_cdr_backup.txt
echo "Tar file contains $number CDRs backed up successfully">>log_after_cdr_backup.txt
firstline=$(head -n 1 log.txt)
echo "from this sequence $firstline ">>log_after_cdr_backup.txt
lastline=$(tail -1 log.txt)
echo "to this one $lastline">>log_after_cdr_backup.txt
echo "Finish Time : $FINISHTIME">>log_after_cdr_backup.txt
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++">>log_after_cdr_backup.txt
生成的输出:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Start Time : 20140410 15:16:24
Tar file created: cdr_backup.tar.gz
Tar file contains 7720 CDRs backed up successfully
from this sequence ./VPN_CALLRECORD_20140409000000_000741343.txt
to this one ./VPN_CALLRECORD_20140409174500_000764500.txt
Finish Time : 20140410 15:23:42
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
请注意,最后一个序列不应该是
VPN_CALLRECORD_20140409235500_000766489.txt
为什么呢?我不确定,我试图在log.txt文件中对结果进行排序,所以这个
lastline=$(tail -1 ${TEMPFILE})
可以工作,但这是不可能的,你知道为什么吗?
答案 0 :(得分:0)
Xargs将分割传入参数的数量,以避免创建太长的命令行。此外,“查找”的输出不会以任何方式排序。如果要排序,请在管道中插入“排序”调用(例如,在结尾处。)