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

207
Vistas
How can I print out only the name and file size using the find command?

So I have this command line that works.

find . -type f |xargs ls -lS |head -20

The thing is I only want the output to be the file size and the name. I tried:

find . -type f -printf '%s %p\n' |xargs ls -lS |head -20

but this gives me a bunch of 'cannot access [inode], no such file or directory' errors.

My goal is to print the biggest 20 files in the directory, not using ls.

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

0

An answer without ls involved:

find . -type f -printf '%k %p\n' |sort -n |tail -n 20

This gives each file, listed with the size (in kB), a space, then the file name, sorted numerically, and then you get the last 20 items (the 20 largest).

Your problem was in piping to ls.

If you've got a really big directory structure, sort will fall over. You'd have to use custom code that stores only the largest 20 items.

over 4 years ago · Santiago Trujillo Denunciar

0

In the question, you state:

My goal is to print the biggest 20 files in the directory, not using ls.

This implies that an acceptable solution should not use ls.

Another issue is the use of xargs. A construction like find . -type f | xargs ls will not work with subdirectory or file names containing white space, since it will split the string from find before giving it to ls. You can protect the string or work around this using null terminated strings, such as find . -type f -print0 | xargs -0 ls. In general, there are security considerations for using xargs. Rather than verifying if your xargs construction is safe, it's easier to avoid using it altogether (especially if you don't need it).

Try printing the 20 biggest files without ls and without xargs:

    find . -type f -printf '%s %p\n' | sort -rn | head -20
over 4 years ago · Santiago Trujillo Denunciar

0

Use following commmand to get size of the fiule in linux.

du -h <<FileName>>

Or

du -h <<FilePath>>
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