How to find string of file name of images?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to find string of file name of images?
# 1  
Old 08-19-2014
How to find string of file name of images?

Hi & good day,

How to use find correctly ?

I have several folders, _img1, _img2 etc.

Then I want to use the find command to find part of an image name, such as:

the string ”modern”

which is (at least) in:

”_img2/modern_world2PS220.jpg”

Also I want to know _in which folder_ it was found.

This does not work:
Code:
find . -type f -print modern *

Any ideas please?

with best regards,
Omar K N
Stockholm, Sweden
# 2  
Old 08-19-2014
Code:
find . -type f -name "*modern*"

This User Gave Thanks to pilnet101 For This Post:
# 3  
Old 08-19-2014
Hello OmarKN,
If you are looking for strings within a file, then have a look at the grep command. It allows you to search within files for expressions or strings. It is often combined with find so that one finds a list of files matching on name, location, age etc. and then it repeatedly calls grep to search within those files.


I hope that this helps, but feel free to ask for more information if I'm not clear or I have gone off on the wrong direction.



Robin
Lancashire,
UK
This User Gave Thanks to rbatte1 For This Post:
# 4  
Old 08-19-2014
Quote:
Originally Posted by pilnet101
Code:
find . -type f -name "*modern*"

This works fine!

How to restrict the search to only jpg and png - files?

Alternatively,

How to restrict the search to only certain folders? (such as _img1/ _img2/ )?

with best regards,
Omar K N
Stockholm, Sweden

---------- Post updated at 06:58 PM ---------- Previous update was at 06:56 PM ----------

Quote:
Originally Posted by rbatte1
It is often combined with find so that one finds a list of files matching on name, location, age etc. and then it repeatedly calls grep to search within those files.
Hi Robin,

This was interesting.

Do you think you have an example as to first use find (a string in a file name) and then also grep (inside the file)?

That would be great!

with best regards,
Omar K N
Stockholm, Sweden
# 5  
Old 08-19-2014
Hello Omkar,

Here is the example as per your request, I am just using mtime which will look for files which are older than a day and then I am looking for a text in those files just for example.
Kindly let me know if this helps.


let us say we have following files in our test directory.

Code:
-rw-rw-r--. 1 singh singh   0 Aug 15 13:25 new file
-rw-rw-r--. 1 singh singh  74 Aug 18 10:44 check_data
-rw-rw-r--. 1 singh singh 136 Aug 19 09:10 get_data1211
-rw-rw-r--. 1 singh singh  81 Aug 19 09:26 get_data1211.ksh

Code:
find . -mtime -1 -type f -exec grep -i "chr1" {} \;

Output will be as follows.

Code:
chr1    3217769    3217789    2952725-5    255    +
chr1    3260455    3260475    2434087-6    255    -

Thanks,
R. Singh
# 6  
Old 08-19-2014
You can restrict jpg and png files like this

Code:
find  -type f -name "*modern*.jpg" -o -name "*modern*.png"

# 7  
Old 08-19-2014
Quote:
Originally Posted by OmarKN
How to restrict the search to only jpg and png - files?
How to restrict the search to only certain folders? (such as _img1/ _img2/ )?
1. Try adding -regex '.*\.[jp][pn]g' to pilnet101's command

2. find _img1/ _img2/ ...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script to read string from file#1 and find/replace in file#2

Hello Forum. I have a file called abc.sed with the following commands; s/1/one/g s/2/two/g ... I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies

2. Shell Programming and Scripting

Find string in file and find the all records by string

Hello I would like to get know how to do this: I got a big file (about 1GB) and I need to find a string (for instance by grep ) and then find all records in this file based on a string. Thanks for advice. Martin (12 Replies)
Discussion started by: mape
12 Replies

3. Shell Programming and Scripting

Bash Script to find/sort/move images/duplicate images from USB drive

Ultimately, I'm looking to create a script that allows me to plug in a usb drive with lots of jpegs on it & copy them over to a folder on my hard drive. So in the process of copying I am looking to hash check them, record dupes to a file, copy only 1 of the identical files (if it doesn't exsist... (1 Reply)
Discussion started by: JonaQuinn
1 Replies

4. Shell Programming and Scripting

How to find & auto resize images?

I need a command or mini scripts that can find certain type of images file recursively from the current dir with files of minimum 736 width and resize them by "736 max width, relative height" and replace the source files. I currently have GD installed but can also install Imagemagick if needed, I'm... (5 Replies)
Discussion started by: Frozen77
5 Replies

5. Shell Programming and Scripting

Find string in file and append new string after

Hi All, I'm trying to insert a string into a file at a specific location. I'd like to add a string after the parent::__construct(); in my file. <?php if (! defined('BASEPATH')) exit('No direct script access allowed'); class MY_Controller extends CI_Controller { function... (6 Replies)
Discussion started by: jjkilpatrick
6 Replies

6. Shell Programming and Scripting

find string and replace with string in other file

Dear all, I need your help, I have file like this: file1:23456 01910964830098775635 34567 01942809546554654323 67589 26546854368698023653 09778 58716868568576876878 08675 86178546154065406546 08573 54165843543054354305 . .file2: 23456 25 34567 26 67589 27 (2 Replies)
Discussion started by: attila
2 Replies

7. Shell Programming and Scripting

Find all images, append unique prefix to name and move to different directory

Hi, I have a directory with Multiple subdirectories and 1000s of pictures (jpg) in each directory. The problem is that each directory has a 001.jpg in them. I want to append a unique name (the directory_name)would be fine. and then move them to one main backup directory once they have been... (1 Reply)
Discussion started by: kmaq7621
1 Replies

8. Shell Programming and Scripting

Find multiple string in one file using find command

Hi, I want find multiple string in one file using find coomand. And keeping it in one variable.grep is not working. (5 Replies)
Discussion started by: vivek1489
5 Replies

9. Linux

Find String in FileName and move the String to new File if not found

Hi all, I have a question.. Here is my requirement..I have 500 files in a path say /a/b/c I have some numbers in a file which are comma seperated...and I wanted to check if the numbers are present in the FileName in the path /a/b/c..if the number is there in the file that is fine..but if... (1 Reply)
Discussion started by: us_pokiri
1 Replies

10. Shell Programming and Scripting

How to find a certain string in a file and replace it with a value from another file using sed/awk?

Hi Everyone, I am new to this forum and new to sed/awk programming too !! I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column. file 1: (assert (=... (21 Replies)
Discussion started by: paramad
21 Replies
Login or Register to Ask a Question