Deleting files using UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting files using UNIX
# 1  
Old 09-19-2014
Deleting files using UNIX

Hi All ,

I am using the below if condition to delete files .
Code:
if [ "$LINKTRIGGER" != "" ]
then
if [ ! -f ${LANDINGDIR}/${LINKTRIGGER}.* ]; then
log_err "Trigger File ${LINKTRIGGER} does not exist!"
fi
log_msg "Deleting the Linktrigger"
rm -v ${LANDINGDIR}/${LINKTRIGGER}.*
else
if [ ! -f ${LANDINGDIR}/${TRGFILE}.* ]; then
log_err "Trigger File ${TRGFILE} does not exist!"
echo nofile
fi
log_msg "Deleting the individual trigger"
rm -v ${LANDINGDIR}/${TRGFILE}.*
fi

This is working fine however this piece of code is not working
Code:
 
if [ ! -f ${LANDINGDIR}/${LINKTRIGGER}.* ]; then
log_err "Trigger File ${LINKTRIGGER} does not exist!"
fi

Please let me know whats wrong

Thanks
dj

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 09-19-2014 at 08:20 AM..
# 2  
Old 09-19-2014
Hello dj,

It was a little mess with place of else. Following may help.

Code:
if [ "$LINKTRIGGER" != "" ]
then
 if [ ! -f ${LANDINGDIR}/${LINKTRIGGER}.* ]; then
  log_err "Trigger File ${LINKTRIGGER} does not exist!"
 else
  log_msg "Deleting the Linktrigger"
  rm -v ${LANDINGDIR}/${LINKTRIGGER}.*
 fi
 if [ ! -f ${LANDINGDIR}/${TRGFILE}.* ]; then
  log_err "Trigger File ${TRGFILE} does not exist!"
  echo nofile
 else
  log_msg "Deleting the individual trigger"
  rm -v ${LANDINGDIR}/${TRGFILE}.*
 fi 
fi

Thanks,
R. Singh

Last edited by RavinderSingh13; 09-19-2014 at 08:27 AM..
# 3  
Old 09-19-2014
Search for a file

Hi all ,

Can u please let me know how do i search for file name with any extension in a particular folder

I am using the below code
Code:
if [ -f ${LANDINGDIR}/${TRGFILE} .* ]

but this is not working

Last edited by Franklin52; 09-19-2014 at 03:08 PM.. Reason: Please use code tags
# 4  
Old 09-19-2014
Posted by Hypesslearner:
Quote:
Hi all ,
Can u please let me know how do i search for file name with any extension in a particular folder
I am using the below code

if [ -f ${LANDINGDIR}/${TRGFILE} .* ]

but this is not working
Hello,

Following may help.

Code:
LANDINGDIR="/tmp"
TRGFILE="TEST.MATCHTEXT"
if [[ -f "$LANDINGDIR""/""$TRGFILE" ]]
then
 echo "present."
else
 echo "NOT present."
fi

This is an example for searching the file in any directory.

Thanks,
R. Singh
# 5  
Old 09-19-2014
Thankyou . But i need to find Test.txt ot Test.trigger or any file with text.* . How do i do this ?
# 6  
Old 09-19-2014
Hello,

Could you please try following command and let me kno if this helps.
This is just an example.

Code:
find /tmp -name "test*"
Syntax: find PATH -name "name"

Output will be as follows.
Code:
/tmp/test4
/tmp/test3
/tmp/test2
/tmp/test1
/tmp/test1213
/tmp/test1212
/tmp/test1211
/tmp/test122.ksh

Thanks,
R. Singh
# 7  
Old 09-19-2014
Yes it is working but how do i use this in if condition as i need to use this in IF condition . My requirement is to check for test and delete all files like test1 or test2
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting files

Hi I have an AIX server. I'm planning to use the below script to remove 60 days older files. find /path/ -mtime +60 -exec rm -f {} \; I just want to make sure it will only remove the files. I don't want the directories to be removed. If in case it will delete the directories... (2 Replies)
Discussion started by: newtoaixos
2 Replies

2. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

3. UNIX for Dummies Questions & Answers

Deleting a pattern in UNIX without deleting the entire line

Hi I have a file: r58778.3|SOURCES={KEY=f665931a...,fw,221-705}|ERRORS={16_1:T,30_1:T,56_1:C,57_1:T,59_1:A,101_1:A,115:-,158_1:C,186_1:A,204:-,271_1:T,305:-,350_1:C,368_1:G,442_1:C,472_1:G,477_1:A}|SOURCE_1="Contig_1092402550638"(f665931a359e36cea0976db191ff60ff09cc816e) I want to retain... (15 Replies)
Discussion started by: Alyaa
15 Replies

4. UNIX for Dummies Questions & Answers

problem deleting multiple files using rm in UNIX

I'm baffled..... the system I work on creates files every Mon-Friday I'm trying to delete all files older than 30 days old from a Unix prompt, the command I'm using is: find /directory/ -mtime +30 -exec rm {} \; however it returns /directory/filename: 644 mode ? (y/n) for every file! ... (1 Reply)
Discussion started by: bquattrone
1 Replies

5. Shell Programming and Scripting

AIX system.... deleting files in remote directory after retrieving files

Hi Friends, I am new to this , I am working on AIX system and my scenario is to retrive the files from remote system and remove the files from the remote system after retreving files. I can able to retrieve the files but Can't remove files in remote system. Please check my code and help me out... (3 Replies)
Discussion started by: vinayparakala
3 Replies

6. Shell Programming and Scripting

Need help comparing two files and deleting some things in those files!

So I have two files: File1 pictures.txt 1.1 1.3 dance.txt 1.2 1.4 treehouse.txt 1.3 1.5 File2 pictures.txt 1.5 ref2313 1.4 ref2345 1.3 ref5432 1.2 ref4244 dance.txt 1.6 ref2342 1.5 ref2352 1.4 ref0695 1.3 ref5738 1.2 ref4948 1.1 treehouse.txt 1.6 ref8573 1.5 ref3284 1.4 ref5838... (24 Replies)
Discussion started by: linuxkid
24 Replies

7. Solaris

Deleting files

OK, Easy question probably, I have a directory that is full of like 1000 files. I want to get rid of files more than 5 days old. Is there an easy way to do this? there are like 800 files that fit into this category so doing it manually would be a pain. Any help is appreciated! (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

8. Shell Programming and Scripting

Deleting old files

Hi, I have a directory which contains files.This Directory keeps getting in new files from time to time.I want to maintain only 15 files in that directory at any time and the old files should be deleted. Eg: Directory 'c' @'a/b/c contains: 1_a 2_a 3_a... I want to delete all the old... (2 Replies)
Discussion started by: shiroh_1982
2 Replies

9. Shell Programming and Scripting

Deleting the files

Hi, I've to delete certain files older than X days from a Maintenance server. I'm doing this using find . -name lds\* -mtime $X \ -exec ls -l {} \; find . -name lds\* -mtime $X \ -exec rm -fR {} \; As well as I've to delete the files from another FTP server which are again older than X... (0 Replies)
Discussion started by: livetaurean19
0 Replies

10. UNIX for Dummies Questions & Answers

Deleting Unix files from DOS

I have a DOS script on Windows NT that uses FTP to connect to a Unix server and to copy files to the WinNT. So far, so good. Now I want to delete those files on Unix afterwards but I'm unable to delete all files in the directory. How can I delete all the files on Unix from where i did ftp all... (3 Replies)
Discussion started by: vidireporting
3 Replies
Login or Register to Ask a Question