Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Power of ls command
Fazal ur Rehman
Fazal ur Rehman

Posted on • Edited on

     

Power of ls command

what is a command?

The simplest answer is that a command is a software program that, when executed on the CLI, performs any action.
some commands take additional input to run correctly, This input is known asoptions andarguments

command [options] [arguments]

  • Options are used to modify the behavior of command.
  • Arguments are used to provide additional information.

Today we'll discuss the fundamentals ofls command and try to cover some basic parameters. we use this command daily basic and frequently even though we never aware of all the available options.

ls: By itself, the ls command lists files and directories contained in the current working directory.
Alt Text

Arguments

Thels command takes the argument as a name of the directory, it lists the contents of the directory, In the following example, the/etc/dpkg directory is used as an argument.
Alt Text
Thels command also accepts multiple arguments. To list the contents of both the/etc/ppp and/etc/ssh directories
Alt Text

Options

options used with commands to expend or modify the way a command behaves.
-a : Thels command omits hidden files by default. A hidden file is any file(or directory) that begins with a dot. character. with the used of-a option we can display all filed including hidden files.
Alt Text

-l : With this option we get results in a long listing, providing additional information about the files that are listed, such as the permission, size, creation date, and other information.(I will try to cover permission in the next post. this is a very important and fundamental part of Linux file system)
Alt Text

-h : If the-h option added with-l the file sizes will be displayed in human readable order (or you can write full word form;--human-readable)
Alt Text
note: The order of the combined options isn't important. The output of all of these examples would be the same:
ls -l -h
ls -hl
ls -lh

-r : By default ls print the results in ascending alphabetical order, with the help of-r option we print the result in reverse order.
Alt Text

-s : To see the file (or directory) size. very use full with flag-h
Alt Text

-S : To sort files by size. it is most useful when used with the-l option so the file sizes are visible and-h option to display human-readable file sizes.
Alt Text

-R : With the help of this flag we can display all of the files in a directory as well as all of the files in all subdirectories under that directory. This is called arecursive listing.
Alt Text

-t Sorted by modified time or created time
-m List all the files and directories separated with comma

I hope this article will help you to learn a few options ofls commands in Linux. Please refer to the manual pages by using the man ls command to explore in-depth

Thanks! happy coding :))

Top comments(2)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
cyberjack profile image
CyberJack
Software Architect @ TSG Group · PHP · Symfony · Open Source · Linux · Photography
  • Location
    Boxtel - The Netherlands
  • Work
    Software Architect @ TSG Group
  • Joined
• Edited on• Edited

I recommend adding the -F option.

-F, --classify    append indicator (one of */=>@|) to entries
Enter fullscreen modeExit fullscreen mode

Basically it makes it easier to see the difference between files, executable files, directories, links, whiteouts, sockets and FIFO without depending on colors.

CollapseExpand
 
iamfazal profile image
Fazal ur Rehman
Experienced Software Engineer with a demonstrated history of working in the software industry. Looking for remote work
  • Location
    Karachi
  • Education
    Computer Science
  • Work
    Associate Software Engineer at Trukkr
  • Joined

Yeah, sure I will.

Thanks for spending your time on my post 😊

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Experienced Software Engineer with a demonstrated history of working in the software industry. Looking for remote work
  • Location
    Karachi
  • Education
    Computer Science
  • Work
    Associate Software Engineer at Trukkr
  • Joined

More fromFazal ur Rehman

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp