Linux find command seems to not transmit all the result to the '-exec command'


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Linux find command seems to not transmit all the result to the '-exec command'
# 1  
Old 04-07-2019
Linux find command seems to not transmit all the result to the '-exec command'

Hello.


From a script, a command for a test is use :

Code:
 find   /home/user_install   -maxdepth 1    -type f     -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end     -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc'

Tha command return the following in the console screen :

Code:
/home/user_install/.bashrc
/home/user_install/.profile
/home/user_install/.i18n
/home/user_install/.inputrc
/home/user_install/.gtkrc-2.0

Within that script the function 'COPY_CHERCHE ' is define as this :

Code:
function COPY_CHERCHE () {

    local B_FILE
    local B_FOLDER_OUT
    local B_EXCLUDE
    local B_FILE_OUT
    local MY_DEBUG=1
    FLAG="0"

#    set -x

    B_FILE="$1"
    B_FOLDER_OUT="$2"
    B_EXCLUDE="$3"
    B_FILE_OUT="$4"
    echo "B_FILE        : $B_FILE"
    echo "B_FOLDER_OUT  : $B_FOLDER_OUT"
    echo "B_EXCLUDE     : $B_EXCLUDE"
    echo "B_FILE_OUT    : $B_FILE_OUT"

# +-------------+
# |    BEGIN    |
# +-------------+

    echo
    echo "--"
    echo

# +-----------+
# |    END    |
# +-----------+

}

export -f COPY_CHERCHE

Now we change the test command with the real command :
Code:
find   /home/user_install   -maxdepth 1    -type f     -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end     -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc'    -exec bash -c 'COPY_CHERCHE  "{}"   /tmp/000_skel_file_folder_PHASE2__2019-04-07___17:23:39     ¤    /tmp/000_skel_file_list_2019-04-07___17:23:39  '  \;

As tou can see, 4 parameters are sent to the function :

Parameter 1 : the file found by the find command --> "{}"
Parameter 2 : a folder name where to copy the founded file
parameter 3 : the character '¤' which is just flag
parameter 4 : a file where to log operations


My problem is that only one file is taken into account : ''/home/user_install/.inputrc"


Here is my debug output :
Code:
!
! +-+-+-+-+-+-+ ENTERING FUNCTION CHERCHE +-+-+-+-+-+-+
!
PATH         :  /home/user_install   -maxdepth 1    -type f 
SEARCH       :  -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' 
DATE         :   -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end  
EXCLUDE      :  ¤ 
EXCLUDE DIR  : 
FOLDER OUT   :  /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41 
FILE OUT     :  /tmp/000_skel_file_list_2019-04-07___18:21:41 
!
! COMMAND LINE : find   /home/user_install   -maxdepth 1    -type f     -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end     -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc'    -exec bash -c 'COPY_CHERCHE  "{}"   /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41     ¤    /tmp/000_skel_file_list_2019-04-07___18:21:41  '  \; 
!
!


+ eval 'find   /home/user_install   -maxdepth 1    -type f     -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end     -name '\''.bashrc'\'' -o -name '\''.profile'\'' -o -name '\''.gtkrc-2.0'\'' -o -name '\''.i18n'\'' -o -name '\''.inputrc'\''    -exec bash -c '\''COPY_CHERCHE  "{}"   /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41     ¤    /tmp/000_skel_file_list_2019-04-07___18:21:41  '\''  \; '
++ find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb '!' -newer /tmp/000_skel_file_end -name .bashrc -o -name .profile -o -name .gtkrc-2.0 -o -name .i18n -o -name .inputrc -exec bash -c 'COPY_CHERCHE  "{}"   /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41     ¤    /tmp/000_skel_file_list_2019-04-07___18:21:41  ' ';'
%
% +-+-+-+-+-+-+ ENTERING FUNCTION COPY_CHERCHE +-+-+-+-+-+-+
%
+ B_FILE=/home/user_install/.inputrc
+ B_FOLDER_OUT=/tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41
+ B_EXCLUDE=¤
+ B_FILE_OUT=/tmp/000_skel_file_list_2019-04-07___18:21:41
+ echo 'B_FILE        : /home/user_install/.inputrc'
B_FILE        : /home/user_install/.inputrc
+ echo 'B_FOLDER_OUT  : /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41'
B_FOLDER_OUT  : /tmp/000_skel_file_folder_PHASE2__2019-04-07___18:21:41
+ echo 'B_EXCLUDE     : ¤'
B_EXCLUDE     : ¤
+ echo 'B_FILE_OUT    : /tmp/000_skel_file_list_2019-04-07___18:21:41'
B_FILE_OUT    : /tmp/000_skel_file_list_2019-04-07___18:21:41
+ echo %
%
+ echo '% +-+-+-+-+-+-+  EXITING FUNCTION COPY_CHERCHE  +-+-+-+-+-+-+'
% +-+-+-+-+-+-+  EXITING FUNCTION COPY_CHERCHE  +-+-+-+-+-+-+
+ echo %
%
+ echo '% +-+-+-+-+-+-+  RETURNING TO FUNCTION CHERCHE  +-+-+-+-+-+-+'
% +-+-+-+-+-+-+  RETURNING TO FUNCTION CHERCHE  +-+-+-+-+-+-+
+ echo %
%
+ echo '!'
!
+ echo '! +-+-+-+-+-+-+ EXITING FUNCTION CHERCHE +-+-+-+-+-+-+'
! +-+-+-+-+-+-+ EXITING FUNCTION CHERCHE +-+-+-+-+-+-+
+ echo '!'
!
+ echo '! +-+-+-+-+-+-+    RETURNING TO MAIN    +-+-+-+-+-+-+'
! +-+-+-+-+-+-+    RETURNING TO MAIN    +-+-+-+-+-+-+
+ echo '!'
!
+ echo '   --- FINISHED ---'
   --- FINISHED ---

