Find or ls with pipe to the command file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find or ls with pipe to the command file
# 1  
Old 05-17-2016
Find or ls with pipe to the command file

Hello all!


I am trying to find the "Notes" backup from my iPhone in my folder ~/Library/Application\ Support/MobileSync/Backup/[UDID] which used to be in the sqlite file ca3bc056d4da0bbf88b5fb3be254f3b7147e639c. But since an update of the MacOS it is still there, but not updated anymore. (This is off topic, but probably somebody knows the right answer?)

My question: I would like to connect the commands find/ls -l with a pipe to file to get the following information of all files with size an type together (here an example for the old backup filename of Notes:

Code:
find . -type f -name "ca3*" -ls -print
12954433     2632 -rw-r--r--    1 mstep            staff             1347584  8 Mai 12:17 ./ca3bc056d4da0bbf88b5fb3be254f3b7147e639c

with

Code:
file ca3*
ca3bc056d4da0bbf88b5fb3be254f3b7147e639c: SQLite 3.x database

And this of course for all files of my iPhone-Backup. Fantastic would be, if a filter for a keyword like SQLite or XML would be possible, to get only these files. Is this possible?

I would be very grateful for any help


marek
# 2  
Old 05-17-2016
Not sure that I fully understand, but would
Code:
find . -type f -name "ca3*" -ls -print -exec file {} +

do what you need?
# 3  
Old 05-17-2016
Because type returns the file name, you certainly don't need -print or -ls.
Last but not least, you can pipe the result to egrep
Code:
find ... | egrep "SQLite|XML"

# 4  
Old 05-17-2016
If I understand what you're trying to do correctly (run the file utility with the pathnames of all regular files in the file hierarchy rooted in the current directory whose final component filenames contain the string SQLite or the string XML), this should do what you want:
Code:
find . -type f \( -name '*SQLite*' -o -name '*XML*' \) -exec file {} +

# 5  
Old 05-18-2016
Thank you RudiC and MadeInGermany for your answers!


Code:
find . -type f -name "ca3*" -ls -print -exec file {} +
12954433     2632 -rw-r--r--    1 mstep            staff             1347584  8 Mai 12:17 ./ca3bc056d4da0bbf88b5fb3be254f3b7147e639c
./ca3bc056d4da0bbf88b5fb3be254f3b7147e639c
./ca3bc056d4da0bbf88b5fb3be254f3b7147e639c: SQLite 3.x database

Which is a good start. The cleaning up of the result would be easy with grep. My Result should look something like follows:

Code:
12954433     2632 -rw-r--r--    1 mstep            staff             1347584  8 Mai 12:17 ./ca3bc056d4da0bbf88b5fb3be254f3b7147e639c SQLite 3.x database


That means one line with at least the size, filename and Type. (For all files)

Code:
find . -type f -print | egrep "SQLite|XML"

No results at all.

This command without -print gives on Mac and tcsh:

Code:
find . -type f -name "ca3*" -exec egrep "SQLite|XML" {} \;
Binary file ./ca3bc056d4da0bbf88b5fb3be254f3b7147e639c matches

Best greetings

marek

---------- Post updated 05-18-16 at 06:24 AM ---------- Previous update was 05-17-16 at 11:43 PM ----------

Quote:
Originally Posted by Don Cragun
If I understand what you're trying to do correctly (run the file utility with the pathnames of all regular files in the file hierarchy rooted in the current directory whose final component filenames contain the string SQLite or the string XML), this should do what you want:
Code:
find . -type f \( -name '*SQLite*' -o -name '*XML*' \) -exec file {} +

Thank you Don Cragun! No! this is not working. My posting was not clear! Mea culpa, sorry. In the backup folder of iPhone are only cryptic file names, and many of them like:

Code:
ls -lh | head
total 283624
    8 -rw-r--r--  1 mstep  staff   228B  8 Mai 12:17 000cae3437db21095a85771716e6874f92ce7593
    8 -rw-r--r--  1 mstep  staff   647B 18 Mai 06:00 0014310bf09a503606714f20a1c0602059a15e3d
   24 -rw-r--r--  1 mstep  staff   8,8K  8 Mai 12:17 0026af8b0c56f79d958d8d59085db5e37328b6d2
  144 -rw-r--r--  1 mstep  staff    71K  8 Mai 12:18 007f5d9bfb179f6e22c203eb1867379f6ebd29fe
   16 -rw-r--r--  1 mstep  staff   7,6K  8 Mai 12:17 007fdf26e30550ee76f4ce0e238c63e544ade889
    8 -rw-r--r--  1 mstep  staff   255B 12 Mai 22:13 012707a2ae34d77a28b16a9e443b780ea4e6b0aa
   56 -rw-r--r--  1 mstep  staff    28K  8 Mai 12:17 015ff977c6cb9eb67b715f319bd9f8cec4e263bd
   32 -rw-r--r--  1 mstep  staff    14K 16 Mai 22:43 01a14737bf725839e60201704f5e0447e23800a6
    8 -rw-r--r--  1 mstep  staff    42B  8 Mai 12:17 02080c751f0cd98738a2e9ccf7c133f0197865fa

The file type is only discovered with the command
Code:
file

like follows:

Code:
file * | head
000cae3437db21095a85771716e6874f92ce7593: Apple binary property list
0014310bf09a503606714f20a1c0602059a15e3d: Apple binary property list
0026af8b0c56f79d958d8d59085db5e37328b6d2: Adaptive Multi-Rate Codec (GSM telephony)
007f5d9bfb179f6e22c203eb1867379f6ebd29fe: JPEG image data, JFIF standard 1.01
007fdf26e30550ee76f4ce0e238c63e544ade889: Adaptive Multi-Rate Codec (GSM telephony)
012707a2ae34d77a28b16a9e443b780ea4e6b0aa: Apple binary property list
015ff977c6cb9eb67b715f319bd9f8cec4e263bd: JPEG image data
01a14737bf725839e60201704f5e0447e23800a6: XML  document text
02080c751f0cd98738a2e9ccf7c133f0197865fa: Apple binary property list
028402bab9ac2d1ff052d0aa85f71c8604975cf3: PNG image data, 431 x 768, 8-bit colormap, non-interlaced

my question is: how to connect the two commands to get at least following file informations:

size + type (SQLite or XML ...) and filename

To make a file filter to get only XML files, would be even better. I am unable to pass only the filenames through the pipe to
Code:
file

but keep all the informations of the preceding
Code:
ls

or
Code:
find

Is there a way to do it, or should I try with Perl?

Thanks again!

marek
# 6  
Old 05-18-2016
try this
Code:
find . -type f \( -name '*SQLite*' -o -name '*XML*' \) -exec ls -ltr {} + | awk '{filename=$NF;$NF="";printf $0" ";system ("/usr/bin/file "filename); }'

# 7  
Old 05-18-2016
@pravin27, didn't the previous post say that SQLite and XML should match on the file type=contents not name?

The following pipes the output of a simple find command into a while loop that does the postprocessing
Code:
find . -type f -print |
while read f
do
  ftype=`file "$f"`
  case $ftype in
  *SQLite*|*XML*)
    ls -lh "$f"
    echo "$ftype"
  ;;
  esac
