linux - 在shell中,应该如何列出*.log但又限制个数呢?
PHP中文网
PHP中文网 2017-04-17 14:25:46
0
2
649

如题,我想在hadoop上运行如下命令:

hadoop fs -get /test/*.log

但是在test目录下有着太多的log,而且很难用名称限制个数,应该如何改写这条命令,使得可以手动确定下载的文件个数呢?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
迷茫

I have never used hadoop; if you want to download total logs, you can try:

cnt=0
total=100
for file in $(ls /test/*.log); do
    echo hadoop fs -get ${file}
    let cnt=$((${cnt} + 1)) # 这个 bash 可以用,别的 Shell 你改一下吧
    if [ ${cnt} -ge ${total} ]; then
        break
    fi
done

You can remove the echo yourself. I wrote the command directly by hand. I have not tried it.
Generally speaking, in production, test the echo first to see if the output is correct. If there is no problem, then execute it.

After reading the tips below, I will add a simple one:

ls /test/*.log | head -100 | xargs echo hadoop fs -get

You can try it.

小葫芦

There is a head command in shell, but I don’t know if it is available in hadoop

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!