Any help is welcome
# 2  
Old 04-07-2019
The default between two conditional arguments like -type f or -name xyz is AND.
You can explicitely write -type f -a -name xyz.
The AND makes it necessary to evaluate the second condition if the first condition evaluated TRUE.
The AND has precedence over the -o OR.
If you want to evaluate an OR before an AND you need to work with parenthesis (that must be quoted to escape their special meaning in the shell).
Code:
find  /home/user_install  -maxdepth 1  -type f  -newer /tmp/000_skel_file_deb   ! -newer /tmp/000_skel_file_end  \( -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc'  \)  -exec ...

This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 04-10-2019
Adding -print to the end of your test command, would allow you to more accurately see when the -exec argument would be invoked.

Code:
find   /home/user_install   -maxdepth 1    -type f \
       -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end \
       -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o  \
       -name '.i18n' -o -name '.inputrc' \
       -print

vrs

Code:
find   /home/user_install   -maxdepth 1    -type f \
       -newer /tmp/000_skel_file_deb  ! -newer /tmp/000_skel_file_end \
       \( -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o  \
          -name '.i18n' -o -name '.inputrc' \) \
       -print

These 2 Users Gave Thanks to Chubler_XL For This Post:
# 4  
Old 05-29-2019
Thank you every body for helping.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and move command with exec

Hi all, I am trying to find files newer than a given file and them mv them to a new location. So I far I have: find . ! -newer <file_name> -exec ls -l {} \; and find . ! -newer <file_name> -exec mv /TEMP_LOCATION {} \; find is not liking this. Anyone know how to modify the last... (2 Replies)
Discussion started by: jonnyd
2 Replies

2. UNIX for Dummies Questions & Answers

What does the '\' in find -exec command

Hi, I have two scripts that remove files. One works fine and is coded find -name "syst*" -mtime +1 -exec rm {} \; The other is almost the same - only thing missing is the '\'. On that script though I keep getting: rm syst1202.file ? etc Does the \ make that difference or is it a... (3 Replies)
Discussion started by: Grueben
3 Replies

3. Shell Programming and Scripting

find command with -exec

Hi all, Please could someone help with the following command requirement. I basically need to find files NEWER than a given file and order the result on time. My attempt so far is as follows: find . -newer <file_name> -exec ls -lrt {} ;\ But I dont seem to get the right result... (12 Replies)
Discussion started by: jonnyd
12 Replies

4. Shell Programming and Scripting

Help! Paste Multiple SQL output result to exec command

Hi, I want to write the shell script to change multple file name (the file name is get from DB) e.g. cp db1.txt file1_new.txt cp db2.txt file2_new.txt cp db3.txt file3_new.txt I have write the script like this: VAR=`sqlplus -s $LOGON @<<ENDOFTEXT set termout off ... (0 Replies)
Discussion started by: jackyntk
0 Replies

5. Shell Programming and Scripting

find command with -exec

Hi People, I have a directory full of compressed files (.Z extention) In many of these files there is a string pattern (3800078163033) I want to find all file names which contain this string in their text. Regards, Abhishek (2 Replies)
Discussion started by: max29583
2 Replies

6. Shell Programming and Scripting

find command with exec doesnt work

Hi There, I have a script which finds for log files and removes them if the file has changed in the last day. The script runs fine without errors. The log file is still there. So, I decided to print the find command and run the command outside the script. Getting "Incomplete statement" Can you... (6 Replies)
Discussion started by: funtochat2002
6 Replies

7. UNIX for Dummies Questions & Answers

Find command with prune and exec options

Hi, I'm using the following command to get a list of files on the system. find /releases -type f -exec ls -l > /home/sebarry/list.txt '{}' \; however, its searching a directory I don't want it to search so I know I have to use prune but I don't seem to be able to get prune and exec to work... (2 Replies)
Discussion started by: Sebarry
2 Replies

8. UNIX for Advanced & Expert Users

Find command with prune and exec

Hi, I'm using the following command to get a list of files on the system. find /releases -type f -exec ls -l > /home/sebarry/list.txt '{}' \; however, its searching a directory I don't want it to search so I know I have to use prune but I don't seem to be able to get prune and exec to work... (1 Reply)
Discussion started by: Sebarry
1 Replies

9. UNIX for Dummies Questions & Answers

find command exec error

Hi All, i am writing a shell script in korn shell which deletes all the files in a directory once in every 10DAYS. the directory has different format files. the script has something like this; cd /home/data/pavi echo "Please Enter the Number of Days to search for" read DAYS... (2 Replies)
Discussion started by: pavan_test
2 Replies
Login or Register to Ask a Question