You are not logged in.

#1 2007-02-09 19:03:59

Plexxxy
Member
Registered: 2006-07-31
Posts: 10

[CLI] mkdir from list? [Solved]

I have a bunch of files (archives actually) that each need directories of the same name. There are approximately 400 of these will rather long names, so I have no desire to type them all out. My plan was to output a list of the files from ls, trim the file extensions from the list, and then pipe that list into mkdir. Voila right? Except I can't figure out how to get mkdir to read from the list. I've tried various ways I could think of like cat dirlist | mkdir, mkdir | cat dirlist, etc, but none work.

I know I can't be the first to want to make a list of directories from a list so there must be a way. Heck I used to do it in Windows and we all know how weak that command line is wink

Thanks
Plex

Last edited by Plexxxy (2007-02-09 19:19:36)

Offline

#2 2007-02-09 19:11:29

smoon
Member
Registered: 2005-08-22
Posts: 468
Website

Re: [CLI] mkdir from list? [Solved]

There are probably many ways to achieve what you want. Here's one of them (which requires xargs):

cat dirlist | xargs -L 1 mkdir

Offline

#3 2007-02-09 19:18:51

Plexxxy
Member
Registered: 2006-07-31
Posts: 10

Re: [CLI] mkdir from list? [Solved]

Ahh perfect! Many thanks big_smile

Offline

#4 2007-02-09 22:42:27

lilsirecho
Veteran
Registered: 2003-10-24
Posts: 5,000

Re: [CLI] mkdir from list? [Solved]

cat dirlist | xargs -L 1 mkdir

Did not work on my machine.

Where get xargs?


Prediction...This year will be a very odd year!
Hard work does not kill people but why risk it: Charlie Mccarthy
A man is not complete until he is married..then..he is finished.
When ALL is lost, what can be found? Even bytes get lonely for a little bit!     X-ray confirms Iam spineless!

Offline

#5 2007-02-11 11:48:22

Leffe
Member
Registered: 2006-05-30
Posts: 47

Re: [CLI] mkdir from list? [Solved]

% pacman -Qo `which xargs`
/usr/bin/xargs is owned by findutils 4.2.29-1

Offline

#6 2007-02-12 17:17:04

rhfrommn
Member
From: Minnesota
Registered: 2005-01-13
Posts: 99

Re: [CLI] mkdir from list? [Solved]

Another possibility if you're in ksh or bash is

for i in `cat dirlist`; do
mkdir $i
done

Of course, run that from the directory you want all the new ones to be created in.

Offline

#7 2007-02-12 18:06:53

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: [CLI] mkdir from list? [Solved]

Am I missing something? What's wrong with:

mkdir $(cat dirlist)

Offline

#8 2007-02-13 00:42:22

lilsirecho
Veteran
Registered: 2003-10-24
Posts: 5,000

Re: [CLI] mkdir from list? [Solved]

[root@n6re ~]# mkdir $(cat dirlist)
cat: dirlist: No such file or directory
mkdir: missing operand
Try `mkdir --help' for more information.
[root@n6re ~]#


Prediction...This year will be a very odd year!
Hard work does not kill people but why risk it: Charlie Mccarthy
A man is not complete until he is married..then..he is finished.
When ALL is lost, what can be found? Even bytes get lonely for a little bit!     X-ray confirms Iam spineless!

Offline

#9 2007-02-13 00:46:43

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: [CLI] mkdir from list? [Solved]

rhfrommn wrote:

Another possibility if you're in ksh or bash is

for i in `cat dirlist`; do
mkdir $i
done

Of course, run that from the directory you want all the new ones to be created in.

one line:

for d in $(cat dirlist); do mkdir $d; done

Offline

#10 2007-02-13 01:05:48

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: [CLI] mkdir from list? [Solved]

lilsirecho wrote:

[root@n6re ~]# mkdir $(cat dirlist)
cat: dirlist: No such file or directory
mkdir: missing operand
Try `mkdir --help' for more information.
[root@n6re ~]#

You need a file 'dirlist' with all the directories in it.  smile

Offline

Board footer

Powered by FluxBB