Linux ls command and it's options

Blogs ❯❯ Linux

Image could not load

Image on pixabay

Hello everyone , I hope अब सभी लोग अच्छे हैं इस blog में हम Linux में use होने वाली बहुत basic but important command ls के बारे में बात करेंगे, I hope आपको यह blog पसंद आएगा।

What is ls ?

Linux में ls command का use directories या directory contents को list करने के लिए किया जाता है। By default यह सभी visible files और directory को list करता है।

Example के लिए मैंने कुछ sample directories & files बना रखी हैं , तो simple ls command run करने पर आपको कुछ इस तरह से Output मिलेगा।

$ ls
dir_1  dir_2  dir_3  dir_4  file_1.txt  file_2.txt

हालाँकि ls commands के साथ और भी parameters(options) pass किये जाते हैं जिसे आप simply ls -- लिखकर दो बार TAB button press करने पर सभी options दिख जायँगे -

~$ ls --
--all                                      --full-time                                --quoting-style=
--almost-all                               --group-directories-first                  --recursive
--author                                   --help                                     --reverse
--block-size=                              --hide-control-chars                       --show-control-chars
--classify                                 --hide=                                    --si
--color                                    --human-readable                           --size
--color=                                   --hyperlink                                --sort
--context                                  --ignore-backups                           --sort=
--dereference                              --ignore=                                  --tabsize=
--dereference-command-line                 --indicator-style=                         --time
--dereference-command-line-symlink-to-dir  --inode                                    --time-style=
--directory                                --kibibytes                                --time=
--dired                                    --literal                                  --version
--escape                                   --no-group                                 --width=
--file-type                                --numeric-uid-gid
--format=                                  --quote-name

Syntax :

ls [option]

Now , एक एक करके , इन सभी commands के बारे में देखते हैं।

Linux ls --all

ls --all command का use सभी hidden files और directories को print करता है , shortcut आप में इसे -a भी लिख सकते हैं।

~$ ls --all
.  ..  .bash_history  .bash_logout  .bashrc  .cache  .lesshst  .profile  .ssh  dir_1  dir_2  dir_3  dir_4  file_1.txt  file_2.txt
~$ ls -a
.  ..  .bash_history  .bash_logout  .bashrc  .cache  .lesshst  .profile  .ssh  dir_1  dir_2  dir_3  dir_4  file_1.txt  file_2.txt

Linux ls --almost-all

ls --almost-all command का use सभी hidden & normal files और directories को print करता है। लेकिन यह implied . और .. को list नहीं करता है। जैसा कि आप example में देख सकते हैं। shortcut में इसे भी आप -A लिख सकते हैं।

~$ ls --almost-all
.bash_history  .bash_logout  .bashrc  .cache  .lesshst  .profile  .ssh  dir_1  dir_2  dir_3  dir_4  file_1.txt  file_2.txt
~$ ls -A
.bash_history  .bash_logout  .bashrc  .cache  .lesshst  .profile  .ssh  dir_1  dir_2  dir_3  dir_4  file_1.txt  file_2.txt

Linux ls --reverse

ls --reverse command का use सभी files और directories को reverse order में sort करने के लिए किया जाता है। इसे shortcut में आप -r लिख सकते हैं।

~$ ls
dir_1  dir_2  dir_3  dir_4  dir_5  file_1.txt  file_2.txt
~$ ls -r
file_2.txt  file_1.txt  dir_5  dir_4  dir_3  dir_2  dir_1

Linux ls --recursive

ls --recursive command , सभी files और directories को list करने साथ - साथ किसी directory / sub-directory के अंदर files & subdirectories को recursively list करता है। इसे shortcut में आप -R लिख सकते हैं।

~$ ls --recursive
.:
dir_1  dir_2  dir_3  dir_4  dir_5  file_1.txt  file_2.txt
./dir_1:
dir1_file.txt
./dir_2:
./dir_3:
./dir_4:
./dir_5:

Linux ls --size

ls --size command , सभी files और directories को allocate किये गए size के साथ list करता है। इसे shortcut में आप -s लिख सकते हैं।

~$ ls --size
total 20
4 dir_1  4 dir_2  4 dir_3  4 dir_4  4 dir_5  0 file_1.txt  0 file_2.txt
~$ ls -s
total 20
4 dir_1  4 dir_2  4 dir_3  4 dir_4  4 dir_5  0 file_1.txt  0 file_2.txt

Linux ls -l

यह ls का सबसे important parameter(option) है , ls -l command का use files और directories को full information के साथ list करता है। information में files / directories का name , create date , size, owner name और permissions को print करता है।

~$ ls -l
total 20
drwxrwxr-x 2 ubuntu ubuntu 4096 Oct  2 14:40 dir_1
drwxrwxr-x 2 ubuntu ubuntu 4096 Oct  2 13:31 dir_2
drwxrwxr-x 2 ubuntu ubuntu 4096 Oct  2 13:31 dir_3
drwxrwxr-x 2 ubuntu ubuntu 4096 Oct  2 13:31 dir_4
drwxrwxr-x 2 ubuntu ubuntu 4096 Oct  2 14:36 dir_5
-rw-rw-r-- 1 ubuntu ubuntu    0 Oct  2 13:32 file_1.txt
-rw-rw-r-- 1 ubuntu ubuntu    0 Oct  2 13:32 file_2.txt
Recent Blogs

Loading ...

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook