Linux - incorrect result with find and xargs command

Asked

Viewed 64 times

0

I’m trying to list the files of the last day, but through the command below it lists the files of the last day and then starts to list all the files:

[oracle@orcl11 adump]$ find . -ctime -1 | xargs ls -l
-rw-r--r--. 1 oracle oinstall   530 Jun  5 20:12 ./adx_orcl.txt
-rw-r-----. 1 oracle oinstall   743 Jun  5 18:24 ./orcl_ora_1987_1.aud
-rw-r-----. 1 oracle oinstall   750 Jun  5 18:25 ./orcl_ora_1987_2.aud
-rw-r-----. 1 oracle oinstall  1451 Jun  5 18:25 ./orcl_ora_2081_2.aud
-rw-r-----. 1 oracle oinstall  1957 Jun  5 18:41 ./orcl_ora_2096_2.aud
-rw-r-----. 1 oracle oinstall  3586 Jun  5 19:41 ./orcl_ora_2255_2.aud
-rw-r-----. 1 oracle oinstall  1442 Jun  5 18:59 ./orcl_ora_2311_1.aud
-rw-r-----. 1 oracle oinstall   758 Jun  5 19:01 ./orcl_ora_2361_1.aud
-rw-r-----. 1 oracle oinstall 21739 Jun  5 19:36 ./orcl_ora_2369_1.aud
-rw-r-----. 1 oracle oinstall  1403 Jun  5 19:08 ./orcl_ora_2388_1.aud
-rw-r-----. 1 oracle oinstall  1172 Jun  5 19:08 ./orcl_ora_2391_1.aud
-rw-r-----. 1 oracle oinstall   743 Jun  5 19:41 ./orcl_ora_2513_1.aud
-rw-r-----. 1 oracle oinstall   750 Jun  5 19:41 ./orcl_ora_2513_2.aud
-rw-r--r--. 1 oracle oinstall  2024 Jun  5 19:41 ./orcl_ora_2606_1.xml
-rw-r--r--. 1 oracle oinstall  2055 Jun  5 19:43 ./orcl_ora_2622_1.xml
-rw-r--r--. 1 oracle oinstall  1259 Jun  5 19:52 ./orcl_ora_2729_1.xml
-rw-r--r--. 1 oracle oinstall  4688 Jun  5 19:46 ./orcl_ora_2757_1.xml
-rw-r--r--. 1 oracle oinstall  1689 Jun  5 19:52 ./orcl_ora_3222_1.xml
-rw-r--r--. 1 oracle oinstall  1259 Jun  5 19:54 ./orcl_ora_3237_1.xml
-rw-r--r--. 1 oracle oinstall   752 Jun  5 19:53 ./orcl_ora_3244_1.xml
-rw-r--r--. 1 oracle oinstall 38643 Jun  5 20:48 ./orcl_ora_3246_1.xml
-rw-r--r--. 1 oracle oinstall  2160 Jun  5 20:21 ./orcl_ora_3334_1.xml
-rw-r--r--. 1 oracle oinstall  4368 Jun  5 20:20 ./orcl_ora_3407_1.xml

.:
total 11268
-rw-r--r--. 1 oracle oinstall    530 Jun  5 20:12 adx_orcl.txt
-rw-r-----. 1 oracle oinstall   3597 May 28 08:49 orcl_dm00_2169_1.aud
-rw-r-----. 1 oracle oinstall   3597 May 27 19:02 orcl_dm00_2206_1.aud
-rw-r-----. 1 oracle oinstall   3597 May 27 19:03 orcl_dm00_2280_1.aud
-rw-r-----. 1 oracle oinstall   3597 May 27 19:04 orcl_dm00_2286_1.aud
-rw-r-----. 1 oracle oinstall   3597 May 27 19:05 orcl_dm00_2307_1.aud
-rw-r-----. 1 oracle oinstall   3597 May 28 08:55 orcl_dm00_2343_1.aud
-rw-r-----. 1 oracle oinstall   3597 May 28 08:56 orcl_dm00_2350_1.aud
-rw-r-----. 1 oracle oinstall   3597 May 28 08:58 orcl_dm00_2402_1.aud
-rw-r-----. 1 oracle oinstall   3597 May 27 19:27 orcl_dm00_2419_1.aud
...

Why does this happen? Note that if I use only the command find it returns correctly:

[oracle@orcl11 adump]$ find . -ctime -1
.
./orcl_ora_2513_2.aud
./orcl_ora_1987_2.aud
./orcl_ora_2361_1.aud
./orcl_ora_2096_2.aud
./orcl_ora_2757_1.xml
./orcl_ora_3222_1.xml
./orcl_ora_2388_1.aud
./orcl_ora_2513_1.aud
./orcl_ora_3246_1.xml
./orcl_ora_2622_1.xml
./orcl_ora_3407_1.xml
./orcl_ora_2369_1.aud
./orcl_ora_2391_1.aud
./orcl_ora_2311_1.aud
./orcl_ora_2606_1.xml
./orcl_ora_3334_1.xml
./orcl_ora_1987_1.aud
./orcl_ora_2081_2.aud
./orcl_ora_2255_2.aud
./orcl_ora_3237_1.xml
./adx_orcl.txt
./orcl_ora_2729_1.xml
./orcl_ora_3244_1.xml
  • 1

    Utilize find . -ctime -1 -print | less

1 answer

3


Note that the first result of find is a point:

[oracle@orcl11 adump]$ find . -ctime -1
.  <--- aqui
./orcl_ora_2513_2.aud
...

The point corresponds to the current directory. And the xargs will pass the point to the ls (along with the names of the found files).

And when the ls receives a list of files and a directory as parameters, it lists the files and then also lists the contents of the directory.

This is what is happening: first are listed the files that the find found, and then listing with all the files is the result of passing the . (the current directory) for the ls.

For this not to happen, you can use the option -type and make the find just find the files (ignoring directories):

find . -ctime -1 -type f | xargs ls -l

In the case, -type f makes it only listed files, so the . is not listed. See all options on documentation.

  • 1

    Very well noted, thank you very much!

  • cool; or find . -ctime -1 | xargs ls -ld

Browser other questions tagged

You are not signed in. Login or sign up in order to post.