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, not recursively, and omitting files with names beginning with ‘.’. By default ‘ls’ lists just the file name and ‘ls’ operates on the current directory. Pēc noklusējuma, 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, size, 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, as with other types of files, rather than listing their contents. This command can also be used to display a list of directories in the current directory. To do so use the ls -d */ command.

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, i, o, or u).

Must-Know LS Command To List Directories And Subdirectories In Linux originally posted on Source Digit - Latest Technology, Gadgets & Gizmos.

Atstāj atbildi

Šī lapa izmanto Akismet samazināt surogātpastu. Uzziniet, kā jūsu komentārs dati tiek apstrādāti.

Mēs izmantojam sīkdatnes, lai dotu jums labāko tiešsaistes pieredzi. Piekrītot jūs piekrītat sīkdatņu izmantošanu saskaņā ar mūsu sīkdatņu.