From 9153666e72effdf56ce19332f953caff7d173a7e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 31 Jan 2019 17:34:24 +0100 Subject: [PATCH] Userland: /bin/ls shouldn't display inode numbers by default. Added the -i option to ls which turns on inode number display. --- Userland/ls.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Userland/ls.cpp b/Userland/ls.cpp index da69b1e232..a431cf8af5 100644 --- a/Userland/ls.cpp +++ b/Userland/ls.cpp @@ -15,11 +15,13 @@ static int do_dir_short(const char* path); static bool flag_colorize = true; static bool flag_long = false; static bool flag_show_dotfiles = false; +static bool flag_show_inode = false; int main(int argc, char** argv) { + static const char* valid_option_characters = "laiG"; int opt; - while ((opt = getopt(argc, argv, "laG")) != -1) { + while ((opt = getopt(argc, argv, valid_option_characters)) != -1) { switch (opt) { case 'a': flag_show_dotfiles = true; @@ -30,8 +32,11 @@ int main(int argc, char** argv) case 'G': flag_colorize = false; break; + case 'i': + flag_show_inode = true; + break; default: - fprintf(stderr, "usage: ls [-laG] [path]\n"); + fprintf(stderr, "usage: ls [-%s] [path]\n", valid_option_characters); return 1; } } @@ -116,7 +121,8 @@ int do_dir(const char* path) return 2; } - printf("%08u ", de->d_ino); + if (flag_show_inode) + printf("%08u ", de->d_ino); if (S_ISDIR(st.st_mode)) printf("d");