Bash to delete file in directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash to delete file in directory
# 1  
Old 04-16-2015
Bash to delete file in directory

Will the below bash delete all the "snps.ivg" in the given directory? Thank you Smilie


Code:
 find N:\all_array\Samples -maxdepth 1 -type f -name "snps.ivg" -delete

# 2  
Old 04-16-2015
I'd start here
This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 04-16-2015
Any reason why you don't want to use rm snps.ivg?
This User Gave Thanks to balajesuri For This Post:
# 4  
Old 04-16-2015
Try it without the -delete and see if it prints the names. If it prints the right names, you're on the right track.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 04-16-2015
So to use rm snps.ivg to delete all 1000 entries would I use

Code:
cd "directory"

while true
do rm snps.ivg
done

I am cautious before using rm . Thank you Smilie.
# 6  
Old 04-16-2015
find will not delete files if you don't put -delete into it. If you run it without the -delete it will only print names.
# 7  
Old 04-16-2015
How is it possible to have plenty of files with the same name in one directory?
Do you mean instead «All files ending with "snps.ivg"» or «All "snps.ivg" in all sub-directories»?
Thanks for clarifying, or sorry if I missed something Smilie.

Last edited by tukuyomi; 04-16-2015 at 03:54 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching File in Directory and all Subdirectory and Delete

Hi All, My directory structure is like Directory1 SubDirectory1 SubDirectory2 SubDirectory3 I have main directories and subdirectories underneath. I want to write a shell script where I will be passing file name as a parameter, Now I want to find all the files in Directory1... (19 Replies)
Discussion started by: John William
19 Replies

2. Shell Programming and Scripting

Delete all files from the directory except the ones in the log file

I have a log file with contents like below. Repository: https://someserver:9443/ Workspace: (1000) "test_scripts_ws" Component: (1001) "some_Automated_Scripts" Change sets: (1002) ---$ john "test memory" 17-Sep-2014 02:24 PM Changes: --a--... (9 Replies)
Discussion started by: gaurav99
9 Replies

3. UNIX for Dummies Questions & Answers

Delete .txt file from current directory

I have created few text file during run time by redirecting the txt file echo USER_LIST_"$(date '+%d%h%Y')".csv > report_location.txt report_location.txt is creating in the same location where I run script home/script When I try to remove the txt file at the end of the... (3 Replies)
Discussion started by: stew
3 Replies

4. Shell Programming and Scripting

Delete File in a Directory Using a Condition

Hello, I have a directory with many files whose creation time is distributed all over the day. I need ANY 20 files per hour. So, I need 20 files for hour 00 20 files for hour 01 ... 20 files for hour 23 What I have done so far is not great. Here is the code: # get the Month a=`echo... (8 Replies)
Discussion started by: shekhar2010us
8 Replies

5. Shell Programming and Scripting

delete only particular file in directory shell script

Hi, what function do we use to delete only particular file that we want in directory shell script for example I want only to delete test.txt in directory how to do it ? in sh Thank (1 Reply)
Discussion started by: guidely
1 Replies

6. UNIX for Dummies Questions & Answers

Not able to delete this file/directory/entry

Hello UNIX gurus, I noticed this file or whatever in one of our directories, and somehow I am not able to proceed with my work, without deleting this one. .insert--- 1 siebload intrface 0 Feb 22 01:25 Testfile I am confused, as it doesnt appear to be a file, and on doing any... (2 Replies)
Discussion started by: ppathak1234
2 Replies

7. Shell Programming and Scripting

Script to delete all something.txt~ file from a directory

There are some files in a directory like a.tx~ , b.txt~,c.txt~. I want to delete all these files inside that directory and sub directory. How can i do this? #!/bin/bash cd thatdirectory ...... rm -rf *~ ...... (7 Replies)
Discussion started by: cola
7 Replies

8. Shell Programming and Scripting

find full directory and delete old dated file?

I want to write a code that will look for a particular directory which is full or more than 95% used, and will search older file and delete it. My code looks like this: df -k|while read f1 f2 f3 f4 f5 f6 do if expr '$f5' -ge '95%' || continue then echo $f5 else echo "there is no... (2 Replies)
Discussion started by: xramm
2 Replies

9. Shell Programming and Scripting

i want to delete a file based on existing file in a directory

hi i am having four files in a directory.like 1)sampleRej 2)exampleRej 3)samplemain 4)examplemain my requirement is i have to search for the rejected files (sampleRej,exampleRej) in a directory.if these files in that directory then i have to delete the main files... (3 Replies)
Discussion started by: srivsn
3 Replies

10. UNIX for Dummies Questions & Answers

Delete Core file in root directory

HP UX 11i Ok my server is about to run out of space, and i would like to know if there is something that i should be doing on a regular basis to maintain the machine like logs that i should clear or dmp file that i should delete... Thanks in Advance (2 Replies)
Discussion started by: bbutler3295
2 Replies
Login or Register to Ask a Question