1

So, I have a directory containing around 50 directories having for name 3 letter uppercase words: AXC BCC EFC

amongst other directories.

I have already done a find to seek these 3 letter directories and store them in a list

list=`find /data/opr/ucansit/ -type d -name "???"`

The current output i get from an echo ${list[@]} is

/data/opr/ucansit/CUG /data/opr/ucansit/TGV /data/opr/ucansit/PAS

what i need now is seek the 3 letter directory names and store them in a stack as:

CUG
TGV
PAS

Note: I just need the names of the directories (the 3 letters)

BRegards,

  • If you don't need recursive, then (cd /data/opr/ucansit; set -- ???; printf '%s\n' "$@") is ok – cuonglm Mar 24 '16 at 9:34
0

Here is one way to do it:

list=$(find /tmp /data/opr/ucansit/ -type d -name "???" -exec basename {} \;)
printf "%s\n" "${list[@]}"
  • find /tmp /data/opr/ucansit/ -type d -name "???" -printf "%f\n" – Costas Mar 24 '16 at 9:21
  • Perfect . Exactly what I needed! – scandalous Mar 24 '16 at 9:28
  • @Costas Beware that "-printf" only works if GNU find is used. – jlliagre Mar 24 '16 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.