Re: Weird behavior with find command when tarring files

From: Rich J <rjoralist3_at_society.servebeer.com>
Date: Tue, 18 Dec 2018 08:01:23 -0600
Message-ID: <449ceb2cdc8d713f6f2129abb170a991_at_society.servebeer.com>



On 2018/12/17 16:44, Dave Herring wrote:

> Thanks for the tips with "xargs", Jared, although I don't quite understand what "xargs" is doing when "-0E" are involved. The following was done on RHEL6.6:
>
> Create 5 randomly named files with "x_" prefix.
>
> % for ((i=1; i<=10; i++)); do touch x_`date +%N`.txt; done
>
> % find . -maxdepth 1 -type f -print0
>
> ./x_287598645.txt./x_295644322.txt./x_303214626.txt./x_310464579.txt./x_317687226.txt./x_325071789.txt./x_332189678.txt./x_339226164.txt./x_346212508.txt./x_353403282.txt
>
> Show that a "find" on "y_" names piped to "xargs -0 ls" still shows all files. This is because "ls" doesn't require [FILE] to be listed.
>
> % find . -maxdepth 1 -type f -name 'y_*' -print0 | xargs -0 ls
>
> x_287598645.txt x_303214626.txt x_317687226.txt x_332189678.txt x_346212508.txt
>
> x_295644322.txt x_310464579.txt x_325071789.txt x_339226164.txt x_353403282.txt

I've used the "-i" parameter (along with the required curly braces for substitution) to xargs to prevent execution when there are no matching files. This is on OL7, but runs the same on my OL6 box:

:~:> cd $ORACLE_HOME/rdbms/admin
:/OPT/ORACLE/12.2.0/RDBMS/ADMIN:> find . -type f -name "xm*"|xargs ls -l

-rw-r----- 1 oracle oinstall  484 Jan  3  2002 ./xmlja.sql
-rw-r----- 1 oracle oinstall 3711 Sep 30  2003 ./xmlu817.sql
-rw-r----- 1 oracle oinstall 4852 Sep 30  2003 ./xmlu901.sql 

:/OPT/ORACLE/12.2.0/RDBMS/ADMIN:> find . -type f -name "XM*"|xargs ls -l total 58168

drwxr-xr-x 6 oracle oinstall    4096 Oct 31  2017 cdb_cloud
-rw-r--r-- 1 oracle oinstall   41192 Mar 29  2016 a1102000.sql
-rw-r--r-- 1 oracle oinstall   78185 Jul  8  2016 a1201000.sql
-rw-r--r-- 1 oracle oinstall    3168 Oct 15  2003 addmrpt.sql
-rw-r--r-- 1 oracle oinstall    4748 Jan  5  2005 addmrpti.sql
-rw-r--r-- 1 oracle oinstall    6408 Jul 22  2016 addmtmig.sql
-rw-r--r-- 1 oracle oinstall    3011 Jul 21  2009 agtept.lst
-rw-r--r-- 1 oracle oinstall    1993 Dec 17  2015 apex_to_common.sql
-rw-r--r-- 1 oracle oinstall    7865 Aug 10  2016 approot_to_pdb.sql
_(and all of the rest of the files in the dir, because there are no matching files for the find command, so "ls -l" runs as-is)_

:/OPT/ORACLE/12.2.0/RDBMS/ADMIN:> find . -type f -name "XM*"|xargs -i ls -l {}
_(no files listed with the "-i" when there are no matching files for find)_

:/OPT/ORACLE/12.2.0/RDBMS/ADMIN:> find . -type f -name "xm*"|xargs -i ls

-l {}
-rw-r----- 1 oracle oinstall 4852 Sep 30  2003 ./xmlu901.sql
-rw-r----- 1 oracle oinstall 3711 Sep 30  2003 ./xmlu817.sql
-rw-r----- 1 oracle oinstall 484 Jan  3  2002 ./xmlja.sql 

There are caveats, but I've used the multi-platform "-i" switch for years to do things like rename files (before the Linux-only "rename" command), because the "{}" substitution can be used multiple times in one xargs.

HTH! GL!
Rich

--
http://www.freelists.org/webpage/oracle-l
Received on Tue Dec 18 2018 - 15:01:23 CET

Original text of this message