LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 01-25-2016, 05:40 AM   #1
ostene
Member
 
Registered: Jul 2006
Location: Lidingo, Sweden
Distribution: Kubuntu
Posts: 54

Rep: Reputation: 1
"touch" do not make content in file


Hello,

This command is from a site and should fill library with 100
files with the number "i" in every file.

for i in `seq 1 100`;do touch /home/myname/tmp/foo/file$i;done

It gives the files but every file is empty.
Sorry I can not see what is wrong.

Scientific Linux 7.1 64-bit, KDE desktop,

Thanks ostene
 
Old 01-25-2016, 06:15 AM   #2
Soadyheid
Senior Member
 
Registered: Aug 2010
Location: Near Edinburgh, Scotland
Distribution: Cinnamon Mint 20.1 (Laptop) and 20.2 (Desktop)
Posts: 1,672

Rep: Reputation: 486Reputation: 486Reputation: 486Reputation: 486Reputation: 486
Code:
$ touch <filename>
is used to create an empty file called <filename> so your command is doing exactly what you're asking it to do.

Play Bonny!

 
Old 01-25-2016, 06:23 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
To put the number into the file, you could do it like this:

Code:
for i in `seq 1 100`;do echo $i > /home/myname/tmp/foo/file$i ;done
 
Old 01-25-2016, 07:04 AM   #4
huffdad
Member
 
Registered: Jan 2006
Location: Missouri
Distribution: Slackware & LFS
Posts: 31

Rep: Reputation: 6
"touch" only makes sure that a file exists. If it does exist, then touch does not change the file. If the file does not exist, then touch creates the file, but does not add anything to it.
 
Old 01-26-2016, 04:36 PM   #5
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
Originally Posted by huffdad View Post
"touch" only makes sure that a file exists. If it does exist, then touch does not change the file. If the file does not exist, then touch creates the file, but does not add anything to it.
Actually touch updates the time stamp of an existing file.

Example:
Code:
$ ls -al myfile
-rw-r--r-- 1 beryllos beryllos 1476 Oct  1  2014 myfile
$ touch myfile
$ ls -al myfile
-rw-r--r-- 1 beryllos beryllos 1476 Jan 26 17:27 myfile
Find out more in the manual here.

or here:
Code:
$ man touch

Last edited by Beryllos; 01-26-2016 at 04:37 PM.
 
Old 01-26-2016, 06:04 PM   #6
huffdad
Member
 
Registered: Jan 2006
Location: Missouri
Distribution: Slackware & LFS
Posts: 31

Rep: Reputation: 6
Ah, thanks for that. That's a detail I've never needed before. Will keep it in mind for future reference. Thanks for the correction. I don't like giving false info.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
kernel make error: "vmlinux.o no such file ..." and make -d "Reaping losing ..." micscherer Linux - Kernel 3 06-12-2012 07:29 AM
[SOLVED] redirection of "ls" command to file gives chaotic content SharpyWarpy Linux - General 3 07-31-2009 03:13 AM
how to use "touch" for a hole file tree mandavi Linux - General 11 07-05-2005 05:16 AM
Parasite in a file name with touch & ">" orgazmo Programming 25 05-24-2005 03:28 AM
Can't boot Mandrake 10.0, "Cannot touch, Read-Only File System" RasutoIbuki Mandriva 5 07-23-2004 08:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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