Not sure how to write a script to delete certain files?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Not sure how to write a script to delete certain files?
# 1  
Old 01-04-2010
Not sure how to write a script to delete certain files?

I'm a total *nix newb so I really could use some help! Smilie

I plan on running a cron job on my server that deletes some files and then backs up and emails the website for archival purposes.

Before I get in too deep I'd like to remove some unnecessary files that phpThumb creates. I'm not sure why but when phpThumb creates thumbnails and caches them it also creates an extenion-less copy of the source file and names it phpThumb* (ie. phpThumbdcvgh, phpThumbsdgh, phpThumbsgd). I have no need for them because within the cache directory there is another directory called source that caches the source files (with a useful .jpeg extension no less!).

I've never scripted anything for a *nix system before - the closest I've come is to installing Ubuntu once. Smilie

Looking around the net this is what I've got for a script so far. Please let me know what it would do. Most importantly if it would actually delete the many phpThumb files. I'm not sure if *nix systems use an asterisk the way I believe it would.

Code:
find /public_html/cache -exec rm -f {phpThumb*} \;

Thanks for any help!

BTW - anyone have any links to Linux for beginners? It's something I'd really like to learn but it's so foreign to me coming from Window's simplicity. What! I can't double-click to install a program?!
# 2  
Old 01-04-2010
Code:
find /public_html/cache -name 'phpThumb*'  -exec rm -f {} \;

will do what you want. This code assumes there are no directories under ./cache with
phpThumb* filenames
# 3  
Old 01-04-2010
First things first. What Linux are we talking about? What kind of access do you have? Do you have shell access? If so, with what (telnet/ssh)? What's the absolute path (not the one relative to the document root) on the server to those cached files?

Quote:
Originally Posted by Sinistral
BTW - anyone have any links to Linux for beginners? It's something I'd really like to learn but it's so foreign to me coming from Window's simplicity. What! I can't double-click to install a program?!
Comparing Windows to Linux is like comparing a car to a motorbike. Both use roads, but that's where the similarity ends. Just because you're used to something doesn't mean it's easy.
And why should anyone have to hunt endlessly for programs online, and then be asked the same questions again and again for different programs, when there's a nifty feature called Software Repository?
# 4  
Old 01-04-2010
Quote:
Originally Posted by jim mcnamara
Code:
find /public_html/cache -name 'phpThumb*'  -exec rm -f {} \;

will do what you want. This code assumes there are no directories under ./cache with
phpThumb* filenames
Thanks, Jim!

Quote:
Originally Posted by pludi
First things first. What Linux are we talking about? What kind of access do you have? Do you have shell access? If so, with what (telnet/ssh)? What's the absolute path (not the one relative to the document root) on the server to those cached files?
I'm not exactly sure what Linux variant the server is on. I've been able to find out it's "Linux" with kernel 2.6.18-164.2.1.el 5.028stab066.7 through cPanel. I have SSH shell access (I think since cPanel has a tab for it) but I've only used FTP so far. Would the absolute path be something like /home/stickyup/? Stickyup being the account name my host gave me.

Last edited by Sinistral; 01-04-2010 at 08:56 PM.. Reason: simple typo
# 5  
Old 01-05-2010
Quote:
Originally Posted by Sinistral
[...]2.6.18-164.2.1.el 5.028stab066.7[...]
To those who know it that tells us that it's Red Hat Enterprise Linux 5. Someone more experienced with it than me might even find out the exact patch level, but that's irrelevant for your question.
Quote:
Originally Posted by Sinistral
I have SSH shell access (I think since cPanel has a tab for it) but I've only used FTP so far. Would the absolute path be something like /home/stickyup/?[...]
Did jim's command work? If so, you've already got the absolute path. Otherwise, find out if the SSH access works, and try this:
Code:
cd ~/public_html/
pwd

The output from pwd should be the absolute path to the public_html directory.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. How to Post in the The UNIX and Linux Forums

Help me, write a bash script to delete parent entry with all their child entry in LDAP UNIX server

Hi All, Please help me and guide me to write a bash/shell script on Linux box to delete parent entry with all their child entries. example: Parent is : ---------- dn: email=yogesh.kumar@wipro.com, o=wipro, o=in child is: ---------- dn: cn: yogesh kumar, email=yogesh.kumar@wipro.com,... (1 Reply)
Discussion started by: Chand
1 Replies

2. 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

3. Shell Programming and Scripting

Script to open files and write into new one

Hello! I am a real beginner in scripting, so I am struggling with a really easy task! I want to write a script to concatenate several text files onto each other and generate a new file. I wanted the first argument to be the name of the new file, so: ./my_script.sh new_file file1.txt... (5 Replies)
Discussion started by: malajedala
5 Replies

4. Shell Programming and Scripting

Is rsync --delete on some files without write permission possible?

Hello all, I have a problem with rsync command. From a backup server, I use a command like the one below: rsync -av --delete user@host:/home/user/ /home/backup_user/daily_rotating_backup/ In some folders of the user there are some files on which he has removed his write permission on... (3 Replies)
Discussion started by: freddie50
3 Replies

5. Shell Programming and Scripting

Need help creating a script to FTP files to a server and then delete the files that were transfered.

I am trying to FTP files to a Windows server through my Linux machine. I have setup the file transfer with no problems but am having problem deleting those files from the Linux box. My current non-working solution is below. Any ideas, anyone?? :wall: Please be gentle, I'm fairly new to this... (4 Replies)
Discussion started by: jmalfhs
4 Replies

6. Shell Programming and Scripting

Write a shell script to find ctrl M and delete them

Hi All, I would like to write a shell script to find Control M charactes and after getting the result i want to delete it. But in the script the following command couldn't work. find . -exec grep -l '^M' {} \; > test.txt ^M is ctrl V and M thanks in advance for any help. (4 Replies)
Discussion started by: jatanig
4 Replies

7. Shell Programming and Scripting

write script for more then 600 files

Hi, i have 600 or more file on my server and from this 600 files i want to make one file. i have written this script SPATH=/etlstg/DAT TPATH=/etlstg/DAT/DAT_PROCESSED FILE_DATE=`TZ=CST+24 date +20%y%m%d` a1=0 while do a2=0 while do a3=0 while ... (1 Reply)
Discussion started by: prasson_ibm
1 Replies

8. Shell Programming and Scripting

Write a new file from 2 files as input to the script

Hi- I am hoping someone can give me some pointers to get me started. I have a file which contains some dn's .e.g file 1 cn=bob,cn=user,dc=com cn=kev,cn=user,dc=com cn=john,cn=user,dc=com I have a second file e.g. file.template which looks something like :- dn: <dn> objectclass:... (5 Replies)
Discussion started by: sniper57
5 Replies

9. Shell Programming and Scripting

write a script to compare two files

Hi all, i am new to unix,i have never worked on scripting and all,i am learning now and i have to write a script to compare two files. The requirement is like : in the first file i am searching for a word and after i get that word i have to select everything from the rest of the file and redirect... (34 Replies)
Discussion started by: usha rao
34 Replies

10. Shell Programming and Scripting

Script with read/write Files

Hello, I am a Newbie in ksh Unix Script. So I must write a ksh/sh script who read character at a position in a File. So also it must read all the lines who belongs at these characters , then write these lines in a another File. Can you help me , or give little councils to advance with my... (5 Replies)
Discussion started by: steiner
5 Replies
Login or Register to Ask a Question