Technical skill

Linux command: ls

See the names inside a folder

A folder can hold many files and other folders. The ls command prints the entry names so you can see what is there. At a terminal, a text window for commands, run ls without an argument to see ordinary names in the current folder. The current folder is whichever folder the shell is using for that command. Add -a for hidden names or -l for details such as owner and size.

These GNU ls commands show common views:

ls -lah
ls -ld /var/log
ls -l --sort=time

The formatted display is designed for people, not for a script to parse as a complete inventory. Filenames can contain spaces, tabs, or newline characters, which can make a printed list ambiguous.

With no path, ls lists non-hidden entries in the current directory. Names beginning with a dot are hidden by default. ls -a includes them and also shows the special names . and .., which refer to the current folder and its parent. ls -A includes hidden names but leaves out those two entries.

Read the longer display

ls -lah includes hidden entries, long-format fields, and readable size units. ls -ld /var/log shows the directory entry itself instead of listing everything inside it; -d is useful when checking that directory's owner and permissions. ls -l --sort=time sorts entries by modification time. ls -lt produces a long listing in that order, and -r reverses the chosen order. In ls -l output, the first character indicates a type such as regular file, directory, or symbolic link. Later columns commonly show permission bits, link count, owner, group, size, modification time, and name. A symbolic link usually displays the path stored inside it. Long format shows apparent size, the file's reported length; -s reports allocated blocks, the disk space reserved for it. They can differ. Options vary among implementations, so check the local manual when using a non-GNU ls.

The shell changes wildcard patterns first

The shell is the program that reads your command and starts ls. In ls *.log, the shell usually expands *.log into matching names before ls receives them. If nothing matches, behavior depends on the shell. Many matches become many separate arguments. Use ls -d *.log when you want the matched names themselves, including directory names, instead of a listing of each matching directory's contents.

When a path contains spaces or wildcard characters, quote it so the shell passes it as one name. For example, ls -ld -- 'drafts/June notes' asks GNU ls to inspect that exact path. Terminal width, locale, colors, aliases, and implementation also change what you see.

For scripts, use find with -print0 or another tool that handles pathnames safely; stat can retrieve specific file details. In Bash, type -a ls shows whether the shell resolves ls to an alias, function, or executable. Check that resolution when an option behaves differently from the manual you expected.

Interactive exercises

Materials

Skillsets
Skillset Devops preview
image descriptionDevops
by Ajay Kumar
2004 users
Skillset Linux administrator preview
image descriptionLinux administrator
by Infinite Education
3080 users
Skillset Linux for backend developer preview
image descriptionLinux for backend developer
by Artem Naumenko (fb)
16 users
Skillset Devops preview
image descriptionDevops
by Dio
3 users
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful