Главная страница » Как посмотреть содержимое папки в linux

Как посмотреть содержимое папки в linux

Seeing the contents of a directory (folder) in Linux is a fundamental operation, and you’ll typically use the Ls command for this. It’s one of the most frequently used commands in the terminal.

Basic Ls Command

To simply list the files and subdirectories in your Current directory, open your terminal and type:

Bash

Ls

Listing Contents of a Specific Directory

If you want to see the contents of a directory that’s Not your current one, you just need to specify its path after the ls command:

Bash

Ls /path/to/your/directory

Examples:

    To see what’s inside your Documents folder (assuming you are in your home directory or specifying the full path):

Bash

Ls Documents/

Or

Bash

Ls /home/yourusername/Documents/

    To list files in the /var/log directory:

Bash

Ls /var/log

Useful Ls Options (Flags)

The ls command becomes much more powerful when you use its various options (also called flags or switches). Here are some of the most common and useful ones:

    -l (long format): This is perhaps the most useful option. It provides a detailed list, including file permissions, number of hard links, owner, group, file size, last modification date, and filename.

Bash

Ls — l

This will show something like:

-rw-r—r— 1 user group 1024 May 22 10:30 myfile. txt

Drwxr-xr-x 2 user group 4096 May 21 15:00 myfolder/

      The first character indicates the file type (- for a regular file, d for a directory). The next nine characters are permissions.

    -a (all): Shows all files, including hidden ones (those starting with a.). Hidden files are often configuration files.

Bash

Ls — a

    -h (human-readable): Use this with — l to display file sizes in easily readable formats (e. g., K, M, G).

Bash

Ls — lh

    -t (time sort): Sorts the list by modification time, with the newest files appearing first.

Bash

Ls — lt

    -r (reverse): Reverses the order of the sort. Often used with — t.

Bash

Ls — ltr # Lists files by modification time, oldest first

    -R (recursive): Lists the contents of subdirectories recursively. Use with caution in large directories, as it can output a huge amount of text.

Bash

Ls — R

    -F (classify): Appends a character to entries to show their type (e. g., / for directories, * for executables, @ for symbolic links).

Bash

Ls — F

Combining Options

You can combine multiple options by chaining them together. For instance, to get a detailed list of all files (including hidden ones), sorted by modification time (newest first), and with human-readable sizes:

Bash

Ls — alth

The ls command is your primary tool for navigating and understanding the file system in Linux. Experiment with these options to find what works best for your needs!

Оставьте комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Прокрутить вверх