LinuxQuestions.org
Help answer threads with 0 replies.
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 08-25-2009, 05:11 AM   #1
mlibot
LQ Newbie
 
Registered: Jul 2009
Posts: 16

Rep: Reputation: 0
How to make a sub directory to one directory..?


I have a problem because i do not know how to make a sub directory to one directory. for example..

i have a directory name directory1. and i want to make a new directory named directory2 inside the directory1..

thanks for help
 
Old 08-25-2009, 05:15 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Code:
mkdir directory1/directory2
if you use the -p option of mkdir all the directories specified in the path are created in one shot, so that you can also do mkdir -p dir1/dir2/dir3/dir4/dir5 and so on.
 
Old 08-25-2009, 05:15 AM   #3
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291
cd into directory1 and then mkdir directory2.

In order to have this working you should be in the parent directory of directory1. If directory1 is a subdirectory of /home then you could also give the full path:
Code:
cd /home/directory1
mkdir directory2
Kind regards,

Eric
 
Old 08-25-2009, 06:22 AM   #4
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: /root
Distribution: Slackware & BSD
Posts: 1,223

Rep: Reputation: 231Reputation: 231Reputation: 231
mlibot,

There are two basic ways to make subdirectory.

1. You can cd to the first directory and there issue mkdir command. Example:

user@host--$: mkdir directory1
user@host--$: cd directory1
user@host/directory1 --$: mkdir ./directory2
user@host/directory1 --$: cd directory2
user@host/directory1/directory2 --$: <now you see you are already inside the second sub level of directory1.>
--------

2. You can make all levels of subdirectories in a single command, by using -p parent switch. Example:

user@host --$: mkdir -p /home/directory1/directory2/directory3
user@host --$: cd /home/directory1/directory2/directory3
user@host/home/directory1/directory2/directory3 --$: <see you are here now>
--------

Actually, you can learn many things like this if you consult your terminal manual help. To know about "mkdir" command you can invoke manual by issuing this command:

user@host --$: man mkdir <then the manual is opened>
--------

Hope it helps.

Goodluck.
 
Old 08-26-2009, 01:33 AM   #5
mlibot
LQ Newbie
 
Registered: Jul 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Thanks for the reply... I know that already. but i do this using shell script.. it is possible to make..?

one directory named directory1 then inside directory1 there was another directory named directory2 using shell script..
any idea..?
 
Old 08-26-2009, 01:43 AM   #6
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291Reputation: 1291
Hi,

Of course that's possible. Shell commands can be executed from the console or using a shell script. Of course when using a shell script you need to take care of error handling, for example, first check if a directory you create doesn't already exist.
Code:
mkdir -p /directory1/directory2/directory3
will create the tree structure the same way if executed from console or from a script.

Kind regards,

Eric
 
Old 08-26-2009, 02:55 AM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally Posted by mlibot View Post
Thanks for the reply... I know that already. but i do this using shell script.. it is possible to make..?

one directory named directory1 then inside directory1 there was another directory named directory2 using shell script..
any idea..?
Anything you can do on the command-line you can put
in a script ...


Cheers,
Tink
 
Old 08-26-2009, 09:44 AM   #8
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Rep: Reputation: 36
use the -p flag to make sub directories.
 
  


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
Username & Password Sync Fedora Directory and Microsoft Active Directory karnac01 Fedora 4 07-19-2010 01:51 AM
change default vsftp anonymous accout directory /var/ftp to other directory? hocheetiong Linux - Newbie 2 01-24-2010 07:33 PM
Active Directory User Cannot Write to Samba Home Directory jonwatson Linux - Networking 2 12-19-2006 01:40 PM
LXer: Directory services made easy with Fedora Directory Server LXer Syndicated Linux News 0 12-08-2006 04:54 AM
write permissions for directory - not accidently move/deleted the directory linuxgamer Linux - Newbie 10 12-02-2003 04:04 AM


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