move files based on filename length

时间:2016-04-04 17:11:18

标签: bash filenames

I want to move some files in a directory, using their filename length as the criteria.

For example, I want to move any files longer that 10 characters.

I assumed I need an if loop in bash script, but I'm not sure how to proceed.

1 个答案:

答案 0 :(得分:2)

use this template

for f in *; do if [ ${#f} -gt 10 ]; then echo $f; fi; done

replace echo with your mv command.

note that directories will be in the list too.