Summary of Common LS commands under 20145239 Linux

Source: Internet
Author: User
Tags sorts

Summary of Common LS commands under 20145239 Linux

By learning this week's instructional video and what is required, we find that the LS command has been used for a number of times, but as a beginner, maybe I will only use LS or at most ls-l two usage. But in fact LS is a very practical instruction, so I would like to briefly summarize the common command of LS.

    • LS, English full name: list is the meaning of lists.
Common commands (take the 10io folder of the week as an example):

1. Ls-a lists all files under the file, including "." The beginning of the hidden file (the Linux file hidden file is preceded by the., if present: Represents the existence of the parent directory).

2. Ls-l lists the details of the file, such as creator, creation time, file read-write permission list, and so on.

3. Ls-f add a character to the end of each file to indicate the type of the file. ' @ ' means symbolic link, ' | ' Represents the FIFOs, "/" for the directory, and "=" for the socket.

4. Ls-s prints the size of the file after each file. Size (sizes)

5. Ls-t the sorting of files by time. Time (Hours)

6. ls-a list except "." and ".." Other than the file.

7. Ls-r lists all subdirectories in the directory, equivalent to the "recursive" implementation in our programming.

8. ls-l lists the link names of the files. Link (links)

9. ls-s sort files by size

file color meaning:

Green----> representative executable file
Red----> represent compressed files
Dark blue----> representative catalogue
Light blue-----> on behalf of linked files
Grey----> on behalf of some other files

All LS commands are enumerated:

Here are the options for almost any LS command, many of which may not be commonly used but can be used as an understanding.

-A lists all files under the directory, including the. The implied file at the beginning.
-B lists the characters that are not output in the file name in the form of a backslash and a character number (as in the C language).
-C The modified time of the I node of the output file and sorted by this.
-D Displays the directory as if it were a file, rather than displaying the file below it.
-e outputs the full information of the time, not the output of the brief information.
-f-u the output file is not sorted.
-I index information for the I node of the output file.
-K represents the size of a file in the form of a byte.
-l lists the file details.
-m output file name horizontally and "," as a separator.
-N replaces the name with the uid,gid of the number.
-O Displays detailed information about the file in addition to the group information.
-p-f a character appended to each file name to indicate the type of the file, "*" indicates an executable normal
file; "/" means directory; "@" means symbolic link; "|" Represents FIFOs; "=" represents a socket.
-Q replaces non-output characters.
-R sorts the directory backwards.
-S prints the size of the file after each file name.
-T is sorted by time.
-U sorts the time the file was last accessed.
-X output by column, sorted horizontally.
-a displays except for "." and ".." All files outside the file.
-B does not output backup files ending with "~".
-C output By column, sorted vertically.
-G output file for the group information.
-l lists the link file name instead of the file that is linked to.
-N does not limit file length.
-Q Enclose the file name of the output in double quotation marks.
-r lists all the files under subdirectories.
-S is sorted by file size.
-X sorts with the file's extension (the last character after the.).
-11 lines output only one file.
--color=no do not display color file names
The--HELP displays help information on the standard output.
The--version outputs the version information on the standard output and exits.

Write your own ls command:

In fact, the LS command can be written on its own, but I am trying to write the LS command is still difficult to understand, many functions are not in place. Here is a code that can run the LS command that you have written, so that you can learn the reference.

#include <sys/types.h>#include<sys/stat.h>#include<unistd.h>#include<stdio.h>#include<string.h>#include<errno.h>#include<pwd.h>#include<grp.h>#include<time.h>#include<dirent.h>intFUN1 (Char*dir,Char*filename) {    structstat buf; Char  out[ -]; if(Stat (DIR,&AMP;BUF) <0) {perror ("Stat"); return(-1); }    Switch(Buf.st_mode &s_ifmt) {     Cases_ifreg:printf ("-");  Break;  Cases_ifdir:printf ("D");  Break;  Cases_ifchr:printf ("C");  Break;  Cases_ifblk:printf ("b");  Break;  Cases_ififo:printf ("P");  Break;  Cases_iflnk:printf ("L");  Break;  Cases_ifsock:printf ("s");  Break; }    intN;  for(n=8; n>=0; n--)    {        if(buf.st_mode& (1<<N)) {Switch(n%3)            {             Case 2: printf ("R");  Break;  Case 1: printf ("W");  Break;  Case 0: printf ("x");  Break; default:                 Break; }        }        Else{printf ("-"); }} printf ("%d", Buf.st_nlink); structpasswd *PW; PW=Getpwuid (BUF.ST_UID); printf ("%s",pw->pw_name); structGroup *GR; GR=Getgrgid (Buf.st_gid); printf ("%s",gr->gr_name); printf ("%ld", buf.st_size); structTM *T; T= LocalTime (&buf.st_atime); printf ("%d-%d-%d%d:%d", t->tm_year+1900, T->tm_mon+1, T-Tm_mday, T-Tm_hour, T-tm_min); printf ("%s", filename); if(S_islnk (Buf.st_mode)) {printf (" -"); if(Readlink (filename, out, -)==-1) {} printf ("%s", out); } printf ("\ n"); return 0;}intMainintARGC,Char**argv) {    Charw[ -]; Memset (W,0, -); if(argc<2) strcpy (W,"./"); Elsestrcpy (w,argv[1]); structstat buf; Charname[ -]; if(Stat (W,&AMP;BUF) <0) {fprintf (stderr,"Stat error:%s\n", Strerror (errno)); return-1; }        if(S_isdir (Buf.st_mode)) {DIR*dir; Dir=Opendir (W); structDirent *PDR;  while((pdr = Readdir (dir))! =NULL) {            if(pdr->d_name[0]=='.')            {            }            Else{printf ("dir:%s \ n",pdr->d_name); memset (Name,0, -);            strcpy (NAME,W); //strcat (name, "/");strcat (name,pdr->d_name); FUN1 (name,pdr-d_name); }                    }    }    Else{fun1 (w,w); }    return 0;}

Operation Result:

Summary of Common LS commands under 20145239 Linux

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.