دستور ls یکی از دستورات پرکاربرد و کاربردی در لینوکس می باشد.من معتقدم اگر قصد استفاده از خط فرمان لینوکس را دارید اولین دستوری که باید یاد بگیرید دستور ls می باشد هرچند ما از خیلی از option های آن استفاده نمی کنیم.در این قسمت درباره دستور ls و option هایی که بیشترین کاربرد را دارند صحبت خواهیم کرد.
1- List Files using ls with no option
ls بدون option فقط لیسیتی از فایلها و پوشه ها را بدون نمایش جزئیاتی مانند:حجم(size) و مجوز(permission) و زمان(time) و تاریخ آخرین تغییرات(modified date) و لینکها(links) و … نمایش میدهد.
ls #
Desktop Documents Downloads Music Pictures Public Templates Videos linux.pdf
2. List Files With option –l
ls -l پوشه ها و فایل ها را همراه با size, modified date, time, permission نشان می دهد.
# ls -l
total 32
drwxr-xr-x. 2 naser naser 4096 Dec 17 19:15 Desktop
drwxr-xr-x. 2 naser naser 4096 Dec 17 19:15 Documents
drwxr-xr-x. 2 naser naser 096 Dec 26 22:13 Downloads
drwxr-xr-x. 2 naser naser 4096 Dec 17 19:15 Music
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 حجم فایل ها کاملا واضح لیست می شوند.
total 718M
-rw-rw-r-- 1 naser naser 96K Sep 11 18:11 ۱.pdf
-rw-rw-r-- 1 naser naser 17M Sep 12 18:28 ۲۳.pdf
-rw-rw-r-- 1 naser naser 152 Apr 15 22:50 a.pl~
-rw-rw-r-- 1 naser naser 141K Sep 12 21:51 C:\nppdf32Log\debuglog.txt
drwx----- 12 naser naser 4.0K Jul 27 12:27 Darss
drwxr-xr-x 5 naser naser 4.0K Sep 11 18:09 Desktop
drwxr-xr-x 10 naser naser 4.0K Sep 12 15:57 Downloads
5. List Files and Directories with ‘/’ Character at the end
با آپشن -F در دستور ls در آخر همه ی پوشه ها علامت “/” نمایش داده خواهد شد.
Desktop/ Documents/ Downloads/ Music/ Pictures/ Public/ Templates/ Videos/
6. List Files in Reverse Order
با آپشن -r فایل ها و پوشه ها برعکس نمایش داده می شوند .یعنی اول آخرین فایل نمایش داده می شود.
Videos Templates Public Pictures Music Downloads Documents Desktop
7. Recursively list Sub-Directories
با اجرای این دستور پوشه ها را با محتویات داخلش به صورت درختی لیست می کند.
.:
Desktop Pictures Downloads
Home.desktop trash.desktop
./Pictures/ShakhSi/KhabGah/3921:
./Pictures/ShakhSi/KhanevaDegi:
01082013009.mp4 23122012185.jpg 24122012214.jpg 30072013006.jpg
01082013010.mp4 23122012187.jpg 24122012215.jpg 30072013006.mp4
01082013011.mp4
8. Reverse Output Order
با اجرای این دستور فایل ها و پوشه ها به ترتیب آخرین زمان تغییرات نمایش داده خواهند شد.
# ls -ltr
total 734360
-rw-rw-r-- 1 naser naser 0 Mar 14 2013 e.txt~
-rw-rw-r-- 1 naser naser 153722 Aug 4 04:03 linux.pdf
drwxr-xr-x 14 naser naser 4096 Aug 13 12:41 Music
drwxr-xr-x 5 naser naser 4096 Sep 11 18:09 Desktop
9. Sort Files by File Size
با این دستور فایل ها به ترتیب حجم نمایش داده خواهند شد.حجم بیشتر اول نمایش داده می شود.
-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
10. Display Inode number of File or Directory
برای دیدن Inode number هم از دستور زیر می توانید استفاده کنید:
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.13
Copyright (C) 2011 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.
12. Show Help Page
برای دیدن دفترچه راهنمای ls و option ها هم این دستور را اجرا کنید.
13. List Directory Information
با دستور ls -l فایل های داخل پوشه /tmp را می توان لیست کرد.با پارامتر -ld می توان اطلاعات پوشه /tmp را بدست آورد.
ls -l /tmp/
total 44
drwxrwxrwt 2 lightdm lightdm 4096 Sep 13 19:27 at-spi2
drwx------ 24 guest-CZ8QGK guest-CZ8QGK 680 Sep 13 19:35 guest-CZ8QGK
drwx------ 2 naser naser 4096 Sep 13 18:49 keyring-DNBv7S
drwx------ 2 naser naser 4096 Sep 13 18:49 ssh-saBpJWJJ3431
# ls -ld /tmp/
drwxrwxrwt. 20 root root 500 Dec 27 18:41 /tmp/
14. Display UID and GID of Files
با نمایش UID و GID فایل ها و پوشه ها از پارامتر -n با دستور ls استفاده کنید.
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 بسازید:
حالا فقط با اجرای دستور ls شما عمل ls -l را مشاهده می کنید.
برای دیدن 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 که قبل ساختیم از این دستور استفاده کنید.
lمنبع : tazik.ir
اگر قبلا در بیان ثبت نام کرده اید لطفا ابتدا وارد شوید، در غیر این صورت می توانید ثبت نام کنید.