LinuxQuestions.org
Register a domain and help support LQ
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 06-19-2013, 02:56 PM   #1
anandg111
Member
 
Registered: Jan 2012
Posts: 56

Rep: Reputation: Disabled
mkdir a/b/c # where a/b does not exists. is it possible to create it ?


Is is possible to create the directories in following manner.

for example my home dir is empty
and i want to create dir a/b/c

mkdir a/b/c # where a/b does not exists.
 
Old 06-19-2013, 03:05 PM   #2
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 304

Rep: Reputation: 121Reputation: 121
You may need the -p option (to make parent directories as needed):
Code:
$ mkdir a/b/c
mkdir: cannot create directory ‘a/b/c’: No such file or directory
$ mkdir -p a/b/c
$ mkdir -p -v c/d/e
mkdir: created directory ‘c’
mkdir: created directory ‘c/d’
mkdir: created directory ‘c/d/e’
$
Please use the available documentation to look these things up, for example:
Code:
$ man mkdir

Last edited by Beryllos; 06-19-2013 at 03:07 PM.
 
1 members found this post helpful.
Old 06-19-2013, 03:27 PM   #3
anandg111
Member
 
Registered: Jan 2012
Posts: 56

Original Poster
Rep: Reputation: Disabled
thanks for your quick reply beryllos
I have one more question, is it possible to delete the same path of dirs if all the dirs are not empty ?
 
Old 06-19-2013, 03:33 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
You mean:

Code:
rm -fr a
?
 
1 members found this post helpful.
Old 06-19-2013, 04:42 PM   #5
anandg111
Member
 
Registered: Jan 2012
Posts: 56

Original Poster
Rep: Reputation: Disabled
yes i was looking for this only.
Thanks...
 
Old 06-19-2013, 04:47 PM   #6
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 304

Rep: Reputation: 121Reputation: 121
Quote:
Originally Posted by suicidaleggroll View Post
Code:
rm -fr a
anandg111 and newbies, please note, 'rm -fr a' will remove the directory 'a', along with all of its contents.

Feel free to refer to the documentation for additional details:
Code:
$ man rm
 
Old 06-19-2013, 04:51 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by Beryllos View Post
anandg111 and newbies, please note, 'rm -fr a' will remove the directory 'a', along with all of its contents.
That's what he asked for.
 
Old 06-19-2013, 11:02 PM   #8
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 304

Rep: Reputation: 121Reputation: 121
Quote:
Originally Posted by anandg111 View Post
... is it possible to delete the same path of dirs if all the dirs are not empty ?
suicidaleggroll, I get it, but I posted my last message because the question is unclear or ambiguous. The requirements should be defined more clearly. For example, if the directory tree has other branches, like a/d or a/b/e, should they be preserved? I don't intend to pursue that question; I am just saying the wording was a little hazy.
 
Old 06-19-2013, 11:22 PM   #9
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by Beryllos View Post
suicidaleggroll, I get it, but I posted my last message because the question is unclear or ambiguous. The requirements should be defined more clearly. For example, if the directory tree has other branches, like a/d or a/b/e, should they be preserved? I don't intend to pursue that question; I am just saying the wording was a little hazy.
True, and "rm -fr" is a dangerous command. Mixed with a wildcard and run and run as the wrong user in the wrong location it could instantly spell disaster for any system. Anybody who does not get a little chill down their spine when typing "rm -fr" should not be administering any operational Linux system.
 
  


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: cannot create multi-level directory Jenny Peng Linux - Networking 2 08-29-2012 10:52 PM
mkdir: cannot create directory `work': Permission denied NikeshVarghese Linux - Newbie 1 06-13-2012 03:43 AM
[SOLVED] How to create directories using mkdir functio robertjinx Programming 7 08-14-2011 07:00 AM
[SOLVED] "sudo: Can't mkdir /var/run/sudo/%user%: File exists" CNBarnes Linux - Server 7 01-10-2011 05:11 PM
[SOLVED] line that checks if dir "TEST" exists. If so, nothing, of not mkdir Mike_V Programming 5 08-26-2010 09:44 AM


All times are GMT -5. The time now is 08:24 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration