creating file and it directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers creating file and it directory
# 1  
Old 09-19-2012
[SOLVED] creating file and it directory

hello,

is there any command that i can use to create a file and also it directory (if not exist)?

example: <command> /home/admin/testdir/test1.txt
desc: this will create test1.txt under testdir directory. but if testdir is not exist it will be created automatically.

thank you...

Last edited by makan; 09-19-2012 at 04:09 AM..
# 2  
Old 09-19-2012
Try something like this..

Code:
[ ! -d test_2 ] && mkdir test_2 || touch test_2/test.txt


Last edited by pamu; 09-19-2012 at 05:59 AM..
This User Gave Thanks to pamu For This Post:
# 3  
Old 09-19-2012
Quote:
Originally Posted by pamu
Try something like this..

Code:
[ ! -d test_2 ] && mkdir test_2 && touch test_2/test.txt

thank you for your help Smilie
# 4  
Old 09-19-2012
You could try:
Code:
mkdir -p /home/admin/testdir; touch /home/admin/testdir/test1.txt

The p option will create the directory if it doesn't exist.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

creating directory from scripts

Dear All, I have a shell scripts which create a directory and perform moving some files, when the script is kept where it is creating directory then it runs fine , but when the scripts is run where it is supposed to be which is different location then where i am creating directory , scripts... (2 Replies)
Discussion started by: guddu_12
2 Replies

2. UNIX for Dummies Questions & Answers

Need help in creating directory

Hello Experts let say we got a line a file named /user/Oracle/my_catalog/default/root/webcat+backup+testing+07192011.atr now i have to create a directory with name webcat backup testing 07192011 by removing + and removing .atr at the given path...can it be possible Please let me know... (4 Replies)
Discussion started by: aks_1902
4 Replies

3. Homework & Coursework Questions

Creating directories within a directory?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Ok i need to create a directory within another directory in one command. I'm already in a directory to. I need to... (6 Replies)
Discussion started by: gangsta
6 Replies

4. UNIX for Dummies Questions & Answers

creating separate directories according to file extension and keeping file in different directory as

unix program to which a directory name will be passed as parameter. This directory will contain files with various extensions. This script will create directories with the names of the extention of the files and then put the files in the corresponding folder. All files which do not have any... (2 Replies)
Discussion started by: Deekay.p
2 Replies

5. Shell Programming and Scripting

Creating Directory

Hi All, As I m very new for Unix, I need to check for a directory and move a file. If Directory is not found, The script should create a directory and move the file. Can any one help here. (7 Replies)
Discussion started by: vikramtk
7 Replies

6. UNIX for Dummies Questions & Answers

Creating a file to count how many files in the directory

hello there i want to creat a file that count how many files i have in the directory. for this i use the command find . -type f | wc -l > 1In1.myfile the problem with this command is that it not update after i add a new file in the directory. Anyone got any ideas how i can... (5 Replies)
Discussion started by: AntiPin
5 Replies

7. Shell Programming and Scripting

Creating date directory and moving files into that directory

I have list of files named file_username_051208_025233.log. Here 051208 is the date and 025233 is the time.I have to run thousands of files daily.I want to put all the files depending on the date of running into a date directory.Suppose if we run files today they should put into 05:Dec:08... (3 Replies)
Discussion started by: ravi030
3 Replies

8. Shell Programming and Scripting

ls > file - Creating file containing the list of all files present in a directory

Hi All, I need to create a file which contains the list of all the files present in that directory. e.g., ls /export/home/user/*.dat > list_file.dat but what i am getting is: $ ls /export/home/user/*.dat > list_file.dat /export/home/user/*.dat: No such file or directory But I have... (1 Reply)
Discussion started by: pranavagarwal
1 Replies

9. UNIX for Advanced & Expert Users

creating directory error

i have create a Directory with "$@#$%" . After creating a Directory, put ls command display "#$%" . Why? (2 Replies)
Discussion started by: lakshmananindia
2 Replies

10. Shell Programming and Scripting

creating a file on remote directory using sftp

Hi, My requirement is to sftp a file from one server to another.After the file is completely transferrred, i should be able to create a text(dummy) file on the remote directory. How could this be accomplished. Any suggestions? (1 Reply)
Discussion started by: borncrazy
1 Replies
Login or Register to Ask a Question