LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-09-2021, 03:14 AM   #1
BudiKusasi
Member
 
Registered: Apr 2017
Distribution: Artix
Posts: 345

Rep: Reputation: 15
mkdir linux alternative that can make directories the paths specified in a file done at once


Is there utility as mkdir linux alternative that can make directories the paths specified in a file done at once in a call, so that far faster, simpler, more efficient?
as mkdir can do it by for loop
Code:
(while read -r s;do
 mkdir -p $s
done ) <Paths
let that util be illustrated as
Code:
mdir -f Paths
as the file contains more 500 lines has a clear difference ?

Last edited by BudiKusasi; 01-09-2021 at 03:23 AM.
 
Old 01-09-2021, 03:39 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
If it is an actual problem (which I doubt), then try something like this:
Code:
cat Paths | xargs mkdir -p --
 
2 members found this post helpful.
Old 01-09-2021, 04:48 AM   #3
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
UUOC.
 
1 members found this post helpful.
Old 01-09-2021, 04:57 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
And why do you care given the hardware we all have available these days ?. What's the real cost of another shell instance ?.
 
Old 01-09-2021, 05:51 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Quote:
Originally Posted by syg00 View Post
And why do you care given the hardware we all have available these days ?. What's the real cost of another shell instance ?.
In this case most probably the cost of the additional shell is negligible. The real problem is the bad habit. In general would be nice to get into the way of doing "best practices". Especially when it is not that difficult.
 
2 members found this post helpful.
Old 01-09-2021, 07:01 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
For example, tar(1) is known to be able to create multiple directories. Though it requires a prepared data-file.
 
1 members found this post helpful.
Old 01-09-2021, 11:06 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Right, `cat` can be left out:
Code:
xargs <Paths mkdir -p --
 
1 members found this post helpful.
Old 01-09-2021, 05:34 PM   #8
BudiKusasi
Member
 
Registered: Apr 2017
Distribution: Artix
Posts: 345

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by NevemTeve View Post
Right, `cat` can be left out:
Code:
xargs <Paths mkdir -p --
@NevemTeve. You're brilliant !!!

the proof of your generous work

$ time (while read -r s;do mkdir -p l$s ;done) <m

real 0m1.403s
user 0m0.291s
sys 0m1.198s


$ time xargs <m mkdir -p --

real 0m0.052s
user 0m0.007s
sys 0m0.045s


Just even 477 lines in m

much low than the actual demand at least 670 lines
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Apache 2.x: http for some paths and https for other paths john lee Linux - Newbie 2 07-17-2012 01:33 AM
[SOLVED] mkdir: cannot creat directory. How to enable mkdir for user in usb dir? Foxbat1155 Linux - Newbie 13 02-16-2012 11:20 AM
how to give options like '-v' for mkdir using system call mkdir() ? nehapawar Linux - Newbie 2 02-05-2010 02:13 AM
Symbolic Links, directories, and relative paths (../). Can it be done? jimwillsher Linux - Newbie 1 03-11-2005 05:27 PM
Automatically resolving WINDOWS paths to pre-configured Linux paths gazzy Linux - General 1 09-05-2003 10:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration