دستور ls یکی از دستورات پرکاربرد و کاربردی در لینوکس می باشد.من معتقدم اگر قصد استفاده از خط فرمان لینوکس را دارید اولین دستوری که باید یاد بگیرید دستور ls می باشد هرچند ما از خیلی از option های آن استفاده نمی کنیم.در این قسمت من درباره دستور ls و option هایی که بیشترین کاربرد را دارند صحبت خواهم کرد.
۱٫ List Files using ls with no option
ls بدون option فقط لیسیتی از فایلها و پوشه ها را بدون نمایش جزئیاتی مانند:حجم(size) و مجوز(permission) و زمان(time) و تاریخ آخرین تغییرات(modified date) و لینکها(links) و … نمایش میدهد.
# ls Desktop Documents Downloads Music Pictures Public Templates Videos
2. List Files With option –l
ls -l پوشه ها و فایل ها را همراه با size, modified date, time, permission نشان می دهد.
# ls -l total 32 drwxr-xr-x. 2 tazik tazik 4096 Dec 17 19:15 Desktop drwxr-xr-x. 2 tazik tazik 4096 Dec 17 19:15 Documents drwxr-xr-x. 2 tazik tazik 4096 Dec 26 22:13 Downloads drwxr-xr-x. 2 tazik tazik 4096 Dec 17 19:15 Music drwxr-xr-x. 3 tazik tazik 4096 Dec 18 21:59 Pictures drwxr-xr-x. 3 tazik tazik 4096 Dec 24 16:32 Public drwxr-xr-x. 2 tazik tazik 4096 Dec 17 19:15 Templates drwxr-xr-x. 2 tazik tazik 4096 Dec 17 19:15 Videos
3. View Hidden Files
برای نمایش همه فایل ها همراه با فایل های مخفی بدین ترتیب عمل می کنیم:
فایل های مخفی با “.” مشخصاند.
# ls -a . Desktop .goldendict .orc Videos .. .directory .gstreamer-0.10 Pictures .VirtualBox .bash_history .dmrc .gtkrc-2.0-kde4 .pki .xine .bash_logout Documents .hplip Public .xsession-errors .bash_profile Downloads .kde .pulse .xsession-errors-:0 .bashrc .esd_auth .local .pulse-cookie .bluefish .fonts.conf .mozilla .purple .cache .gconf .mplayer Templates .config .gimp-2.8 Music .thumbnails
4. List Files with option -lh
با ترکیب -lh حجم فایل ها کاملا واضح لیست می شوند.
# ls -lh total 32K drwxr-xr-x. 2 tazik tazik 4.0K Dec 17 19:15 Desktop drwxr-xr-x. 2 tazik tazik 4.0K Dec 17 19:15 Documents drwxr-xr-x. 2 tazik tazik 4.0K Dec 26 22:13 Downloads drwxr-xr-x. 2 tazik tazik 4.0K Dec 17 19:15 Music drwxr-xr-x. 3 tazik tazik 4.0K Dec 18 21:59 Pictures drwxr-xr-x. 3 tazik tazik 4.0K Dec 24 16:32 Public drwxr-xr-x. 2 tazik tazik 4.0K Dec 17 19:15 Templates drwxr-xr-x. 2 tazik tazik 4.0K Dec 17 19:15 Videos
5. List Files and Directories with ‘/’ Character at the end
با آپشن -F در دستور ls در آخر همه ی پوشه ها علامت “/” نمایش داده خواهد شد.
# ls -F Desktop/ Documents/ Downloads/ Music/ Pictures/ Public/ Templates/ Videos/
6. List Files in Reverse Order
با آپشن -r فایل ها و پوشه ها برعکس نمایش داده می شوند .یعنی اول آخرین فایل نمایش داده می شود.
# ls -r Videos Templates Public Pictures Music Downloads Documents Desktop
7. Recursively list Sub-Directories
با اجرای این دستور پوشه ها را با محتویات داخلش به صورت درختی لیست می کند.
# ls -R .: Desktop Documents Downloads Music Pictures Public Templates Videos ./Desktop: Home.desktop trash.desktop ./Documents: ./Downloads: 1287213086_129371206_1-Shoe-Cabinet-with-Sliding-Door-Unit-21-Vision-Home-Expo-Serdang-Raya-1287213086.jpg PATTINO-GLOSSY-DARK-GREY-SHOE-CABINET-WITH-WOODEN-DRAWER-5830.jpg waznt-sure-bout-u-before.jpg ./Music: ./Pictures: smplayer_screenshots ./Pictures/smplayer_screenshots: ./Public: 1 sit3-shine.7.gif 30-Linux-Commands.png wordpress-uncategorized-1.png 30-Linux-Commands.xcf wordpress-uncategorized-2.jpg 30-Linux-Commanuds 2.png wordpress-uncategorized-3.jpg line.jpg wordpress-uncategorized-4.jpg linux-command-1-250x200.jpg wordpress-uncategorized-5.jpg linux-command-1.jpg wordpress-uncategorized-6.jpg linux-penguin.jpg wordpress-uncategorized.jpg ./Public/1: footer.png Text File Text File~ ./Templates: ./Videos:
8. Reverse Output Order
با اجرای این دستور فایل ها و پوشه ها به ترتیب آخرین زمان تغییرات نمایش داده خواهند شد.
ls -ltr total 32 drwxr-xr-x. 2 tazik tazik 4096 Dec 17 19:15 Videos drwxr-xr-x. 2 tazik tazik 4096 Dec 17 19:15 Templates drwxr-xr-x. 2 tazik tazik 4096 Dec 17 19:15 Music drwxr-xr-x. 2 tazik tazik 4096 Dec 17 19:15 Documents drwxr-xr-x. 2 tazik tazik 4096 Dec 17 19:15 Desktop drwxr-xr-x. 3 tazik tazik 4096 Dec 18 21:59 Pictures drwxr-xr-x. 3 tazik tazik 4096 Dec 24 16:32 Public drwxr-xr-x. 2 tazik tazik 4096 Dec 26 22:13 Downloads
9. Sort Files by File Size
با این دستور فایل ها به ترتیب حجم نمایش داده خواهند شد.حجم بیشتر اول نمایش داده می شود.
# ls -lS total 176 -rw-r--r--. 1 root root 48867 Jul 31 02:17 install.log -rw-r--r--. 1 root root 46701 Jul 31 09:58 index.html -rw-r--r--. 1 root root 21262 Aug 12 12:42 fbcmd_update.php -rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Desktop drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Documents drwxr-xr-x. 4 root root 4096 Aug 16 02:55 Downloads drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Music drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Pictures drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Public drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Templates drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Videos -rw-------. 1 root root 1586 Jul 31 02:17 anaconda-ks.cfg -rw-r--r--. 1 root root 683 Aug 19 09:59 0001.pcap
10. Display Inode number of File or Directory
برای دیدن Inode number هم از دستور زیر می توانید استفاده کنید:
ls -i 131081 Desktop 131082 Downloads 131087 Pictures 131083 Templates 131085 Documents 131086 Music 131084 Public 131088 Videos
11. Shows version of ls command
برای دیدن ورژن دستور ls.
ls --version ls (GNU coreutils) 8.17 Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://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.
12. Show Help Page
برای دیدن دفترچه راهنمای ls و option ها هم این دستور را اجرا کنید.
# ls --help Usage: ls [OPTION]... [FILE]...
13. List Directory Information
با دستور ls -l فایل های داخل پوشه /tmp را می توان لیست کرد.با پارامتر -ld می توان اطلاعات پوشه /tmp را بدست آورد.
ls -l /tmp/ total 0 drwx------. 2 tazik tazik 80 Dec 27 11:53 kde-tazik drwx------. 2 tazik tazik 100 Dec 27 16:22 ksocket-tazik drwx------. 2 tazik tazik 100 Dec 27 11:53 pulse-BjEQsu9zQpsW srwxrwxr-x. 1 tazik tazik 0 Dec 27 11:53 qtsingleapp-Golden-86bf-3e8 -rw-rw-r--. 1 tazik tazik 0 Dec 27 11:53 qtsingleapp-Golden-86bf-3e8-lockfile -rw-rw-r--. 1 tazik tazik 0 Dec 27 12:38 qtsingleapp-smplay-ca73-3e8-lockfile drwx------. 2 tazik tazik 60 Dec 27 11:53 ssh-wUDkKCEFoBkW drwxrwxrwt. 2 root colord 40 Dec 27 11:53 systemd-private-1F5muP drwxrwxrwt. 2 root root 40 Dec 27 17:25 systemd-private-7KhcbA drwxrwxrwt. 2 root root 40 Dec 27 11:53 systemd-private-bdkOIs drwxrwxrwt. 2 root mysql 40 Dec 27 17:25 systemd-private-KqeR4N drwxrwxrwt. 2 root mysql 40 Dec 27 18:40 systemd-private-MBxg4X drwxrwxrwt. 2 root root 40 Dec 27 11:53 systemd-private-R1atiH drwxrwxrwt. 2 root mysql 40 Dec 27 17:25 systemd-private-Rwydf1
# ls -ld /tmp/ drwxrwxrwt. 20 root root 500 Dec 27 18:41 /tmp/
14. Display UID and GID of Files
با نمایش UID و GID فایل ها و پوشه ها از پارامتر -n با دستور ls استفاده کنید.
# ls -n total 32 drwxr-xr-x. 2 1000 1000 4096 Dec 17 19:15 Desktop drwxr-xr-x. 2 1000 1000 4096 Dec 17 19:15 Documents drwxr-xr-x. 2 1000 1000 4096 Dec 26 22:13 Downloads drwxr-xr-x. 2 1000 1000 4096 Dec 17 19:15 Music drwxr-xr-x. 3 1000 1000 4096 Dec 18 21:59 Pictures drwxr-xr-x. 3 1000 1000 4096 Dec 24 16:32 Public drwxr-xr-x. 2 1000 1000 4096 Dec 17 19:15 Templates drwxr-xr-x. 2 1000 1000 4096 Dec 17 19:15 Videos
15. ls command and it’s Aliases
شما می توانید برای دستور ls -l یک shortcut با دستور alias بسازید:
# alias ls=\"ls -l\"
حالا فقط با اجرای دستور ls شما عمل ls -l را مشاهده می کنید.
برای دیدن alias دردسترس روی سیستم خود از دستور alias استفاده کنید:
alias alias egrep=\'egrep --color=auto\' alias fgrep=\'fgrep --color=auto\' alias grep=\'grep --color=auto\' alias l.=\'ls -d .* --color=auto\' alias ll=\'ls -l --color=auto\' alias ls=\'ls -l\' alias which=\'alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde\'
برای پاک کردم alias که قبل ساختیم از این دستور استفاده کنید.
# unalias ls
اگر من چیزی را دراین لیست فراموش کردم شما در قسمت نظرات می توانید این لیست را کاملتر کنید.
Cheers !