done

The following variant tries to print both information in one line
Code:
find . -type f -print |
while read f
do
  ftype=`file "$f"`
  case $ftype in
  *SQLite*|*XML*)
    echo "$(ls -lh "$f") : ${ftype#*: }"
  ;;
  esac
done


Last edited by MadeInGermany; 05-18-2016 at 06:06 AM.. Reason: variant added
These 2 Users Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk command to split pipe delimited file

Hello, I need to split a pipe de-limited file based on the COLUMN 7 value . If the column value changes I need to split the file Source File Payment|ID|DATE|TIME|CONTROLNUMBER|NUMBER|NAME|INDICATOR 42156974|1137937|10/1/2018|104440|4232|2054391|CARE|1... (9 Replies)
Discussion started by: rosebud123
9 Replies

2. SuSE

Find command doesn't pipe the output as required.

Hi, I am using below code snippet to echo/display the files found (matching a pattern from searchstring.out file) and the corresponding owner. while read j do echo "Pattern to search is:- $j" find / -name "*$j*" |\ while read k do echo "File found is:- $k" owner=$(ls... (9 Replies)
Discussion started by: Vipin Batra
9 Replies

3. Shell Programming and Scripting

How to ignore Pipe in Pipe delimited file?

Hi guys, I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file for eg: file 1: xx|yy|"xyz|zzz"|zzz|12... using below awk command awk 'BEGIN {FS=OFS="|" } print $3 i would get xyz But i want as : xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

4. Shell Programming and Scripting

Find for line with not null values at nth place in pipe delimited file

Hi, I am trying to find the lines in a pipe delimited file where 11th column has not null values. Any help is appreciated. Need help asap please. thanks in advance. (3 Replies)
Discussion started by: manikms
3 Replies

5. Shell Programming and Scripting

wanted to find both link file and ordinary file using single find command

find . -type fl o/p is only the ordinary file. where in it wont give the link files. (2 Replies)
Discussion started by: nikhil jain
2 Replies

6. UNIX for Dummies Questions & Answers

find string and get the rest of the line in a pipe delimited file

Hi friends, I have a file where I should search for a string and get the rest of the line but without the delimiter using awk. for example I have the series of string in a file: input_string.txt bbb ccc aaa and the mapping file looks like this. mapping.txt aaa|12 bbb|23 ccc|43... (11 Replies)
Discussion started by: kokoro
11 Replies

7. UNIX for Advanced & Expert Users

Pipe text in to find command

I would like to know why this command does not work. I have a script which connects to and ftp site. After getting the remote files localy i need move each remote file to a archive folder on the FTP site *Please also note that some of the files have spaces in the file name. Im trying to... (3 Replies)
Discussion started by: juanjanse
3 Replies

8. Linux

Simplified find command to find multiple file types

Hi, I'm using the following command to find the multiple requierd file types and its working fine find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f Though... (2 Replies)
Discussion started by: vickramshetty
2 Replies

9. UNIX for Dummies Questions & Answers

how to find a file named vijay in a directory using find command

I need to find whether there is a file named vijay is there or not in folder named "opt" .I tried "ls *|grep vijay" but it showed permission problem. so i need to use find command (6 Replies)
Discussion started by: amirthraj_12
6 Replies

10. UNIX for Dummies Questions & Answers

Pipe out ftp command to a file

hi there all the unix-gurus, anyone can offer me some advise/help? i'm writing a ftp script and i need to spool out the output to a file but i'm facing some problems when i'm doing the following: ftp -n <mail server> ${log_dir}/test_put.log << END user <user_id> <password> verbose bin #... (2 Replies)
Discussion started by: lweegp
2 Replies
Login or Register to Ask a Question