The r parameter of the LS command represents the recursive listing of all files in all subfolders, 1 means that each row displays only one file or folder, and F means that the output is not sorted, and F indicates that the output of each item is followed by the corresponding */=>@| character at the end of its file type. The effect of LS-R1FF command is implemented by C language, and its source code is as follows:
#include <stdio.h> #include <sys/types.h> #include <dirent.h> #include <sys/stat.h> #include <pwd.h> #include <grp.h> #include <string.h>void listdir (char *); char get_type (struct stat *); int main (int Argc,char * argv[]) {if (argc = = 1) listdir ("."); Else{int index = 1;while (argc > 1) {listdir (Argv[index]); index++;argc--;}} return 0;} void Listdir (char * dirname) {dir * dir;struct stat info;//char pointer[];struct dirent * direntp;if (DIR = Opendir (dirname )) = null) {printf ("%s:\n", dirname), while ((DIRENTP = Readdir (dir)) = null) {char absolute_pathname[255];strcpy ( Absolute_pathname,dirname); strcat (Absolute_pathname, "/"); strcat (absolute_pathname,direntp->d_name); Lstat ( Absolute_pathname,&info);p rintf ("%s", Direntp->d_name);p rintf ("%c\n", Get_type (&info));} printf ("\ n"); Rewinddir (dir); while ((DIRENTP = Readdir (dir)) = NULL) {if (strcmp (Direntp->d_name, ".") = = 0 | | strcmp (Direntp->d_name, "..") = = 0) Continue;char absolute_pathname[255];strcpy (ABSOlute_pathname,dirname); strcat (Absolute_pathname, "/"); strcat (absolute_pathname,direntp->d_name); Lstat ( Absolute_pathname,&info); if (S_isdir ((&info)->st_mode)) Listdir (Absolute_pathname);}} Char get_type (struct stat * info) {if (S_ISCHR (Info->st_mode)) return ' * '; if (S_isdir (Info->st_mode)) return '/'; if (S_issock (Info->st_mode)) return ' = '; if (s_isblk (Info->st_mode)) return ' > '; if (S_islnk (Info->st_mode)) return ' @ '; if (S_isfifo (Info->st_mode)) return ' | '; Return ';}
Write your own shell command ls-r1ff