LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-13-2014, 06:31 AM   #1
SmurfGGM
Member
 
Registered: Jul 2008
Posts: 49

Rep: Reputation: 0
Find command - alert on files not found


Hi readers.

I am trying to run a find command and would like to display a message on any of the files that are not found.

I have files in my file_list.tmp that don't exist and would like that to be highlighted in the code below ..

Code:
while read line
do
find $CFXHOME -type f -name $line | grep -v fixes >> $FIXDIR/efin_files.tmp
done < file_list.tmp
backupcount=`wc -l efin_files.tmp | cut -f1 -d' '`
Many thanks.
 
Old 06-13-2014, 06:46 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Maybe something like

Code:
while read line
do
  FILES=$(find $CFXHOME -type f -name $line)
  if [ -z '$FILES" ] ;then
      echo "Missing: $line"
  else
      echo $FILES | grep -v fixes >> $FIXDIR/efin_files.tmp
  fi
done < file_list.tmp
backupcount=`wc -l efin_files.tmp | cut -f1 -d' '`
 
Old 06-13-2014, 07:11 AM   #3
SmurfGGM
Member
 
Registered: Jul 2008
Posts: 49

Original Poster
Rep: Reputation: 0
Thanks but that didn't work.

Only 1 file (instead of 9) is being written to $FIXDIR/efin_files.tmp and FILES=$(find $CFXHOME -type f -name $line) isn't producing anything
 
Old 06-13-2014, 08:22 AM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Change that find command to
Code:
find "$CFXHOME/$line" -type f ! -name '*fixes*' >> "$FIXDIR"/efin_files.tmp
Now, find will complain if the file doesn't exist, and filtering out names that contain "fixes" is done right there by find, eliminating the need for grep. I've also added quoting to protect against names containing spaces or characters special to the shell. That might not be a problem in this case, but it's just good practice.

The only thing that this will silently ignore would be a name that exists but fails the "-type f" test.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find command returning success even when no files are found LarryBear Linux - Newbie 2 09-12-2013 04:58 PM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 05:55 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 04:45 PM
How to find files and copy the found files to the floppy in one command justmehere Linux - Newbie 11 05-04-2008 11:29 PM
egrep to find a command not found string romainp Linux - General 1 09-07-2007 03:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:34 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