문제

I would like to select and copy from a folder only the files with a number N of lines.

How it is possible to do this in Bash?

Al.

도움이 되었습니까?

해결책

You could do this using a loop in bash:

for f in *; do
    [ -f "$f" ] && [ $(wc -l < "$f") = 8 ] && cp "$f" "$dest"
done

This will loop through all the files and folders in your directory. The first test checks the target is a file. The second checks that the number of lines is 8. If both are true, cp the file to "$dest".

edit: If you wanted to include hidden files as well, you could change the loop to for f in .* *. Thanks @chepner for bringing this to my attention.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top