ls perintah adalah salah satu perintah yang paling sering digunakan di Linux. aku percaya ls command adalah perintah pertama yang mungkin Anda gunakan ketika Anda masuk ke command prompt di Linux Box.
Kita gunakan ls perintah setiap hari dan sering meskipun kita mungkin tidak menyadari dan tidak pernah menggunakan semua ls pilihan yang tersedia. Pada artikel ini, kita akan membahas basic ls perintah di mana kami telah mencoba untuk mencakup parameter sebanyak mungkin.
ls tanpa opsi daftar file dan direktori dalam format kosong di mana kami tidak akan dapat melihat detail seperti jenis file, ukuran, tanggal dan waktu yang dimodifikasi, izin dan tautan, dll.
# ls 0001.pcap Desktop Download index.html install.log.syslog Gambar Template. anaconda-ks.cfg Dokumen fbcmd_update.php install.log Musik Video Publik
Di Sini, ls -l (-l is character not one) menunjukkan file atau direktori, ukuran, tanggal dan waktu modifikasi, nama file atau folder dan pemilik file serta izinnya.
# ls -l jumlah 176. -rw-r--r--. 1 root root 683 19 Agustus 09:59 0001.pcap. -rw. 1 root root 1586 31 Juli 02:17 anaconda-ks.cfg. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Desktop. drwxr-xr-x. 2 root root 4096 31 Jul 02:48 Documents. drwxr-xr-x. 4 root root 4096 16 Agustus 02:55 Unduhan. -rw-r--r--. 1 root root 21262 12 Agustus 12:42 fbcmd_update.php. -rw-r--r--. 1 root root 46701 31 Juli 09:58 index.html. -rw-r--r--. 1 root root 48867 31 Juli 02:17 install.log. -rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Musik. drwxr-xr-x. 2 root root 4096 31 Jul 02:48 Gambar. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Publik. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Template. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Video
Daftar semua file termasuk file tersembunyi dimulai dengan '.‘.
# ls -a. .bashrc Dokumen .gconfd install.log .nautilus .pulse-cookie... .cache Unduh .gnome2 install.log.syslog .netstat.swp .recently-used.xbel. 0001.pcap .config .elinks .gnome2_private .kde .opera .spice-vdagent. anaconda-ks.cfg .cshrc .esd_auth .gtk-bookmarks .libreoffice Gambar .tcshrc. .bash_history .dbus .fbcmd .gvfs .local .pki Template. .bash_logout Desktop fbcmd_update.php .ICEauthority .mozilla Video Publik. .bash_profile .digrc .gconf index.html Musik .pulse .wireshark
Dengan kombinasi -lh opsi, menunjukkan ukuran dalam format yang dapat dibaca manusia.
# ls -lh total 176K. -rw-r--r--. 1 root root 683 19 Agustus 09:59 0001.pcap. -rw. 1 root root 1.6K 31 Jul 02:17 anaconda-ks.cfg. drwxr-xr-x. 2 root root 4.0K 31 Juli 02:48 Desktop. drwxr-xr-x. 2 root root 4.0K 31 Juli 02:48 Dokumen. drwxr-xr-x. 4 root root 4.0K 16 Agustus 02:55 Unduhan. -rw-r--r--. 1 root root 21K 12 Agustus 12:42 fbcmd_update.php. -rw-r--r--. 1 root root 46K 31 Juli 09:58 index.html. -rw-r--r--. 1 root root 48K 31 Juli 02:17 install.log. -rw-r--r--. 1 root root 12K 31 Juli 02:13 install.log.syslog. drwxr-xr-x. 2 root root 4.0K 31 Juli 02:48 Musik. drwxr-xr-x. 2 root root 4.0K 31 Jul 02:48 Gambar. drwxr-xr-x. 2 root root 4.0K 31 Juli 02:48 Publik. drwxr-xr-x. 2 root root 4.0K 31 Juli 02:48 Template. drwxr-xr-x. 2 root root 4.0K 31 Juli 02:48 Video
Menggunakan -F pilihan dengan ls perintah, akan menambahkan ‘/’ Karakter di akhir setiap direktori.
# ls -F0001.pcap Desktop/ Downloads/ index.html install.log.syslog Pictures/ Templates/ anaconda-ks.cfg Documents/ fbcmd_update.php install.log Musik/ Publik/ Video/
Perintah berikut dengan ls -r opsi menampilkan file dan direktori dalam urutan terbalik.
# ls -r Video Musik Publik install.log fbcmd_update.php Dokumen anaconda-ks.cfg. Template Gambar install.log.syslog index.html Unduh Desktop 0001.pcap
ls -R opsi akan mencantumkan daftar pohon direktori yang sangat panjang. Lihat contoh output dari perintah.
# ls -R jumlah 1384. -rw. 1 root root 33408 8 Agustus 17:25 anaconda.log. -rw. 1 root root 30508 8 Agustus 17:25 anaconda.program.log ./httpd: total 132. -rw-r--r-- 1 root root 0 19 Agustus 03:14 access_log. -rw-r--r--. 1 root root 61916 10 Agustus 17:55 access_log-20120812 ./lighttpd: total 68. -rw-r--r-- 1 lighttpd lighttpd 7858 21 Agustus 15:26 access.log. -rw-r--r--. 1 lighttpd lighttpd 37531 17 Agustus 18:21 access.log-20120819 ./nginx: total 12. -rw-r--r--. 1 root root 0 Agustus 12 03:17 access.log. -rw-r--r--. 1 root root 390 12 Agustus 03:17 access.log-20120812.gz
Dengan kombinasi -ltr akan menunjukkan file modifikasi atau tanggal direktori terbaru sebagai yang terakhir.
# ls -ltr jumlah 176. -rw-r--r--. 1 root root 11439 Jul 31 02:13 install.log.syslog. -rw-r--r--. 1 root root 48867 31 Juli 02:17 install.log. -rw. 1 root root 1586 31 Juli 02:17 anaconda-ks.cfg. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Desktop. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Video. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Template. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Publik. drwxr-xr-x. 2 root root 4096 31 Jul 02:48 Gambar. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Musik. drwxr-xr-x. 2 root root 4096 31 Jul 02:48 Documents. -rw-r--r--. 1 root root 46701 31 Juli 09:58 index.html. -rw-r--r--. 1 root root 21262 12 Agustus 12:42 fbcmd_update.php. drwxr-xr-x. 4 root root 4096 16 Agustus 02:55 Unduhan. -rw-r--r--. 1 root root 683 19 Agustus 09:59 0001.pcap
Dengan kombinasi -lS menampilkan ukuran file secara berurutan, akan menampilkan ukuran besar terlebih dahulu.
# ls -lS jumlah 176. -rw-r--r--. 1 root root 48867 31 Juli 02:17 install.log. -rw-r--r--. 1 root root 46701 31 Juli 09:58 index.html. -rw-r--r--. 1 root root 21262 12 Agustus 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 31 Juli 02:48 Desktop. drwxr-xr-x. 2 root root 4096 31 Jul 02:48 Documents. drwxr-xr-x. 4 root root 4096 16 Agustus 02:55 Unduhan. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Musik. drwxr-xr-x. 2 root root 4096 31 Jul 02:48 Gambar. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Publik. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Template. drwxr-xr-x. 2 root root 4096 31 Juli 02:48 Video. -rw. 1 root root 1586 31 Juli 02:17 anaconda-ks.cfg. -rw-r--r--. 1 root root 683 19 Agustus 09:59 0001.pcap
Kita bisa melihat beberapa nomor tercetak sebelum file / nama direktori. Dengan -Saya file daftar opsi / direktori dengan nomor inode.
# ls -i 20112 0001.pcap 23610 Dokumen 23793 index.html 23611 Musik 23597 Template. 23564 anaconda-ks.cfg 23595 Unduhan 22 install.log 23612 Gambar 23613 Video. 23594 Desktop 23585 fbcmd_update.php 35 install.log.syslog 23601 Publik
Periksa versi perintah ls.
# ls --versi ls (GNU coreutils) 8.4. Hak Cipta (C) 2010 Free Software Foundation, Inc. Lisensi GPLv3+: GNU GPL versi 3 atau yang lebih baru. Ini adalah perangkat lunak gratis: Anda bebas mengubah dan mendistribusikannya kembali. TIDAK ADA JAMINAN, sejauh diizinkan oleh hukum. Ditulis oleh Richard M. Stallman dan David MacKenzie.
Daftar halaman bantuan dari perintah ls dengan opsi mereka.
# ls --bantuan Penggunaan: ls [OPSI]... [MENGAJUKAN]...
Dengan ls -l file daftar perintah di bawah direktori /tmp. Dimana dengan -ld parameter menampilkan informasi dari /tmp direktori.
# ls -l /tmp jumlah 408. drwx. 2 narad narad 4096 2 Agustus 02:00 CRX_75DAF8CB7768. -R. 1 root root 384683 4 Agustus 12:28 htop-1.0.1.tar.gz. drwx. 2 root root 4096 4 Agustus 11:20 keyring-6Mfjnk. drwx. 2 root root 4096 16 Agustus 01:33 keyring-pioZJr. drwx. 2 gdm gdm 4096 21 Agustus 11:26 orbit-gdm. drwx. 2 root root 4096 19 Agustus 08:41 pulse-gl6o4ZdxQVrX. drwx. 2 narad narad 4096 4 Agustus 08:16 pulsa-UDH76ExwUVoU. drwx. 2 gdm gdm 4096 21 Agustus 11:26 pulse-wJtcweUCtvhn. -rw. 1 root root 300 16 Agustus 03:34 yum_save_tx-2012-08-16-03-34LJTAa1.yumtx
# ls -ld /tmp/ drwxrwxrwt. 13 root root 4096 21 Agustus 12:48 /tmp/
Menampilkan UID dan GID dari file dan direktori. gunakan opsi -n dengan perintah ls.
# ls -n jumlah 36. drwxr-xr-x. 2 500 500 4096 2 Agustus 01:52 Unduhan. drwxr-xr-x. 2 500 500 4096 2 Agustus 01:52 Musik. drwxr-xr-x. 2 500 500 4096 2 Agustus 01:52 Gambar. -rw-rw-r--. 1 500 500 12 Agustus 21 13:06 tmp.txt. drwxr-xr-x. 2 500 500 4096 2 Agustus 01:52 Video
Kami telah membuat alias untuk ls perintah, ketika kita menjalankan perintah ls itu akan memakan waktu -l opsi secara default dan menampilkan daftar panjang seperti yang disebutkan sebelumnya.
# alias ls="ls -l"
Catatan: Kita bisa melihat jumlah alias yang tersedia di sistem Anda dengan perintah alias di bawah ini dan bisa juga unalias seperti contoh di bawah ini.
# aliasalias cp='cp -i' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
Untuk menghapus alias yang telah ditentukan sebelumnya, cukup gunakan perintah unalias.
# unalias ls
Di artikel kami berikutnya, kami akan membahas lebih lanjut atau perintah ls tingkat lanjut dengan contoh-contoh mereka. Saya juga menyarankan Anda untuk melewati beberapa pertanyaan wawancara pada perintah ls dan juga jika kami melewatkan sesuatu dalam daftar, perbarui kami melalui bagian komentar.