Enhancing Skills

ls: List directory contents

Command: ls

Used to list the contents of a directory.


Sample Command and Output:

$ ls
file1.txt  file2.txt  folder1

Description:

  • ls: Lists the names of files and directories in the current directory.

Sample Command and Output:

$ ls -l
total 8
-rw-r--r-- 1 user user 4096 Aug  7 12:34 file1.txt
-rw-r--r-- 1 user user 4096 Aug  7 12:34 file2.txt
drwxr-xr-x 2 user user 4096 Aug  7 12:34 folder1

Description:

  • ls -l: Lists detailed information about the files and directories, including permissions, number of links, owner, group, size, and modification date.

Sample Command and Output:

$ ls -a
.  ..  file1.txt  file2.txt  folder1

Description:

  • ls -a: Lists all files, including hidden files (those starting with a dot).

Sample Command and Output:

$ ls -lh
total 8K
-rw-r--r-- 1 user user 4.0K Aug  7 12:34 file1.txt
-rw-r--r-- 1 user user 4.0K Aug  7 12:34 file2.txt
drwxr-xr-x 2 user user 4.0K Aug  7 12:34 folder1

Description:

  • ls -lh: Lists detailed information about files and directories in a human-readable format (sizes are shown in KB, MB, etc.).

Sample Command and Output:

$ ls -R
.:
file1.txt  file2.txt  folder1

./folder1:
file3.txt

Description:

  • ls -R: Lists all files and directories recursively, showing contents of subdirectories.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.