LinuxQuestions.org
Review your favorite Linux distribution.
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 05-26-2011, 08:22 AM   #1
sina_saeedi82
LQ Newbie
 
Registered: Aug 2009
Posts: 6

Rep: Reputation: 0
Unhappy Create a directory named like his Parent Directory


I need to create a directory named just like his parent.
Example:
/home/sina/2004 - Riot On An Empty Street
/home/sina//2004 - Riot On An Empty Street/2004 - Riot On An Empty Street

I tried this but because there is "Space Characters" in the name of Parent directory, my script fails.

Please Help.
 
Old 05-26-2011, 08:42 AM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,225

Rep: Reputation: 2520Reputation: 2520Reputation: 2520Reputation: 2520Reputation: 2520Reputation: 2520Reputation: 2520Reputation: 2520Reputation: 2520Reputation: 2520Reputation: 2520
don't use spaces in the folder names -- simple .
 
Old 05-26-2011, 08:48 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,550

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Or if you must use spaces (I agree it would not be my choice), place quotes around the name to preserve them.
 
Old 05-26-2011, 08:55 AM   #4
Hevithan
Member
 
Registered: Apr 2011
Location: Washington State
Distribution: Zorin5-(Ubuntu 11.04) // Backtrack 5-(Ubuntu 10.04) // Dreamlinux 3.5-(Debian)
Posts: 275
Blog Entries: 5

Rep: Reputation: 40
If you need to separate the words in a filename, I think you can also use underscores instead of spaces and that shouldn't cause any confusion. I'm pretty sure anyway.
 
Old 05-26-2011, 09:16 AM   #5
sina_saeedi82
LQ Newbie
 
Registered: Aug 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by grail View Post
Or if you must use spaces (I agree it would not be my choice), place quotes around the name to preserve them.
Thanks, quotes are the solution
 
Old 05-26-2011, 09:20 AM   #6
sina_saeedi82
LQ Newbie
 
Registered: Aug 2009
Posts: 6

Original Poster
Rep: Reputation: 0
I have some flac archives and I want to convert theme into MP3 and store the MP3 folder into the flac directory with same name.
Now the names problem solved, Thanks friends.

I must copy my script in each directory and run it separately. I want it works recursively and I run it just one time and it detect all of my flac archives automatically. How can I do that?
 
Old 05-26-2011, 11:41 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,550

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Maybe show us what you have so far? The general idea would be to use find to capture your files and then create from there.
 
Old 05-26-2011, 11:55 AM   #8
astromime
LQ Newbie
 
Registered: May 2011
Posts: 26

Rep: Reputation: 13
also, you can escape the meaning of a space with a back slash

so

Code:
This has spaces
would be
Code:
This\ has\ spaces
 
Old 05-26-2011, 12:36 PM   #9
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Quote:
Originally Posted by sina_saeedi82 View Post
I want it works recursively
Code:
find <starting directory> --type d
That will find all the subdirectories and print out a newline-separated list of them.

See man find for more info.

To iterate over lines, use this:

Code:
<command that outputs a newline-separated list> | while read var
do
    # do stuff. "${var}" will contain the current line.
done

Last edited by MTK358; 05-26-2011 at 12:37 PM.
 
  


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
Parent directory owner n_f Linux - Newbie 3 07-04-2009 11:04 AM
mkdir : cannot create directory : no such file or directory patcheezy Linux - Newbie 6 05-13-2009 12:26 PM
shell script: delete all directories named directory.# except directory.N brian0918 Programming 3 07-13-2005 07:54 PM
'cp -rv .*' recurses into the parent directory??? stefanlasiewski SUSE / openSUSE 5 02-02-2005 06:36 PM
mv the contents of one directory to the parent directory warkrime Linux - Newbie 4 07-14-2003 08:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:45 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