A Linux ls command every day

Source: Internet
Author: User
Tags syslog rsync

The ls command is the most commonly used command under Linux. The LS command is the abbreviation for list. LS is used to print out the list of current directories if LS specifies a different directory then the list of files and folders in the specified directory will be displayed. The LS command not only allows you to view the files contained in a Linux folder but also to view file permissions (including directories, folders, file permissions) to view directory information, and so on . Ls commands are used in daily Linux operations !

1. command format:

ls [options] [directory name]

2. command function:

lists all subdirectories and files in the destination directory.

3. Common parameters:

-a,–all lists all files in the directory, including the implied files that begin with the.

- L, in addition to the file name, also lists the permissions, owner, file size, and more

-h,–human-readable, used with-l, to list file sizes in an easy-to-understand format (e.g. 1K 234M 2G)

- D, which displays the relevant properties of the directory itself, typically used with-l

-r,–reverse in reverse alphabetical order

-r,–recursive List all directory layers and sub-files for all current directories


4. Example:

Example one: List all directories and files under the root directory

[BEGIN] 2015/12/19 21:14:26[[email protected] ~]# pwd/root[[email protected] ~]# ls-a.  .. Anaconda-ks.cfg. bash_history. bash_logout. Bash_profile bashrc. CSHRC install.log install.log.syslog sersync2.5. 4_64bit_binary_stable_final.tar.gz. Tcshrc[end] 2015/12/19 21:14:39

Example Two: list all the directories and files under the root directory and the permissions, owner, file size, and other information in detail to

[begin] 2015/12/19 21:17:39[[email protected] ~]#  PWD/ROOT[[EMAIL PROTECTED] ~]# LS -LTOTAL 772-RW-------.  1 root  Root   3326 dec  3 06:38 anaconda-ks.cfg-rw-r--r--.  1 root  root  39935 dec  3 06:38 install.log-rw-r--r--.  1 root  root   9154 dec  3 06:35 install.log.syslog-rw-r--r--.  1  root root 727290 oct 25  2011 sersync2.5.4_64bit_binary_stable_ final.tar.gz[end] 2015/12/19 21:17:56 

   list all directories and files under the root directory (e.g. 1K 234M 2G) and other information are listed in detail to

[begin] 2015/12/19 21:19:45[[email protected] ~]#  PWD/ROOT[[EMAIL PROTECTED] ~]# LS -HLTOTAL 772K-RW-------.  1 root  root 3.3k dec  3 06:38 anaconda-ks.cfg-rw-r--r--.  1 root  Root  39k dec  3 06:38 install.log-rw-r--r--.  1 root root  9.0k dec  3 06:35 install.log.syslog-rw-r--r--.  1 root root  711k oct 25  2011 sersync2.5.4_64bit_binary_stable_final.tar.gz[end] 2015/ 12/19 21:20:01 

Example four: List root directory permissions, owner, file size

[BEGIN] 2015/12/19 21:28:33[[email protected] ~]# pwd/root[[email protected] ~]# ls-dldr-xr-x---. Root root 4096 Dec 17 22:08. [Email protected] ~]# CD. [Email protected]/]# pwd/[[email protected]/]# ls-dl|grep rootdr-xr-xr-x. Root root 4096 Dec 15 03:15. [END] 2015/12/19 21:30:59

  list the sub-files under the root directory

[Begin] 2015/12/19 21:37:36[[email protected] ~]# pwd/root[[email protected]  ~]# lsanaconda-ks.cfg        install.log          mysql-5.6.24  php-5.5.26              redis-3.0.5          rsync-3.0.7.tar.gz  rubygems-1.8.24                    svn_merge1.shdownload?source=files   install.log.syslog  nginx-1.8.0   postfix-2.2.10          redis-3.0.5.tar.gz  ruby-2.0.0-p353      Sqlite-autoconf-3070900           yaml-0.1.4index.html              jb                   node-v0.6.6   postfix-2.2.10.tar.gz  rsync-3.0.7          rubygame-2.3.0       sqlite-autoconf-3070900.tar.gz.1  yaml-0.1.4.tar.gz.1[[email protected] ~]# ls - ryaml-0.1.4.tar.gz.1  sqlite-autoconf-3070900.tar.gz.1  rubygame-2.3.0       rsync-3.0.7         postfix-2.2.10.tar.gz   node-v0.6.6   jb                   index.htmlyaml-0.1.4            sqlite-autoconf-3070900            Ruby-2.0.0-p353     redis-3.0.5.tar.gz  postfix-2.2.10          nginx-1.8.0   install.log.syslog  download?source=filessvn_merge1.sh         rubygems-1.8.24                    rsync-3.0.7.tar.gz  redis-3.0.5          php-5.5.26              mysql-5.6.24  install.log          anaconda-ks.cfg[end] 2015/12/19 21:37:50

Example SIX: reverse alphabetical order List sub-files under the root directory

[[email protected] ~]# pwd/root[[email protected] ~]# tree.├── a│??]  └── b│??      └── c│??          └── d│??              └── f├──  Anaconda-ks.cfg├── install.log└── install.log.syslog5 directories, 3 files[[email  protected] ~]# [[email protected] ~]# tree.├── a│??  └── b│??      └── c│??          └── d│??              └── f├──  Anaconda-ks.cfg├── install.log└── install.log.syslog5 directories, 3 files[[email  protected] ~]# ls -R.:a  anaconda-ks.cfg  install.log   Install.log.syslog./a:b./a/b:c./a/b/c:d./a/b/c/d:f./a/b/c/d/f:[[email protected] ~]# pwd/root[end] 2015/12/19 21:45:38 

Extended:

1. Display a list of color catalogs

Open/ETC/BASHRC and add the following line:

Alias ls= "LS--color"

The next time you start bash, you'll be able to display a list of colored catalogs as you would in Slackware, where the meanings of colors are as follows:

1. Blue---Directory

2. Green---executable file

3. Red--Compress files

4. Light blue--linked files

5. Gray--Other files





A Linux ls command every day

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.