أمثلة عن الأمر 'ls' في لينكس - Linux Command Line

hocine
Hocine G
Back-end Developer (Python/Django)
10/08/2021 |لينكس ⌨️
أمثلة عن الأمر 'ls' في لينكس - Linux Command Line

الأمر 'ls' في لينكس هو الأمر الاكثر استعمالا, و هو ربما الامر الاول الذي يتم تعلمه, سنحاول تغطية أكبر قدر ممكن من الأمثلة حول استعماله.

يتيح لك الأمر ls عرض قائمة بالملفات والمجلدات الموجودة في مجلد معين. يمكنك أيضًا استخدام هذا الأمر لعرض تفاصيل الملف ، مثل مالك الملف والأذونات المعينة للملف.

 

عرض قائمة الملفات باستخدام الأمر ls بدون خيار

ls بدون اي خيارات تدرج لنا الملفات و المجلدات بدون اي معلومات اضافية.

$ ls
Desktop    Downloads  Pictures  report.pdf  Templates
Documents  Music      Public    script.py   Videos

 

عرض قائمة الملفات باستخدام الأمر ls مع الخيار -l

الأمر ls -l (l هو حرف وليس الرقم واحد) يقوم بادراج الملف أو الدليل والحجم والتاريخ والوقت المعدل واسم الملف أو المجلد ومالك الملف والإذن الخاص به.

$ ls -l
total 40
drwxr-xr-x 2 almatten almatten 4096 Aug 10 18:39 Desktop
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Documents
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:52 Downloads
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Music
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Pictures
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Public
-rw-rw-r-- 1 almatten almatten 1974 Aug 10 17:56 report.pdf
-rw-rw-r-- 1 almatten almatten 3696 Aug 10 17:56 script.py
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Templates
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Videos

عرض الملفات المخفية

الأمر ls -a يدرج قائمة بجميع الملفات بما في ذلك الملفات المخفية التي تبدء بـ '.'.

$ ls -a
.              Downloads   script.py
..             .gnupg      .sudo_as_admin_successful
.bash_history  .local      Templates
.bash_logout   .mozilla    .vboxclient-clipboard.pid
.bashrc        Music       .vboxclient-display-svga-x11.pid
.cache         Pictures    .vboxclient-draganddrop.pid
.config        .profile    .vboxclient-seamless.pid
Desktop        Public      Videos
Documents      report.pdf

عرض الملفات المقروء للانسان باستخدام الخيار -lh

مع الخيار -lh ، تعرض الأحجام مقروءة  بواسطة الإنسان.

$ ls -lh
total 40K
drwxr-xr-x 2 almatten almatten 4.0K Aug 10 18:48 Desktop
drwxr-xr-x 2 almatten almatten 4.0K Aug 10 17:43 Documents
drwxr-xr-x 2 almatten almatten 4.0K Aug 10 17:52 Downloads
drwxr-xr-x 2 almatten almatten 4.0K Aug 10 17:43 Music
drwxr-xr-x 2 almatten almatten 4.0K Aug 10 17:43 Pictures
drwxr-xr-x 2 almatten almatten 4.0K Aug 10 17:43 Public
-rw-rw-r-- 1 almatten almatten 2.0K Aug 10 17:56 report.pdf
-rw-rw-r-- 1 almatten almatten 3.7K Aug 10 17:56 script.py
drwxr-xr-x 2 almatten almatten 4.0K Aug 10 17:43 Templates
drwxr-xr-x 2 almatten almatten 4.0K Aug 10 17:43 Videos

عرض الرمز '/' في النهاية بالنسبة للمجلدات

باستخدام الخيار -F، سيضاف الرمز "/" في نهاية كل مجلد.

$ ls -F
Desktop/    Downloads/  Pictures/  report.pdf  Templates/
Documents/  Music/      Public/    script.py   Videos/

عرض الملفات بترتيب عكسي

يعرض الأمر التالي مع خيار ls -r الملفات والدلائل بترتيب عكسي.

$ ls -r
Videos     script.py   Public    Music      Documents
Templates  report.pdf  Pictures  Downloads  Desktop

عرض الملفات و المجلدات الفرعية

الخيار ls -R سيدرج قائمة طويلة جدًا من أشجار المجلدات.

$ ls -R
.:
Desktop    Downloads  Pictures  report.pdf  Templates
Documents  Music      Public    script.py   Videos

./Desktop:
a.txt

./Documents:

./Downloads:
185152387_286728373098485_3787250665416640707_n.jpg

./Music:

./Pictures:

./Public:
a.txt

./Templates:

./Videos:

طبع ترتيب عكسي

مع مزيج من الخيارات -ltr سيظهر في اَخر القائمة أحدث ملف او مجلد قد تعدل أو أنشئ.

$ ls -ltr
total 40
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Videos
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Templates
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Pictures
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Music
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Documents
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:52 Downloads
-rw-rw-r-- 1 almatten almatten 3696 Aug 10 17:56 script.py
-rw-rw-r-- 1 almatten almatten 1974 Aug 10 17:56 report.pdf
drwxr-xr-x 2 almatten almatten 4096 Aug 10 19:12 Desktop
drwxr-xr-x 2 almatten almatten 4096 Aug 10 19:18 Public

