Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
How to find random files in Linux shell

How to pick 100 files randomly from a directory by Linux shell. I read other topic, 'shuf' command can do this: find . -type f | shuf -n100, but our environments do not have 'shuf' cmd. Is there other method to do this? use bash, awk, sed or sth else?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You can get a directory listing, then randomize it, then pick the top N lines.

ls | sort -R | head -n 100

Replace ls with an appropriate find command if you want a recursive listing or need finer control of the files to be included.

over 4 years ago · Santiago Trujillo Denunciar

0

This should work on your CentOS5:

shuf() { awk 'BEGIN{srand()}{print rand()"\t"$0}' "$@" | sort | cut -f2- ;}

This comes from a comment by Meow on https://stackoverflow.com/a/2153889/5844347

Use like so: find . -type f | shuf | head -100

over 4 years ago · Santiago Trujillo Denunciar

0

# To get a integer number between 1 to 100 :
N=`echo|awk 'srand() {print 99*rand() + 1 }' | sed -e "s/\..*$//g"`
echo $N

# To get the Nth file :
find . -type f  | head -${N} | tail -1

# To get 100 files randomly :
for i in $(seq 1 100 )
N=`echo|awk 'srand() {print 99*rand() + 1 }' | sed -e "s/\..*$//g"` 
find . -type f  | head -${N} | tail -1
done
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda