The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Empty Files DNAx86 Shell Programming and Scripting 3 04-18-2008 09:45 PM
How to parse 2 files simultaneously Awanka Shell Programming and Scripting 8 04-12-2007 08:00 PM
How to find files not empty? videsh77 UNIX for Dummies Questions & Answers 2 02-26-2006 09:15 AM
deleting the empty files srivsn Shell Programming and Scripting 1 02-08-2006 06:39 AM
move files from folder thats are not empty Steven UNIX for Dummies Questions & Answers 8 11-21-2001 10:05 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-14-2008
na5m's Avatar
na5m na5m is offline
Registered User
  
 

Join Date: Jun 2008
Location: Sacramento, CA
Posts: 15
simultaneously create three empty files?

I can't get touch to simultaneously create three empty files file1, file2, file3. I tried:
Code:
$ touch file[1-3]
but all I got was one file:
Code:
$ file[1-3]
What did I do wrong?
  #2 (permalink)  
Old 06-14-2008
Perderabo's Avatar
Perderabo Perderabo is online now Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,117
With file[1-3], the current directory is searched and if filenames matching the pattern exist, the pattern is replaced with the list. Otherwise, the pattern is left alone.

If you:
touch file1 file2 file3 file4 file5
first, you command would update the timestamp on the first three.

What would you expect:
touch *
to do? Create all possible file names????
  #3 (permalink)  
Old 06-14-2008
na5m's Avatar
na5m na5m is offline
Registered User
  
 

Join Date: Jun 2008
Location: Sacramento, CA
Posts: 15
Quote:
What would you expect:
touch *
to do? Create all possible file names????
Now that would eat up some serious disk space

So there's no tricky way to use touch to create multiple files simultaneously in one brief command?
  #4 (permalink)  
Old 06-14-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Use a loop,

Code:
i=1
while [ $i -le 5 ]; do touch file$i; i=`expr $i + 1`; done
  #5 (permalink)  
Old 06-14-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 708
Hi.

Some shells may help:

Code:
#!/bin/bash3 -

# @(#) s1       Demonstrate brace expansion.

echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1)
echo

rm -f scratch*
echo " Situation before:"
ls scratch*

touch scratch{1..3}

echo
echo " Situation after :"
ls scratch*

exit 0
Producing:
Code:
% ./s1

(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 3.00.16(1)-release

 Situation before:
ls: scratch*: No such file or directory

 Situation after :
scratch1  scratch2  scratch3
See man page for details -- also worked on ksh 93s+ ... cheers, drl
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0