Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-24-2009, 02:09 AM   #1
LQ Newbie
Registered: Apr 2009
Posts: 2

Rep: Reputation: 0
Getting all the files modified today & store the names in a variable as , separated

Hi all,

I am very new to linux. I have a question. I have a folder. I want to find the list of files that are modified today and store all those file names in a variable as comma separated values. I thought of using
"find . -mtime 0" command to find the list of files modified today. Also to get those values of file name stored in a variable, I thought of using
"find . -mtime 0 | awk '{print $1}'" command. But 1 value is hard coded in that. I need to know how many outputs coming out of "find . -mtime 0" command so that i can dynamically vary my print statement in awk.

Any help on this.

Thanks in advance.

Old 04-24-2009, 02:14 AM   #2
LQ Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Couldn't you just use something like

find . -mtime 0 -printf "%p, "

Edit - you may want to use the -daystart option if you really want the files from today ratehr than last 24 hours.

find ./ -daystart -mtime 0 -printf "%p, "

Last edited by billymayday; 04-24-2009 at 02:18 AM.
Old 04-24-2009, 02:58 AM   #3
Registered: Sep 2003
Location: UK
Distribution: I use 'em all ;-)
Posts: 275

Rep: Reputation: 38
MYARRAY=( `find . -mtime 0` )

for file in ${MYARRAY[@]
echo $file
Old 04-27-2009, 05:01 AM   #4
LQ Newbie
Registered: Apr 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Hi all,,

Thanks for ur replies.

I got that issue solved with the help of outfilename=$(find . -type f -mtime 0 | tr '\n' ',');

I am facing another issue with this find.....

Here is my program

# Environmental set up

# Initialize error code

if [ "$envSet" = "$2" ]
# Set batch environment
. $1/jobs/ $1

echo "file name ---------"$filename
echo "BATCH_HOME ---------"$BATCH_HOME
echo "3 ---------"$3

#Frame the output file name
if [ "$filename" != "" ]
echo "Inside IF"
#if executed, then the filename of the zip will be taken from that
outfilename = $filename;
echo "Inside ELSE"
#if not executed, then the filename will be the list of files that are last modified today
cd $BATCH_HOME/data/output/$3
outfilename=$(find . -type f -mtime 0 | tr '\n' ',');

echo "outifle-------"$outfilename

# Call the program
$JAVA_HOME/java -Xmx1024m -Djava.awt.headless=true \
-DOUTPUT_PATH=$BATCH_HOME/data/output/$3/ \
-DOUTPUT_FILE=$outfilename \
batch.EmailReportsBatch > $LOG_DIR/EmailReportsBatch.log

# Check if java command fails
if test ! $? -eq 0

When i execute this pgm i am getting the outfilename value correctly. But when it is invoked from main shell(this main shell will generate the reports and then call this shell to mail all the generated reports) this outfilename is giving me one value less than what it is supposed to give. That is if 3 files are modified today, it is giving only 2 file names. Any suggestion why this is happening? But when BATCH_HOME, $3 values are echoed they show the same results...


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
Where does KDE store virtual desktop names? grunt547 Linux - Desktop 11 04-03-2009 04:51 PM
Linux store names and ideas. maxie General 19 03-21-2006 05:48 AM
monitoring directory to get the modified file names appas Programming 1 09-06-2004 04:56 AM
Save last modified to a variable twantrd Programming 2 03-31-2004 03:57 AM
Store PATH variable permanently Skute Linux - Software 8 01-15-2004 04:05 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:59 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration