Linux Basic Command-ls

ls

Function: Display the target list, which is a command with high usage in Linux. The output information of ls command can be highlighted in color to partition different types of files.

Parameters:

- a: Display all files and directories (the file name or directory name must be regarded as a video collection in ls, not listed);
- A: Display a list of all files except shadow files "." and ".";
- C: Multi-column display of output results. This is the default option;
- l: Contrary to the'-C'option, all output information is output in a single column format, not in multiple columns.
- F: After each output item, add the type identifier of the file, which means that "*" denotes a common file with executable permissions, "/" denotes a directory, "@" denotes a symbolic link, "|" denotes a command pipeline FIFO, "=" denotes sockets sockets. When the file is a normal file, no identifier is output.
- b: Output the non-output characters in the file in the way of backslash "" plus character encoding;
- c: When combined with the "-lt" option, the output directory contents are sorted according to the file state time, and the sorting is based on the ctime field in the index node of the file. When used with the "-l" option, the order is the state change time of the file.
- d: Only the directory name is displayed, not the list of contents in the directory. Display the symbolic link file itself instead of the list of directories to which it refers.
- f: The effect of this parameter is the same as that of specifying the "aU" parameter at the same time, and closing the "lst" parameter.
- i: Display the file index node number (inode). An index node represents a file.
file-type: The same function as the "-F" option, but does not display "*";
- k: Display file size in kilobytes.
- l: Show a list of contents in a long format. The output information from left to right includes file name, file type, permission mode, number of hard connections, owner, group, file size and the last modification time of the file.
- m: Separate the names of each file and directory with a "," number.
- n: Substitute user identification code and group identification code for its name.
- r: Arrange and output a list of directory contents in reverse order with file names;
- s: Display the size of files and directories in blocks;
- t: Sort files and directories by change time.
- L: If you encounter a file or directory with symbolic links, list directly the original file or directory to which the link refers.
- R: Recursive processing, all files and subdirectories under the specified directory are processed together;
full-time: List the complete dates and times;
-- color[=WHEN]: Highlight different types of colors with different colors.

Example:

Files that display non-hidden files in the current directory

[root@iZuf61bne18a1bikx6z7bvZ home]# ls
jg  phpinfo.php

Displays a list of all files in the current directory, including shadow files

[root@iZuf61bne18a1bikx6z7bvZ ~]# ls -a
.  ..  .bash_history  .bash_logout  .bash_profile  .bashrc  .cache  .cshrc  .pip  .pydistutils.cfg  .ssh  .tcshrc  .viminfo

Output long format

[root@iZuf61bne18a1bikx6z7bvZ /]# ls -1
bin
boot
dev
etc
home
lib
lib64
lost+found
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var

Display file inode (index node) information

[root@iZuf61bne18a1bikx6z7bvZ home]# ls -i1
1315905 jg
1053344 phpinfo.php

Horizontal Output File List

[root@iZuf61bne18a1bikx6z7bvZ /]# ls -m
bin, boot, dev, etc, home, lib, lib64, lost+found, media, mnt, opt, proc, root, run, sbin, srv, sys, tmp, usr, var

Sort and display by file modification time

[root@iZuf61bne18a1bikx6z7bvZ /]# ls -t
tmp  run  home  root  boot  etc  sys  dev  proc  usr  sbin  lib  lib64  bin  lost+found  var  media  mnt  opt  srv

Display recursive files

[root@iZuf61bne18a1bikx6z7bvZ etc]# ls -R
.:
adjtime                  cron.weekly              GeoIP.conf.default  krb5.conf                 my.cnf             printcap        sasl2           system-release
aliases                  crypttab                 gnupg               krb5.conf.d               my.cnf.d           profile         securetty       system-release-cpe
aliases.db               csh.cshrc                GREP_COLORS         ld.so.cache               NetworkManager     profile.d       security        terminfo
alternatives             csh.login                groff               ld.so.conf                networks           protocols       selinux         tmpfiles.d
anacrontab               dbus-1                   group               ld.so.conf.d              nscd.conf          python          services        tuned
asound.conf              default                  group-              libaudit.conf             nsswitch.conf      rc0.d           sestatus.conf   udev
at.deny                  depmod.d                 grub2.cfg           libnl                     nsswitch.conf.bak  rc1.d           shadow          vconsole.conf
audisp                   dhcp                     grub.d              libuser.conf              ntp                rc2.d           shadow-         vimrc
audit                    DIR_COLORS               gshadow             locale.conf               ntp.conf           rc3.d           shells          virc
bash_completion.d        DIR_COLORS.256color      gshadow-            localtime                 openldap           rc4.d           skel            wgetrc
bashrc                   DIR_COLORS.lightbgcolor  gss                 login.defs                opt                rc5.d           ssh             wpa_supplicant
binfmt.d                 dracut.conf              host.conf           logrotate.conf            os-release         rc6.d           ssl             X11
centos-release           dracut.conf.d            hostname            logrotate.d               pam.d              rc.d            statetab        xdg
centos-release-upstream  e2fsck.conf              hosts               lsb-release.d             passwd             rc.local        statetab.d      xinetd.d
chkconfig.d              eni_utils                hosts.allow         machine-id                passwd-            redhat-lsb      subgid          yum
chrony.conf              environment              hosts.deny          magic                     pkcs11             redhat-release  subuid          yum.conf
chrony.keys              ethertypes               init.d              mail.rc                   pki                resolv.conf     sudo.conf       yum.repos.d
cloud                    exports                  inittab             makedumpfile.conf.sample  plymouth           rpc             sudoers
cron.d                   favicon.png              inputrc             man_db.conf               pm                 rpm             sudoers.d
cron.daily               filesystems              iproute2            mke2fs.conf               polkit-1           rsyncd.conf     sudo-ldap.conf
cron.deny                firewalld                issue               modprobe.d                popt.d             rsyslog.conf    sysconfig
cron.hourly              fstab                    issue.net           modules-load.d            postfix            rsyslog.d       sysctl.conf
cron.monthly             gcrypt                   kdump.conf          motd                      ppp                rwtab           sysctl.d
crontab                  GeoIP.conf               kernel              mtab                      prelink.conf.d     rwtab.d         systemd

./alternatives:
ld                    mta-aliasesman  mta-newaliases     mta-rmail        pax      print-cancel     print-lpc     print-lpq     print-lprman   print-lpstatman
libnssckbi.so.x86_64  mta-mailq       mta-newaliasesman  mta-sendmail     pax-man  print-cancelman  print-lpcman  print-lpqman  print-lprmman
mta                   mta-mailqman    mta-pam            mta-sendmailman  print    print-lp         print-lpman   print-lprm    print-lpstat

./audisp:
audispd.conf  plugins.d

./audisp/plugins.d:
af_unix.conf  syslog.conf

./audit:
auditd.conf  audit.rules  audit-stop.rules  rules.d

./audit/rules.d:
audit.rules

./bash_completion.d:
iprutils

./binfmt.d:

./chkconfig.d:

./cloud:
cloud.cfg  cloud.cfg.d  templates

./cloud/cloud.cfg.d:
05_logging.cfg  README

./cloud/templates:
chef_client.rb.tmpl  hosts.debian.tmpl   hosts.redhat.tmpl  ntp.conf.tmpl  pydistutils.cfg.tmpl  sources.list.aliyun.tmpl  sources.list.ubuntu.tmpl
chrony.conf.tmpl     hosts.freebsd.tmpl  hosts.suse.tmpl    pip.conf.tmpl  resolv.conf.tmpl      sources.list.debian.tmpl

./cron.d:
0hourly  sysstat

./cron.daily:
logrotate  man-db.cron

./cron.hourly:
0anacron

./cron.monthly:

./cron.weekly:

./dbus-1:
session.conf  session.d  system.conf  system.d

./dbus-1/session.d:

./dbus-1/system.d:
com.redhat.tuned.conf  nm-ifcfg-rh.conf                org.freedesktop.locale1.conf   org.freedesktop.NetworkManager.conf  org.freedesktop.timedate1.conf
FirewallD.conf         org.freedesktop.hostname1.conf  org.freedesktop.login1.conf    org.freedesktop.PolicyKit1.conf      teamd.conf
nm-dispatcher.conf     org.freedesktop.import1.conf    org.freedesktop.machine1.conf  org.freedesktop.systemd1.conf        wpa_supplicant.conf

./default:
grub  nss  useradd

./depmod.d:
dist.conf

./dhcp:
dhclient.d  dhclient-down-hooks  dhclient-exit-hooks  dhclient-exit-hooks.d

./dhcp/dhclient.d:
chrony.sh  ntp.sh

./dhcp/dhclient-exit-hooks.d:
azure-cloud.sh

./dracut.conf.d:
virt-drivers.conf  virtio-drivers.conf

./eni_utils:
eni-cleanup  eni-function  eni-helper  eni-hotplug  net.hotplug

./firewalld:
firewalld.conf  helpers  icmptypes  ipsets  lockdown-whitelist.xml  services  zones

UID and GID for Printing Files

[root@iZuf61bne18a1bikx6z7bvZ home]# ls -n
total 8
drwxr-xr-x 5 0 0 4096 Apr  9 08:39 jg
-rw-r--r-- 1 0 0   89 Apr  8 21:41 phpinfo.php

List file and folder details

[root@iZuf61bne18a1bikx6z7bvZ home]# ls -l
total 8
drwxr-xr-x 5 root root 4096 Apr  9 08:39 jg
-rw-r--r-- 1 root root   89 Apr  8 21:41 phpinfo.php

Visualize the details of files and folders

[root@iZuf61bne18a1bikx6z7bvZ yum]# ls -lh
total 20K
drwxr-xr-x. 2 root root 4.0K Nov  5 09:53 fssnap.d
drwxr-xr-x. 2 root root 4.0K Feb 15 17:25 pluginconf.d
drwxr-xr-x. 2 root root 4.0K Apr  8 21:07 protected.d
drwxr-xr-x. 2 root root 4.0K Feb 15 17:23 vars
-rw-r--r--. 1 root root  444 Nov  5 09:53 version-groups.conf

List folder information

[root@iZuf61bne18a1bikx6z7bvZ yum]# ls -ld /etc/
drwxr-xr-x. 78 root root 4096 Apr  8 21:08 /etc/

Classification of documents by special characters

[root@iZuf61bne18a1bikx6z7bvZ /]# ls -F
bin@  boot/  dev/  etc/  home/  lib@  lib64@  lost+found/  media/  mnt/  opt/  proc/  root/  run/  sbin@  srv/  sys/  tmp/  usr/  var/

List files and mark color classifications

Tags: Linux yum DBus PHP Session

Posted on Mon, 22 Apr 2019 09:39:34 -0700 by steven fullman