Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the verbose option in mkdir?

I was working my way through a primer on Shell (Bash) Scripting and noticed the manpage of mkdir describes a verbose option which displays a message when a directory is created:

-v, --verbose
       print a message for each created directory

It seems mkdir -v has a pre-defined message it prints. Is there a way to print a custom message? Is there a way to permanently set a custom message instead of the default message?

like image 223
pranav Avatar asked Dec 25 '22 23:12

pranav


2 Answers

You can create a script like this:

#/bin/bash

/bin/mkdir "$@" |sed -e"s/mkdir: created directory /$USER created folder /"

Then run that script rather than mkdir.

Modify that script for each message you want to change by adding an additional -e"s/x/y" to the sed.

If you insist on it being named mkdir, then you can put it in your search path before mkdir.

I would not recommend naming it mkdir. You will only cause yourself grief for other scripts that call mkdir

like image 32
Be Kind To New Users Avatar answered Jan 05 '23 05:01

Be Kind To New Users


From the source code for mkdir.c, this is the section that deals with the -v option:

    case 'v': /* --verbose  */
      options.created_directory_format = _("created directory %s");
      break;

As you can see, the string that is used is hard-coded into the source. To permanently change the message to a custom message, one can modify this section of the source code and recompile mkdir.

like image 175
John1024 Avatar answered Jan 05 '23 05:01

John1024