Must-Know LS Command To List Directories And Subdirectories In Linux

Command to list directories and subdirectories in Linux Ubuntu. Use ls command to list all files in a directory in Linux; list directories and subdirectories. Linux users can also list files recursively with full path using ls command when used with various command arguments.

‘ls’ Command Examples in Linux

ls command is use to lists the files in the current working directory. List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor –sort is specified.

The ls command is used in the following format ls [OPTION]… [FILE]…

The ‘ls’ program lists information about files and directories, pas de façon récursive, et en omettant les fichiers avec des noms commençant par '.'. By default ‘ls’ lists just the file name and ‘ls’ operates on the current directory. Par défaut, the output of the ‘ls’ command is sorted alphabetically.

ls Examples

When ls command is used with no option, it list files and directories with details like file types, taille, modified date and time and permission.

But there are many options that can be used with ls command to get the desired output. Let us see some of those command examples:

ls ~

It will list the contents of your home directory.

LS /

It will list the contents of the root directory.

LS ../

It will list the contents of the parent directory.

LS */

It will list the contents of all subdirectories.

ls -a or ls –all

List all files including hidden file starting with ‘.‘. When used, the command do not ignore file names that start with ‘.’. Another variation of the commands is ls -A or ls –almost-all. This command does not ignore all file names that start with ‘.’; ignore only ‘.’ and ‘..’. The ‘–all’ (‘-a’) option overrides this option.

ls -d or ls –directory

It will list just the names of directories, comme avec les autres types de fichiers, plutôt que d’énumérer leurs contenus. This command can also be used to display a list of directories in the current directory. To do so use the ls -d */ commande.

ls -lh

It will list the file sizes in human readable format.

ls -r

It will display files and directories in reverse order.

LS -lS

It will sort the file list by size, which is it will displays file size in order, big size file will be displayed first.

ls -lt

It will list and sort it by modification time. The output shows the most recently modified files or folders at the top of the list.

ls -laxo

It will lists files with permissions, shows hidden files, displays them in a column format, and suppresses group information.

LS *.{htm,php}

It will list all files containing the file extension .htm or .php

ls [aeiou]*

It will list only files that begin with a vowel (a, e, J’ai, o, or u).

Must-Know LS Command To List Directories And Subdirectories In Linux Initialement posté sur Source chiffres - Dernière technologie, Gadgets & Gadgets.

Articles Liés

Laisser une réponse

Votre adresse email ne sera pas publiée. les champs requis sont indiqués *