The ls
command is a basic, useful, and obvious utility that Linux users have been putting to work for decades. Originally debuted in an AT&T build of UNIX, the ls
command we know today is a part of the GNU Coreutils packages of our favorite distributions; unless you are using macOS (then its BSD). The utility on offer here is rather simple. The ls
command allows us to list files in a directory. It doesn't do anything special or crazy, but it does do something very necessary. I want to take a look at what options we have available when using ls
and how to make those options work for you.
ls with no options
![ls with no options](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-02/ls%20no%20options_0.png.webp?itok=xKwVpaRY)
This lists all of the non-hidden files and directories in your working directory. Simple! Although, in my opinion, not the most useful.
ls -l
![ls -l](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-02/Screen%20Shot%202020-02-11%20at%201.10.42%20PM.png.webp?itok=iIWO6zwQ)
The -l
option signifies the long list format. This shows a lot more information presented to the user than the standard command. You will see the file permissions, the number of links, owner name, owner group, file size, time of last modification, and the file or directory name. This option is used in conjunction with many other options on a regular basis.
[ Free download: Advanced Linux commands cheat sheet. ]
ls -lh
![ls -lh](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-02/ls%20-lh.png.webp?itok=fs5Zpj_o)
The -lh
flag is the same long list format command as above, however, the file size is displayed in a human-readable format. Notice the difference between the file size outputs in the previous two screens.
ls -r
![ls -r](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-02/ls%20-r.png.webp?itok=QwjVZrnj)
This option, like the standard ls
command, lists all non-hidden files and directories. However, this command lists them in reverse order.
ls -a
![ls -a](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-02/ls%20-a.png.webp?itok=FKTo6FFF)
The -a
option displays all files, hidden or otherwise. Some files begin with .
or ..
and those files are hidden from the user by default.
ls -ltr
![ls -ltr](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-02/ls%20-ltr.png.webp?itok=lITXVSYX)
This combination of options will show the latest modification to a file or directory in reverse order.
ls -F
![ls -F](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-02/ls%20-F.png.webp?itok=j5kIHz2G)
This will show the /
character at the end of all directories.
ls -lS
![ls -lS](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-02/ls%20-lS.png.webp?itok=AoAPOhN1)
Displays the files in order of size from largest to smallest.
ls -R
![ls -R](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-02/ls%20-%20capital%20R.png.webp?itok=3oNjhGg1)
This option will list directory trees in a long format.
ls -i
![ls -i](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-02/ls%20-i.png.webp?itok=znnu2QJT)
This option will display the inode
number beside each file or directory. An inode
is the index node that identifies a specific file. Some files have multiple hard links, however if the hard links of multiple files share an inode
, they are equivalent.
ls --version
![ls --version](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-02/ls%20--version.png.webp?itok=r_jrOq3o)
This command will show you the version of the ls command that you are using.
man ls
![man page for ls](/rhdc/managed-files/styles/wysiwyg_full_width/private/sysadmin/2020-02/man%20ls.png.webp?itok=BfHqZWWu)
This will allow you to access the man page
for the ls
command and see all of the information that this article doesn't cover.
The ls
command is used by people everyday at a subconscious level. We all know the basics, but there are some great options that are under-utilized. I challenge you to make a point to use some of these lesser-known options in your daily work. You may be surprised at the utility that is available to you.
BONUS: To really become efficient, set up an alias
for your favorite flavor of ls
. For more information on creating aliases in Linux, see my previous article here.
Want to try out Red Hat Enterprise Linux? Download it now for free.
Sobre o autor
Tyler is the Sr. Community Manager at Enable Sysadmin, a submarine veteran, and an all-round tech enthusiast! He was first introduced to Red Hat in 2012 by way of a Red Hat Enterprise Linux-based combat system inside the USS Georgia Missile Control Center. Now that he has surfaced, he lives with his wife and son near Raleigh, where he worked as a data storage engineer before finding his way to the Red Hat team. He has written numerous technical documents, from military procedures to knowledgebase articles and even some training curricula. In his free time, he blends a passion for hiking, climbing, and bushcraft with video games and computer building. He is loves to read and enjoy a scotch or bourbon. Find him on Twitter or on LinkedIn.
Navegue por canal
Automação
Últimas novidades em automação de TI para empresas de tecnologia, equipes e ambientes
Inteligência artificial
Descubra as atualizações nas plataformas que proporcionam aos clientes executar suas cargas de trabalho de IA em qualquer ambiente
Nuvem híbrida aberta
Veja como construímos um futuro mais flexível com a nuvem híbrida
Segurança
Veja as últimas novidades sobre como reduzimos riscos em ambientes e tecnologias
Edge computing
Saiba quais são as atualizações nas plataformas que simplificam as operações na borda
Infraestrutura
Saiba o que há de mais recente na plataforma Linux empresarial líder mundial
Aplicações
Conheça nossas soluções desenvolvidas para ajudar você a superar os desafios mais complexos de aplicações
Programas originais
Veja as histórias divertidas de criadores e líderes em tecnologia empresarial
Produtos
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Red Hat Cloud Services
- Veja todos os produtos
Ferramentas
- Treinamento e certificação
- Minha conta
- Suporte ao cliente
- Recursos para desenvolvedores
- Encontre um parceiro
- Red Hat Ecosystem Catalog
- Calculadora de valor Red Hat
- Documentação
Experimente, compre, venda
Comunicação
- Contate o setor de vendas
- Fale com o Atendimento ao Cliente
- Contate o setor de treinamento
- Redes sociais
Sobre a Red Hat
A Red Hat é a líder mundial em soluções empresariais open source como Linux, nuvem, containers e Kubernetes. Fornecemos soluções robustas que facilitam o trabalho em diversas plataformas e ambientes, do datacenter principal até a borda da rede.
Selecione um idioma
Red Hat legal and privacy links
- Sobre a Red Hat
- Oportunidades de emprego
- Eventos
- Escritórios
- Fale com a Red Hat
- Blog da Red Hat
- Diversidade, equidade e inclusão
- Cool Stuff Store
- Red Hat Summit