LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 11-05-2011, 07:25 PM   #1
liakouras
LQ Newbie
 
Registered: Nov 2011
Posts: 2

Rep: Reputation: Disabled
Question Change context script


Hello,

I would like to append to the first line of thousands of files the date of creation of each file. Can this be done with a script?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 11-06-2011, 01:27 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
It can be done by a script if it can be done manually from the command prompt. find can be used to generate the list of files to loop through. stat can be used to get the creation date. sed can be used to append the date to the end of the first line but even with the -i option will change the creation date. If that matters to you, make sed output to a temporary file and then use cat or shell input redirection to write the temporary file into the original.
 
Old 11-06-2011, 02:30 AM   #3
liakouras
LQ Newbie
 
Registered: Nov 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Question

Quote:
Originally Posted by catkin View Post
It can be done by a script if it can be done manually from the command prompt. find can be used to generate the list of files to loop through. stat can be used to get the creation date. sed can be used to append the date to the end of the first line but even with the -i option will change the creation date. If that matters to you, make sed output to a temporary file and then use cat or shell input redirection to write the temporary file into the original.

How is SED going to append it to the beginning of the file?
 
Old 11-06-2011, 05:05 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Try searching the web. You don't think you're the first person who's ever needed to insert a line at the beginning of a file before, do you?

This page may be a good starting point:
http://sed.sourceforge.net/sedfaq.html


By the way, in *nix filesystems there is traditionally NO "creation" date. There's only the time of last content modification (mtime), last inode change (ctime), and last access (atime).

The ext4 filesystem has added a creation time (crtime) flag to its metadata, but it isn't yet supported by most system tools, so it remains unused for now.


That is, unless you're talking about the exif tags of image files, or something. So it might help if you described your goals in more detail. Give us some actual examples or something.
 
2 members found this post helpful.
Old 11-06-2011, 06:30 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by David the H. View Post
By the way, in *nix filesystems there is traditionally NO "creation" date. There's only the time of last content modification (mtime), last inode change (ctime), and last access (atime).
Thanks for pointing it out and apologies for not spotting it myself
 
  


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
Change file security context produce errors johnhunsley Linux - General 1 10-26-2011 08:23 PM
Ubuntu Lucid - howto change/configure Nautilus right click context menu apps masta11 Linux - Desktop 1 11-09-2010 05:00 AM
Konsole - Copy & Paste - Context menu change SA_Ron Linux - Desktop 2 08-13-2010 05:31 PM
[SOLVED] Bash script - how to use output from diff and find in context with cpio Mogget Programming 4 01-23-2009 11:38 AM


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