Delete Photos Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete Photos Script
# 1  
Old 04-14-2011
Delete Photos Script

Good Morning, I need to move a social networking site to another server and I need to delete a bunch of photos. The old site used to allow, our members, to upload up to 100 photos. Now I want to limit it to 10. How can I delete the remaining photos? Here is what it looks like: 2474-14637.jpg 2474-14638.jpg 2474-14639.jpg ... 2474-14650.jpg
# 2  
Old 04-14-2011
How do we know which photos belongs to which user?
# 3  
Old 04-14-2011
2474 is the UserID UserID-PhotoID.jpg
# 4  
Old 04-14-2011
See if this works for you:

Code:
#!/usr/bin/ksh
typeset -i mCnt
ls -1 | sort > File_List
IFS="-"
while read mUser mSuffix
do
  if [[ "${mUser}" != "${mPUser}" ]]; then
    mCnt=1
  fi
  if [[ ${mCnt} -gt 10 ]]; then
    mFName=${mUser}'-'${mSuffix}
    echo "Now deleting <${mFName}>"
    rm -f ${mFName}
  fi
  mPUser=${mUser}
  mCnt=${mCnt}+1
done < File_List

# 5  
Old 04-14-2011
That worked perfectly! Thank you. I never throught of a do if loop.
# 6  
Old 04-14-2011
confirm the command is right
Code:
ls *.jpg |awk -F - '++a[$1]>2' |xargs echo

do the clean:
Code:
ls *.jpg |awk -F - '++a[$1]>10' |xargs rm

# 7  
Old 04-15-2011
Quote:
Originally Posted by rdcwayx
confirm the command is right
Code:
ls *.jpg |awk -F - '++a[$1]>2' |xargs echo

do the clean:
Code:
ls *.jpg |awk -F - '++a[$1]>10' |xargs rm

ls *.jpg |awk -F - '++a[$1]>10' |xargs rm -bash: /bin/ls: Argument list too long rm: missing operand
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

2. Shell Programming and Scripting

Script for creating symbolic links to my photos (*.JPG)

Hi, I have all my pictures as *.JPG and *.CR2 in the following folder structure: /media/a_2TB/pictures/year/year-month-day-hour/picture*.* But sometimes I added a subdirectory --> /media/a_2TB/pictures/year/year-month-day-hour/suba/picture*.*... (3 Replies)
Discussion started by: 8200
3 Replies

3. Red Hat

Need Script to ZIP/SAVE & then DELETE Log file & DELETE ZIPS older than 12 months

ENVIROMENT Linux: Fedora Core release 1 (Yarrow) iPlanet: iPlanet-WebServer-Enterprise/6.0SP1 Log Path: /usr/iplanet/servers/https-company/logs I have iPlanet log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I... (7 Replies)
Discussion started by: zachs
7 Replies

4. UNIX for Advanced & Expert Users

How can I convert photos extension?

Hi all I am working in UNIX O.S and I want to transfer any photos from UNIX O.S to Windows O.S . can any one tell me how can I do this ? (3 Replies)
Discussion started by: bintaleb
3 Replies
Login or Register to Ask a Question