Create a dummy file in all directories that include a .jpg


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create a dummy file in all directories that include a .jpg
# 8  
Old 04-03-2012
Quote:
Originally Posted by bartus11
What system are you using? Anyway, try this:
Code:
find /mnt/user/Pictures/ -type f -name "*.jpg" -exec dirname {} \; | sort | uniq | xargs -i touch "{}/.picture"

I'm still getting the same error. It seems to work, however it fails at a certain point. Is there any way to output what might be going on when it fails?
# 9  
Old 04-03-2012
Try:
Code:
find . -type f -name "*.jpg" -exec dirname {} \; | sort | uniq| sed "s/'/\\\'/g" | xargs -i touch {}/.picture

BTW, try fixing your directory names before processing, because Linux really doesn't like many of the special characters there (i.e. quotes, spaces etc).
This User Gave Thanks to bartus11 For This Post:
# 10  
Old 04-03-2012
linux is fine with them. xargs, on the other hand, is not.
# 11  
Old 04-03-2012
Quote:
Originally Posted by bartus11
Try:
Code:
find . -type f -name "*.jpg" -exec dirname {} \; | sort | uniq| sed "s/'/\\\'/g" | xargs -i touch {}/.picture

BTW, try fixing your directory names before processing, because Linux really doesn't like many of the special characters there (i.e. quotes, spaces etc).
This works perfectly. I know my directories are not named as well as they could be. I'll work on fixing that.


Quote:
Originally Posted by Corona688
I'd try looking for folders instead, so you don't have to extract what picture's in what folder. Seems easier to do vice-versa.

Code:
find /mnt/user/Pictures/ -type d | while read FOLDER
do
        if ls "$FOLDER" | grep "\.jpg$" > /dev/null
        then
                touch "$FOLDER"/.picture
        fi
done

I also got this script working. I had to change the grep "\.jpg$" command to simply grep .jpg, and it worked for me.


They both work very quickly. I love having 2 different good solutions to the same problem.

Thanks again for the extremely prompt help.
# 12  
Old 04-03-2012
You have a very odd version of grep then, which is possible on an embedded system I suppose! Smilie
This User Gave Thanks to Corona688 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

Create movie from jpg (or other picture format) file

hi linux expert is there any program for create movie file from pictures file (like jpg)? Many Thanks samad (1 Reply)
Discussion started by: abdossamad2003
1 Replies

2. Shell Programming and Scripting

Bash to create sub directories from specific file extension

In the bash below I am trying to create sub-directories inside a directory from files with specific .bam extensions. There may be more then one $RDIR ing the directory and the .bam file(s) are trimmed (removing the extension and IonCode_0000_) and the result is the folder name that is saved in... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

Create pdf of a jpg image in shell script

Dear Team, Can any one please let me know, if there is any way to create pdf of a Jpg image file in shell script. I work on Solaris, Korn Shell. Currently we are using sunpcl2pdf.exe to create PDF from PCL(Printer Control Language) files. But we are searching for some different way to... (2 Replies)
Discussion started by: Uttam Maji
2 Replies

4. Shell Programming and Scripting

Help with create multiple directories under diff file systems

Hi, Need help ...I want to create multiple directories in different /file systems using for loop..eg.../ORCL_data01/oradata/orcl/ctl. ../ORCL_data01/oradata/orcl/data. ../ORCL_data01/oradata/orcl/redo. Script :- ========= for dir in `ls -d... (8 Replies)
Discussion started by: Linux6.5
8 Replies

5. UNIX for Dummies Questions & Answers

Converting pdf to jpg in multiple directories?

Hi! On my Ubuntu I have thousands of files in a couple hundred directories. I'm trying to convert the pdf's to jpg's. I used this command in terminal: for fname in *.pdf; do convert $fname ${fname%.pdf}.jpg; doneIt works great but the problem is I have to run this in terminal for each... (2 Replies)
Discussion started by: martinsmith
2 Replies

6. Linux

Create a dummy file even if the path is not exist

hi, i want to create a dummy file even if the path to that file is not exist as follows. suppose, in my working directory 2 files are there. and i create one more file which is exist as follows # pwd /home/satya # ls file1.txt file2.txt # echo dummy > /home/satya/file3.txt # ls... (3 Replies)
Discussion started by: snreddy_gopu
3 Replies

7. Shell Programming and Scripting

How to create tgz file for all the directories in one time?

Hi, On server there is an one folder . which contains sub folder Eg - TEST folder contains test1, test2, execr ,tt (folder). also includes some text file like abc.txt psp.txt gg.log. here iwant to create tgz file for all the folders and file in one time. I know the command... (1 Reply)
Discussion started by: aish11
1 Replies

8. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

9. UNIX for Dummies Questions & Answers

Create directories from a sql file?

Hi, I have a sql file which has CREATE and INSERT commands in it. Basically, inside this file, a table will be created and the data will be inserted into the table. I was wondering if there is a way for me to create directories from this file? Thanks in advance (4 Replies)
Discussion started by: tezarin
4 Replies

10. SCO

Create dummy printer

On SCO Openserver we create a so called dummy printer that directs to /dev/null (we use this in our software to purge some stuff). Now I have SCO UnixWare 7.1.4, but I cannot create a dummy printer. I create the printer exactly as in Openserver by the Printer Manager, - Enter spoolname -... (1 Reply)
Discussion started by: p.vvugt
1 Replies
Login or Register to Ask a Question