• Home
  • Raw
  • Download

Lines Matching +full:ls +full:- +full:tree

1 /* ls.c - list files
6 * See http://opengroup.org/onlinepubs/9699919799/utilities/ls.html
9 * add -b (and default to it instead of -q for an unambiguous representation
11 * add -Z -ll --color
12 * Posix says the -l date format should vary based on how recent it is
13 * and we do --time-style=long-iso instead
15 USE_LS(NEWTOY(ls, "(color):;(full-time)(show-control-chars)ZgoACFHLRSabcdfhikl@mnpqrstux1[-Cxm1][-C…
17 config LS
18 bool "ls"
21 usage: ls [-ACFHLRSZacdfhiklmnpqrstux1] [--color[=auto]] [directory...]
26 -a all files including .hidden -b escape nongraphic chars
27 -c use ctime for timestamps -d directory, not contents
28 -i inode number -p put a '/' after dir names
29 -q unprintable chars as '?' -s storage used (1024 byte units)
30 -u use access time for timestamps -A list all files but . and ..
31 -H follow command line symlinks -L follow symlinks
32 -R recursively list in subdirs -F append /dir *exe @sym |FIFO
33 -Z security context
36 -1 list one file per line -C columns (sorted vertically)
37 -g like -l but no owner -h human readable sizes
38 -l long (show full details) -m comma separated
39 -n like -l but numeric uid/gid -o like -l but no group
40 -x columns (horizontal sort) -ll long with nanoseconds (--full-time)
41 --color device=yellow symlink=turquoise/red dir=blue socket=purple
46 -f unsorted -r reverse -t timestamp -S size
52 // test sst output (suid/sticky in ls flaglist)
54 // ls -lR starts .: then ./subdir:
76 else if ((len = wcrtomb(buf, wc, 0) ) == -1) len = 1; in crunch_qb()
85 else if (-1 != (j = stridx("\\\a\b\033\f\n\r\t\v", from[i]))) in crunch_qb()
89 len = to-buf; in crunch_qb()
99 // Returns wcwidth(utf8) version of strlen with -qb escapes
107 mode_t mode = st->st_mode; in endtype()
133 struct stat *st = &(dt->st); in entrylen()
137 *len = strwidth(dt->name); in entrylen()
141 len[1] = (flags & FLAG_i) ? numlen(st->st_ino) : 0; in entrylen()
145 len[2] = numlen(st->st_nlink); in entrylen()
146 len[3] = fn ? numlen(st->st_uid) : strwidth(getusername(st->st_uid)); in entrylen()
147 len[4] = fn ? numlen(st->st_gid) : strwidth(getgroupname(st->st_gid)); in entrylen()
148 if (S_ISBLK(st->st_mode) || S_ISCHR(st->st_mode)) { in entrylen()
151 len[5] = numlen(dev_major(st->st_rdev))+5; in entrylen()
152 } else len[5] = print_with_h(tmp, st->st_size, 1); in entrylen()
155 len[6] = (flags & FLAG_s) ? print_with_h(tmp, st->st_blocks, 512) : 0; in entrylen()
156 len[7] = (flags & FLAG_Z) ? strwidth((char *)dt->extra) : 0; in entrylen()
163 int ret = 0, reverse = FLAG(r) ? -1 : 1; in compare()
166 if (dta->st.st_size > dtb->st.st_size) ret = -1; in compare()
167 else if (dta->st.st_size < dtb->st.st_size) ret = 1; in compare()
170 if (dta->st.st_mtime > dtb->st.st_mtime) ret = -1; in compare()
171 else if (dta->st.st_mtime < dtb->st.st_mtime) ret = 1; in compare()
172 else if (dta->st.st_mtim.tv_nsec > dtb->st.st_mtim.tv_nsec) ret = -1; in compare()
173 else if (dta->st.st_mtim.tv_nsec < dtb->st.st_mtim.tv_nsec) ret = 1; in compare()
175 if (!ret) ret = strcmp(dta->name, dtb->name); in compare()
187 xprintf("%s\n", new->name); in filter()
197 (FLAG(L) ? lsm_get_context : lsm_lget_context)(path, (char **)&new->extra); in filter()
203 int fd = openat(dirtree_parentfd(new), new->name, in filter()
206 if (fd != -1) { in filter()
207 if (-1 == lsm_fget_context(fd, (char **)&new->extra) && errno == EBADF) in filter()
218 lsm_lget_context(hack, (char **)&new->extra); in filter()
224 if (CFG_TOYBOX_LSM_NONE || !new->extra) new->extra = (long)xstrdup("?"); in filter()
227 if (flags & FLAG_u) new->st.st_mtime = new->st.st_atime; in filter()
228 if (flags & FLAG_c) new->st.st_mtime = new->st.st_ctime; in filter()
234 if (!(flags & FLAG_A) && new->name[0]=='.') return 0; in filter()
256 // For -x, calculate height of display, rounded up in next_column()
257 height = (dtlen+columns-1)/columns; in next_column()
261 if (height*columns - dtlen >= height) { in next_column()
275 ul -= transition; in next_column()
276 *xpos = ul % (columns-1); in next_column()
278 return (*xpos*height) + widecols + (ul/(columns-1)); in next_column()
300 if (zap && pat[strlen(pat)-1]==' ') strcat(tmp, " "); in zprint()
305 // Output types -1, -l, -C, or stream
315 if (-1 == dirfd) { in listfiles()
316 perror_msg_raw(indir->name); in listfiles()
325 if (!indir->parent) { in listfiles()
327 // In this case only show dirname/total header when given -R. in listfiles()
328 dt = indir->child; in listfiles()
329 if (dt && S_ISDIR(dt->st.st_mode) && !dt->next && !(flags&(FLAG_d|FLAG_R))) in listfiles()
331 listfiles(open(dt->name, 0), TT.singledir = dt); in listfiles()
337 for (;dt; dt = dt->next) filter(dt); in listfiles()
340 // This reads/saves contents to display later, except for in "ls -1f" mode. in listfiles()
348 for (dtlen = 0, dt = indir->child; dt; dt = dt->next, dtlen++) in listfiles()
353 // Label directory if not top of tree, or if -R in listfiles()
354 if (indir->parent && (TT.singledir!=indir || (flags&FLAG_R))) in listfiles()
372 blocks += sort[ul]->st.st_blocks; in listfiles()
375 if ((flags&(FLAG_h|FLAG_l|FLAG_o|FLAG_n|FLAG_g|FLAG_s)) && indir->parent) { in listfiles()
390 for (;columns > 1; columns--) { in listfiles()
401 totlen += (*len)-colsizes[c]; in listfiles()
417 struct stat *st = &(sort[next]->st); in listfiles()
418 mode_t mode = st->st_mode; in listfiles()
422 zap = !st->st_blksize && !st->st_dev && !st->st_ino; in listfiles()
424 // Skip directories at the top of the tree when -d isn't set in listfiles()
425 if (S_ISDIR(mode) && !indir->parent && !(flags & FLAG_d)) continue; in listfiles()
441 width += 2-mm; in listfiles()
446 if (flags & FLAG_i) zprint(zap, "lu ", totals[1], st->st_ino); in listfiles()
449 print_with_h(tmp, st->st_blocks, 512); in listfiles()
459 zprint(zap, "ld", totals[2]+1, st->st_nlink); in listfiles()
464 ii = -totals[3]; in listfiles()
465 if (zap || (flags&FLAG_n)) zprint(zap, "lu", ii, st->st_uid); in listfiles()
466 else draw_trim_esc(getusername(st->st_uid), ii, abs(ii), TT.escmore, in listfiles()
473 ii = -totals[4]; in listfiles()
474 if (zap || (flags&FLAG_n)) zprint(zap, "lu", ii, st->st_gid); in listfiles()
475 else draw_trim_esc(getgroupname(st->st_gid), ii, abs(ii), TT.escmore, in listfiles()
480 printf(" %-*s "+!FLAG(l), -(int)totals[7], (char *)sort[next]->extra); in listfiles()
486 if (!zap && (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))) in listfiles()
487 printf("% *d,% 4d", totals[5]-4, dev_major(st->st_rdev), in listfiles()
488 dev_minor(st->st_rdev)); in listfiles()
490 print_with_h(tmp, st->st_size, 1); in listfiles()
494 // print time, always in --time-style=long-iso in listfiles()
495 tm = localtime(&(st->st_mtime)); in listfiles()
500 s += sprintf(s, ":%02d.%09d ", tm->tm_sec, (int)st->st_mtim.tv_nsec); in listfiles()
501 strftime(s, sizeof(tmp)-(s-tmp), "%z", tm); in listfiles()
507 color = color_from_mode(st->st_mode); in listfiles()
511 ss = sort[next]->name; in listfiles()
516 printf(" -> "); in listfiles()
520 if (fstatat(dirfd, sort[next]->symlink, &st2, 0)) color = 256+31; in listfiles()
526 zprint(zap, "s", 0, (unsigned long)sort[next]->symlink); in listfiles()
534 curcol = colsizes[curcol]-(*len)-totpad; in listfiles()
544 if ((flags & FLAG_d) || !S_ISDIR(sort[ul]->st.st_mode)) continue; in listfiles()
546 // Recurse into dirs if at top of the tree or given -R in listfiles()
547 if (!indir->parent || ((flags&FLAG_R) && dirtree_notdotdot(sort[ul]))) in listfiles()
548 listfiles(openat(dirfd, sort[ul]->name, 0), sort[ul]); in listfiles()
549 free((void *)sort[ul]->extra); in listfiles()
565 // Do we have an implied -1 in ls_main()
581 // but currently it has "switch off when this is set", so "-dR" and "-Rd" in ls_main()
586 // Non-absolute paths are relative to current directory. Top of tree is in ls_main()
587 // a dummy node to collect command line arguments into pseudo-directory. in ls_main()
589 TT.files->dirfd = AT_FDCWD; in ls_main()
596 // note: double_list->prev temporarily goes in dirtree->parent in ls_main()
598 if (dt->again&2) { in ls_main()
601 } else dlist_add_nomalloc((void *)&TT.files->child, (void *)dt); in ls_main()
606 dlist_terminate(TT.files->child); in ls_main()
607 for (dt = TT.files->child; dt; dt = dt->next) dt->parent = TT.files; in ls_main()