Linux tree Command

Blogs ❯❯ Linux

Image could not load

Image by pixabay

what is tree Command in Linux ?

Linux में tree command , file structure को traverse करके tree like format में files और directories को list करता है। यह काफी useful command है अगर आप quickly किसी directory structures और किसी certain file की location को investigate करना चाहें।

Linux Install tree

by default , यह package आपके system में installed नहीं होता है , तो tree use करने के लिए आपको इसे install करना पड़ेगा। tree install करने के लिए नीचे दी गयी command को run करें।

$ sudo apt update
$ sudo apt install tree
Linux tree Syntax
$ tree [options] dirpath

By default tree command , current working directory की सभी files और directories को list कर देगा।

Linux tree command example
$ tree
.
├── dir_1
├── dir_2
├── dir_3
├── dir_4
├── file_1.txt
├── file_2.txt
├── file_3.txt
└── file_4.txt

4 directories, 4 files
Linux tree Command Options

हालाँकि tree Command के कई और भी Options हैं , जिन्हे आप tree --help command run करके देख सकते हैं।

Linux tree -d

tree command के साथ -d option का use तब किया जाता है जब आप सिर्फ directories की listing कराना चाहते हो। जैसे ऊपर दिए गए example के output में आपने देखा है कि अभी files और directories दोनों आ रहे हैं , लेकिन -d option pass करने पर सिर्फ directories ही list होंगी।

Example -

$ tree -d
.
├── dir_1
├── dir_2
├── dir_3
└── dir_4

4 directories

Linux tree -s

tree के साथ -s option का use files और directories को size (In bytes) के साथ list करने के लिए किया जाता है।

$ tree -s
[       4096]  .
├── [       4096]  dir_1
├── [       4096]  dir_2
├── [          0]  file_1.txt
└── [          0]  file_2.txt

2 directories, 2 files

Linux tree -h

tree के साथ -h option का use भी files और directories को size के साथ list करने के लिए किया जाता है। लेकिन -h से file का size human-readable format में print होता है। यहां [K for kilobytes, M for megabytes, G for gigabytes] है।

Example -

$ tree -h
[4.0K]  .
├── [4.0K]  dir_1
├── [4.0K]  dir_2
├── [   0]  file_1.txt
└── [   0]  file_2.txt

2 directories, 2 files

Linux tree -u

tree command के साथ -u option का use files / directories के file owner का username या UID के साथ list करने के लिए किया जाता है।

$ tree -u
[ubuntu  ]  .
├── [ubuntu  ]  dir_1
├── [ubuntu  ]  dir_2
├── [ubuntu  ]  file_1.txt
└── [ubuntu  ]  file_2.txt

2 directories, 2 files

Linux tree -p

tree के साथ -p option का use files / directories को उनकी permissions के साथ list करने के लिए किया जाता है।

$ tree -p
[drwxr-x---]  .
└── [drwxrwxr-x]  learning
    ├── [drwxrwxr-x]  dir_1
    ├── [drwxrwxr-x]  dir_2
    ├── [-rw-rw-r--]  file_1.txt
    └── [-rw-rw-r--]  file_2.txt

3 directories, 2 files

Linux tree -f

tree के साथ -f option का use files को full path के साथ list करने के लिए किया जाता है।

$ tree -f
.
└── ./learning
    ├── ./learning/dir_1
    ├── ./learning/dir_2
    ├── ./learning/file_1.txt
    └── ./learning/file_2.txt

3 directories, 2 files

Linux tree -J

tree के साथ -J option का use files / directories को JSON format में print करने के लिए किया जाता है।

$ tree -J
[
  {"type":"directory","name":".","contents":[
    {"type":"directory","name":"dir_1"},
    {"type":"directory","name":"dir_2"},
    {"type":"file","name":"file_1.txt"},
    {"type":"file","name":"file_2.txt"}
  ]}
,
  {"type":"report","directories":2,"files":2}
]

JSON की full form JavaScript Object Notation है , JSON JavaScript Object पर based एक open standard file format है जो , data को key : value pair में data store करता है।

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