Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda