LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-06-2005, 03:22 PM   #1
haora
Member
 
Registered: Mar 2005
Distribution: SuSE 9.1, Ubuntu 5.10
Posts: 69

Rep: Reputation: 15
another shell question..., using mkdir


Hi all, my problem is as follows:

I have a set of .zip files..., and what I want to do, is to create a folder for each file, the folder will be named like this: "filename"_dir (adding the "_dir" string)

But I can't seem to be able to do this using mkdir, what I do is:

mkdir `grep -l '.zip' *`_dir

What I'm I doing wrong???

Thanks in advance....

Fernando
 
Old 04-06-2005, 03:44 PM   #2
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 929

Rep: Reputation: 30
Perhaps try

for i in `ls | grep .zip | tr ".zip" "_dir"`; do mkdir $i; done

Code:
[lthurber@hostname ~/testing]$ ll
total 0
-rw-r--r--    1 lthurber users           0 Apr  6 15:41 stuff1.zip
-rw-r--r--    1 lthurber users           0 Apr  6 15:41 stuff2.zip
-rw-r--r--    1 lthurber users           0 Apr  6 15:41 stuff3.zip
[lthurber@hostname ~/testing]$ for i in `ls | grep .zip | tr ".zip" "_dir"`; do mkdir $i; done
[lthurber@hostname ~/testing]$ ll
total 0
-rw-r--r--    1 lthurber users           0 Apr  6 15:41 stuff1.zip
drwxr-xr-x    2 lthurber users          48 Apr  6 15:43 stuff1_dir
-rw-r--r--    1 lthurber users           0 Apr  6 15:41 stuff2.zip
drwxr-xr-x    2 lthurber users          48 Apr  6 15:43 stuff2_dir
-rw-r--r--    1 lthurber users           0 Apr  6 15:41 stuff3.zip
drwxr-xr-x    2 lthurber users          48 Apr  6 15:43 stuff3_dir
Edit: I just had a thought - I assumed that you wanted "filename".zip to become "filename"_dir - in other words, the directory name should not include the ".zip" part. If I'm mistaken and you really wanted "filename.zip_dir", try this:

for i in `ls | grep .zip`; do k="_dir"; mkdir $i$k; done

Hope that helps!

Last edited by rose_bud4201; 04-06-2005 at 03:50 PM.
 
Old 04-06-2005, 03:48 PM   #3
enemorales
Member
 
Registered: Jul 2004
Location: Santiago, Chile
Distribution: Ubuntu
Posts: 410

Rep: Reputation: 31
I think that you are trying to concatenate the full result of the glob (*zip) with _dir. You could try something like

Code:
for i in *zip; do mkdir ${i}_dir; done
Or, if you want to replace the .zip for _dir, you could also do something like

Code:
for i in *zip; do mkdir ${i%.zip}_dir; done
 
Old 04-06-2005, 03:51 PM   #4
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 929

Rep: Reputation: 30
enemorales beat me to it the "conctenate _dir onto the whole filename" solution. I think we've got the same solution, though his is written more elegantly
 
Old 04-06-2005, 04:02 PM   #5
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
The directories will be created when you unzip the files but if you want to go ahead, try this..
Code:
for i in *.zip; do mkdir `basename "$i" .zip`; done
 
Old 04-06-2005, 04:21 PM   #6
haora
Member
 
Registered: Mar 2005
Distribution: SuSE 9.1, Ubuntu 5.10
Posts: 69

Original Poster
Rep: Reputation: 15
Wow, thanks, I didn't know I could use "for" in the command line....

Thanks again!

Fernando
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
mkdir -p ? shanenin Linux - Software 4 10-19-2011 12:41 PM
mkdir recompilation puishor Programming 4 06-25-2005 05:37 PM
mkdir in / with out being root Gustaf Slackware 5 10-21-2004 03:39 PM
mkdir help... Linux~Powered Linux - Software 2 06-13-2004 12:27 PM
mkdir help ITJedi Linux - Software 1 05-14-2004 06:19 PM


All times are GMT -5. The time now is 02:56 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration