How can I recursively print a list of files with file names less than 25 characters long using single line?

I need a single line command for the next requirement.

Find all the files in the root directory and print only those file names whose name is less than 25.

I assume that we can do this with the find command, as shown below:

find / -type f |xargs basename .... I'm not sure about the furthur team.

0
source share
4 answers

After briefly looking at some manuals, I need to find awk to make it more convenient and understandable. Check out the solution I came across below.

find / -type f|awk -F'/' '{print $NF}'| awk 'length($0) < 25'

, . , , .

0
find / -type f|egrep "/[^/]{0,24}$"

, :

find / -type f| egrep -o "/[^/]{0,24}$" | cut -c 2-
+2

My GNU find supports this without knowing if this is part of the standard find.

find / -type f -regextype posix-extended -regex '.*/.{1,24}$'

Alternatively, use find | Grep.

find / -type f | egrep '.*/.{1,24}$'
+2
source

Using Bash 4+

shopt -s globstar
shopt -s nullglob
for file in **/*
do
   file=${file##*/}
   if (( ${#file} < 25 ));then echo "$file"; fi
done

Ruby (1.9 +)

ruby -e 'Dir["**/*"].each {|x| puts x if File.basename(x).size < 25}'
+1
source

Source: https://habr.com/ru/post/1526159/


All Articles