LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-27-2011, 08:50 PM   #1
HalfMadDad
Member
 
Registered: Jun 2010
Location: Canada
Distribution: Slackware, systemd-garbage
Posts: 143

Rep: Reputation: 9
touch command for directories?


Hi Everyone

touch creates a file or updates a timestamp. mkdir throws an error if the directory already exists.

Is there a command that that would make directories but not throw errors if they are already present and that will not clobber them if they already exist? , much like touch.

Thanks for reading-Patrick
 
Old 09-27-2011, 09:22 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
mkdir -p
 
1 members found this post helpful.
Old 09-27-2011, 09:27 PM   #3
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
mkdir will not clobber a directory if it already exists. It will just skip it and move on.

You can do this a couple of ways (bash).

Code:
mkdir -p /some/directory

#or this way
if [ ! -d /some/directory ];then mkdir -p /some/directory;fi
See man mkdir for what -p does.
 
1 members found this post helpful.
Old 09-27-2011, 09:53 PM   #4
HalfMadDad
Member
 
Registered: Jun 2010
Location: Canada
Distribution: Slackware, systemd-garbage
Posts: 143

Original Poster
Rep: Reputation: 9
Thanks David and sag47. Have a great day!
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Command line: chown command recursively on invisible directories? JZL240I-U Linux - Software 9 10-29-2010 04:34 AM
Behavior of Command Line Expansion in touch command ahmedb72 Linux - Newbie 10 07-01-2009 02:51 AM
tips with touch command rajveervashisth Linux - Newbie 2 08-06-2008 01:22 PM
touch command not found Mystified Linux From Scratch 1 03-28-2005 11:38 AM
touch command dominant Linux - Newbie 6 02-17-2004 04:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:42 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
Open Source Consulting | Domain Registration