Linux系统下如何一次性创建多个文件夹
展开全部
linux系统下可以使用mkdir命令一次性创建多个文件夹。其形式有如下两种:
命令mkdir filename1 filename2 filename3用于在同一个目录下创建三个文件名分别为filename1,filename2,filename3的文件夹。
命令mkdir -p filename1/filename2/filename3用于递归的创建三个文件夹,其中文件夹filename3在文件夹filename2中,filename2在filename1中,这里会从左往右先检测文件夹是否存在,不存在会先创建该文件夹。
mkdir命令参数说明:
-m, --mode=模式,设定权限<模式> (类似 chmod),而不是 rwxrwxrwx 减 umask
-p, --parents 可以是一个路径名称。此时若路径中的某些目录尚不存在,加上此选项后,系统将自动建立好那些尚不存在的目录,即一次可以建立多个目录;
-v, --verbose 每次创建新目录都显示信息
--help 显示此帮助信息并退出
--version 输出版本信息并退出
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
去下载busybox的源码,在busybox-XXXX/coreutils/mkdir.c
/* vi: set sw=4 ts=4: */
/*
* Mini mkdir implementation for busybox
*
* Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
/* BB_AUDIT SUSv3 compliant */
/* */
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Fixed broken permission setting when -p was used; especially in
* conjunction with -m.
*/
/* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
*/
#include "libbb.h"
/* This is a NOFORK applet. Be very careful! */
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
static const char mkdir_longopts[] ALIGN1 =
"mode\0" Required_argument "m"
"parents\0" No_argument "p"
#if ENABLE_SELINUX
"context\0" Required_argument "Z"
#endif
;
#endif
int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mkdir_main(int argc, char **argv)
{
mode_t mode = (mode_t)(-1);
int status = EXIT_SUCCESS;
int flags = 0;
unsigned opt;
char *smode;
#if ENABLE_SELINUX
security_context_t scontext;
#endif
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
applet_long_options = mkdir_longopts;
#endif
opt = getopt32(argv, "m:p" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext));
if (opt & 1) {
mode = 0777;
if (!bb_parse_mode(smode, &mode)) {
bb_error_msg_and_die("invalid mode '%s'", smode);
}
}
if (opt & 2)
flags |= FILEUTILS_RECUR;
#if ENABLE_SELINUX
if (opt & 4) {
selinux_or_die();
setfscreatecon_or_die(scontext);
}
#endif
if (optind == argc) {
bb_show_usage();
}
argv += optind;
do {
if (bb_make_directory(*argv, mode, flags)) {
status = EXIT_FAILURE;
}
} while (*++argv);
return status;
}
/* vi: set sw=4 ts=4: */
/*
* Mini mkdir implementation for busybox
*
* Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
/* BB_AUDIT SUSv3 compliant */
/* */
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Fixed broken permission setting when -p was used; especially in
* conjunction with -m.
*/
/* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
*/
#include "libbb.h"
/* This is a NOFORK applet. Be very careful! */
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
static const char mkdir_longopts[] ALIGN1 =
"mode\0" Required_argument "m"
"parents\0" No_argument "p"
#if ENABLE_SELINUX
"context\0" Required_argument "Z"
#endif
;
#endif
int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mkdir_main(int argc, char **argv)
{
mode_t mode = (mode_t)(-1);
int status = EXIT_SUCCESS;
int flags = 0;
unsigned opt;
char *smode;
#if ENABLE_SELINUX
security_context_t scontext;
#endif
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
applet_long_options = mkdir_longopts;
#endif
opt = getopt32(argv, "m:p" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext));
if (opt & 1) {
mode = 0777;
if (!bb_parse_mode(smode, &mode)) {
bb_error_msg_and_die("invalid mode '%s'", smode);
}
}
if (opt & 2)
flags |= FILEUTILS_RECUR;
#if ENABLE_SELINUX
if (opt & 4) {
selinux_or_die();
setfscreatecon_or_die(scontext);
}
#endif
if (optind == argc) {
bb_show_usage();
}
argv += optind;
do {
if (bb_make_directory(*argv, mode, flags)) {
status = EXIT_FAILURE;
}
} while (*++argv);
return status;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2018-03-05
展开全部
mkdir a b c d....
mkdir -p a/b/c/d
mkdir -p a/b/c/d
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要么就按照上面的办法,要么就是写个shell脚本,批量执行!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询