• Home
  • Raw
  • Download

Lines Matching +full:ls +full:- +full:files

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...]
23 List files.
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
42 files: exe=green suid=red suidfile=redback stickydir=greenback
46 -f unsorted -r reverse -t timestamp -S size
52 // test sst output (suid/sticky in ls flaglist)
54 // ls -lR starts .: then ./subdir:
60 struct dirtree *files, *singledir;
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 = (toys.optflags & 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 int fd = openat(dirtree_parentfd(new), new->name, in filter()
200 if (fd != -1) { in filter()
201 if (-1 == lsm_fget_context(fd, (char **)&new->extra) && errno == EBADF) in filter()
212 lsm_lget_context(hack, (char **)&new->extra); in filter()
217 if (CFG_TOYBOX_LSM_NONE || !new->extra) new->extra = (long)xstrdup("?"); in filter()
220 if (flags & FLAG_u) new->st.st_mtime = new->st.st_atime; in filter()
221 if (flags & FLAG_c) new->st.st_mtime = new->st.st_ctime; in filter()
222 new->st.st_blocks >>= 1; in filter()
225 if (!(flags & FLAG_A) && new->name[0]=='.') return 0; in filter()
247 // For -x, calculate height of display, rounded up in next_column()
248 height = (dtlen+columns-1)/columns; in next_column()
252 if (height*columns - dtlen >= height) { in next_column()
266 ul -= transition; in next_column()
267 *xpos = ul % (columns-1); in next_column()
269 return (*xpos*height) + widecols + (ul/(columns-1)); in next_column()
287 // Output types -1, -l, -C, or stream
297 if (-1 == dirfd) { in listfiles()
298 perror_msg_raw(indir->name); in listfiles()
307 if (!indir->parent) { in listfiles()
309 // In this case only show dirname/total header when given -R. in listfiles()
310 dt = indir->child; in listfiles()
311 if (dt && S_ISDIR(dt->st.st_mode) && !dt->next && !(flags&(FLAG_d|FLAG_R))) in listfiles()
313 listfiles(open(dt->name, 0), TT.singledir = dt); in listfiles()
319 for (;dt; dt = dt->next) filter(dt); in listfiles()
322 // This reads/saves contents to display later, except for in "ls -1f" mode. in listfiles()
330 for (dtlen = 0, dt = indir->child; dt; dt = dt->next, dtlen++) in listfiles()
335 // Label directory if not top of tree, or if -R in listfiles()
336 if (indir->parent && (TT.singledir!=indir || (flags&FLAG_R))) in listfiles()
354 blocks += sort[ul]->st.st_blocks; in listfiles()
357 if ((flags&(FLAG_h|FLAG_l|FLAG_o|FLAG_n|FLAG_g|FLAG_s)) && indir->parent) { in listfiles()
366 // columns can't be more than toybuf can hold, or more than files, in listfiles()
372 for (;columns > 1; columns--) { in listfiles()
382 totlen += (*len)-colsizes[c]; in listfiles()
398 struct stat *st = &(sort[next]->st); in listfiles()
399 mode_t mode = st->st_mode; in listfiles()
402 // Skip directories at the top of the tree when -d isn't set in listfiles()
403 if (S_ISDIR(mode) && !indir->parent && !(flags & FLAG_d)) continue; in listfiles()
419 width += 2-mm; in listfiles()
424 if (flags & FLAG_i) printf("%*lu ", totals[1], (unsigned long)st->st_ino); in listfiles()
427 print_with_h(tmp, st->st_blocks, 512); in listfiles()
436 printf("%s% *ld", tmp, totals[2]+1, (long)st->st_nlink); in listfiles()
441 ii = -totals[3]; in listfiles()
442 if (flags&FLAG_n) printf("%*u", ii, (unsigned)st->st_uid); in listfiles()
443 else draw_trim_esc(getusername(st->st_uid), ii, abs(ii), TT.escmore, in listfiles()
450 ii = -totals[4]; in listfiles()
451 if (flags&FLAG_n) printf("%*u", ii, (unsigned)st->st_gid); in listfiles()
452 else draw_trim_esc(getgroupname(st->st_gid), ii, abs(ii), TT.escmore, in listfiles()
457 printf(" %-*s", -(int)totals[7], (char *)sort[next]->extra); in listfiles()
460 if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode)) in listfiles()
461 printf("% *d,% 4d", totals[5]-4, dev_major(st->st_rdev), in listfiles()
462 dev_minor(st->st_rdev)); in listfiles()
464 print_with_h(tmp, st->st_size, 1); in listfiles()
468 // print time, always in --time-style=long-iso in listfiles()
469 tm = localtime(&(st->st_mtime)); in listfiles()
474 s += sprintf(s, ":%02d.%09d ", tm->tm_sec, (int)st->st_mtim.tv_nsec); in listfiles()
475 strftime(s, sizeof(tmp)-(s-tmp), "%z", tm); in listfiles()
479 printf("%-*s ", (int)totals[7], (char *)sort[next]->extra); in listfiles()
482 color = color_from_mode(st->st_mode); in listfiles()
486 ss = sort[next]->name; in listfiles()
491 printf(" -> "); in listfiles()
495 if (fstatat(dirfd, sort[next]->symlink, &st2, 0)) color = 256+31; in listfiles()
501 printf("%s", sort[next]->symlink); in listfiles()
509 curcol = colsizes[curcol]-(*len)-totpad; in listfiles()
519 if ((flags & FLAG_d) || !S_ISDIR(sort[ul]->st.st_mode)) continue; in listfiles()
521 // Recurse into dirs if at top of the tree or given -R in listfiles()
522 if (!indir->parent || ((flags&FLAG_R) && dirtree_notdotdot(sort[ul]))) in listfiles()
523 listfiles(openat(dirfd, sort[ul]->name, 0), sort[ul]); in listfiles()
524 free((void *)sort[ul]->extra); in listfiles()
540 // Do we have an implied -1 in ls_main()
556 // but currently it has "switch off when this is set", so "-dR" and "-Rd" in ls_main()
560 // Iterate through command line arguments, collecting directories and files. in ls_main()
561 // Non-absolute paths are relative to current directory. Top of tree is in ls_main()
562 // a dummy node to collect command line arguments into pseudo-directory. in ls_main()
563 TT.files = dirtree_add_node(0, 0, 0); in ls_main()
564 TT.files->dirfd = AT_FDCWD; in ls_main()
571 // note: double_list->prev temporarirly goes in dirtree->parent in ls_main()
572 if (dt) dlist_add_nomalloc((void *)&TT.files->child, (void *)dt); in ls_main()
577 dlist_terminate(TT.files->child); in ls_main()
578 for (dt = TT.files->child; dt; dt = dt->next) dt->parent = TT.files; in ls_main()
580 // Display the files we collected in ls_main()
581 listfiles(AT_FDCWD, TT.files); in ls_main()
583 if (CFG_TOYBOX_FREE) free(TT.files); in ls_main()