ترتيب الملفات حسب حجم الملف

مع الخيار -lS عرض القائمة بترتيب خسب الحجم, الحجم الكبير يتم ادراجه اولاََ.

$ ls -lS
total 40
drwxr-xr-x 2 almatten almatten 4096 Aug 10 19:12 Desktop
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Documents
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:52 Downloads
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Music
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Pictures
drwxr-xr-x 2 almatten almatten 4096 Aug 10 19:18 Public
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Templates
drwxr-xr-x 2 almatten almatten 4096 Aug 10 17:43 Videos
-rw-rw-r-- 1 almatten almatten 3696 Aug 10 17:56 script.py
-rw-rw-r-- 1 almatten almatten 1974 Aug 10 17:56 report.pdf

اضهار رقم inode لملف او مجلد

رقم Inode هو رقم موجود بشكل فريد لجميع الملفات في Linux وجميع أنظمة نوع Unix. يقوم الأمر ls مع الخيار -i باضهار رقم الـ inode للملفات المدرجة.

$ ls -i
790527 Desktop    921562 Music     795787 report.pdf  921564 Videos
919918 Documents  921563 Pictures  795779 script.py
795157 Downloads  795159 Public    795158 Templates

اضهار اصدار الأمر 'ls'

تحقق من إصدار الأمر ls.

$ ls --version
ls (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Richard M. Stallman and David MacKenzie.

أو

$ ls --v
ls (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Richard M. Stallman and David MacKenzie.

إظهار صفحة المساعدة

مع الخيار --help الذي ستجده مع كل الاوامر سيضهر لك صفحة المساعدة.

$ ls --help
Usage: ls [OPTION]... [FILE]...

اضهار معلوات عن المجلد

الخيار -l يضهر لنا معلومات عن الملفات التي داخل المجلد /tmp, اما الخيار -ld فسيقوم باضهار المعلومات الخاصة بالمجلد  /tmp بذاته.

$ ls -l /tmp
total 40
-rw------- 1 almatten almatten    0 Aug 10 18:18  config-err-uG2glU
srwxrwxrwx 1 almatten almatten    0 Aug 10 18:18  dbus-Jb6IrgS1od
drwx------ 3 root     root     4096 Aug 10 18:17  systemd-private-801...
drwx------ 3 root     root     4096 Aug 10 18:18  systemd-private-801...
drwx------ 3 root     root     4096 Aug 10 18:14  systemd-private-801...
drwx------ 3 root     root     4096 Aug 10 18:14  systemd-private-801...
drwx------ 3 root     root     4096 Aug 10 18:14  systemd-private-801...
drwx------ 3 root     root     4096 Aug 10 18:14  systemd-private-801...
drwx------ 3 root     root     4096 Aug 10 18:16  systemd-private-801...
drwx------ 2 almatten almatten 4096 Aug 10 19:12  tracker-extract-files.1000
drwx------ 2 gdm      gdm      4096 Aug 10 18:16  tracker-extract-files.110
drwx------ 5 almatten almatten 4096 Aug 10 19:18 'VirtualBox Dropped Files'
$ ls -ld /tmp
drwxrwxrwt 17 root root 4096 Aug 10 19:35 /tmp

اضهار UDI و GID لملف

لاضهار الـ UID و GID لملف او مجلد, نضيف الخيار -n.

UID: رقم مرتبط بحساب مستخدم

GID: رقم مرتبط بمجموعة

$ ls -n
total 40
drwxr-xr-x 2 1000 1000 4096 Aug 10 19:12 Desktop
drwxr-xr-x 2 1000 1000 4096 Aug 10 17:43 Documents
drwxr-xr-x 2 1000 1000 4096 Aug 10 17:52 Downloads
drwxr-xr-x 2 1000 1000 4096 Aug 10 17:43 Music
drwxr-xr-x 2 1000 1000 4096 Aug 10 17:43 Pictures
drwxr-xr-x 2 1000 1000 4096 Aug 10 19:18 Public
-rw-rw-r-- 1 1000 1000 1974 Aug 10 17:56 report.pdf
-rw-rw-r-- 1 1000 1000 3696 Aug 10 17:56 script.py
drwxr-xr-x 2 1000 1000 4096 Aug 10 17:43 Templates
drwxr-xr-x 2 1000 1000 4096 Aug 10 17:43 Videos

 

هذه كانت الخيارات التي يمكن اضافتها مع الأمر 'ls', نرجو انّ الموضوع كان مفيداَ.

 

لمعرفة المزيد حول اوامر لينكس, يمكنك زيارة: اوامر لينكس الأساسية و المهمة التي عليك معرفتها - Linux Command Line

تذكر أن المساهمات في هذا الموضوع يجب أن تتبع إرشادات المجتمع.


التعليقات:

    لا توجد تعليقات بعد.