Visit Our UNIX and Linux User Community


Delete file from folder


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Delete file from folder
# 1  
Old 10-31-2009
Error Delete file from folder

Hi all,
I amd new in UNIX programming. I have a query.
I need to delete some files (like .dec files) from some folders. I have a list of folders. What will be command for it.
Please help me.

Thanks in Advance.
# 2  
Old 10-31-2009
cd /folder
rm -f *.dec (will del all file with .dec)

or

rm -f filename (del one file)
# 3  
Old 10-31-2009
Thx for reply but i have a list of folders from which i have to delete .dec files. How to delete from them at one time. any for loop or something has to be used??
# 4  
Old 10-31-2009
for loop or while loop:


cat filename | while read line
do
cd $line
rm -f *.dec
done
# 5  
Old 10-31-2009
I have a file in which i am having all folder name in diffrent lines. So accoding to you this command will work? Sorry i am asking again but i have to use this in live environment
# 6  
Old 10-31-2009
let says, you have folder:

/tmp

and subfolders /tmp/test1 and /tmp/test1

content in your filename looks like this:

/tmp/test1
/tmp/test2

while loop will read line, and cd $line which means cd /tmp/test1 and rm -f *.dec in /tmp/test1, next, read next line

do it on test env first, or best advise, cp -rp /tmp/test1 /tmp/test1.bkup, just in case you screw up.
# 7  
Old 11-07-2009
Why Not,

Use the find command. This is a very powerful command. Please use this to make sure you have the right files before running the second command. Obviously replace "folders" with the directory you are searching:

Code:
find /folders -type f  "*.dec"

Once you are confident that find has located the files, than run the below command.

Code:
find /folders -type f  "*.dec" -exec rm -f {} \; -print

HTH,
Jaysunn
 

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete oldest folder based on folder named as date

Hi, I have a script doing backup to synology server, the script create new folder each day with the date as being folder name i.e. 2018-07-30. Just before creating the new folder I want the script to find the oldest folder from the list and delete it including its content. for example... (3 Replies)
Discussion started by: humble_learner
3 Replies

2. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

3. Shell Programming and Scripting

How to delete more than 7 days file from Target folder?

Hi Team, I have to remove files which are more than 7 days in my target directory. I have this script but using this i faced some problems like, removed library files of unix. for abc in `find /xxx/abc/OutputFiles/xxxx_*.txt -type f -mtime +5|xargs ls 1` do echo "xxx files are:"$abc ... (1 Reply)
Discussion started by: harris
1 Replies

4. UNIX for Dummies Questions & Answers

To delete the oldest files in a file when file count in the folder exceeds 7

Hi All, I need to delete the oldest file in folder when the file count in the folder exceed 6 ( i have a process that puts the source files into this folder ) E.x : Folder : /data/opt/backup 01/01/2012 a.txt 01/02/2012 b.txt ... (1 Reply)
Discussion started by: akshay01987
1 Replies

5. Shell Programming and Scripting

rsync delete single file from the target folder

Hi We want to delete a single file from the destiantion directory using rsync. Is it possible to do this ? or Do we have any alternate approaches in rsync( for ex applying some filters ..etc) For ex: ----------------------------------------------- Source (Folder) ... (3 Replies)
Discussion started by: MVEERA
3 Replies

6. Shell Programming and Scripting

Folder permissions to delete

I am using the below command to delete files from directories and subdirectories find /test/abc/xyx -type f -mtime +7 -exec rm -f {} \; there are some subfolders in xyx for which i don't have permission to delete. Is there a way i can check the permission of the folder first and then delete... (4 Replies)
Discussion started by: ch33ry
4 Replies

7. Shell Programming and Scripting

Script that delete a File when a DEL File will be placed in same folder

Hi there, i have a question. I have a folder called /usr/test There is a file in it.... test.csv I need not a shell script that checks if there is a file called: test.del And if the file is in the same folder then the script should delete the test.csv and also the test.del. Hope... (9 Replies)
Discussion started by: Bjoern28
9 Replies

8. Shell Programming and Scripting

Auto delete the folder

Hi, i have the directory structure directory /home/ncs/controller/logs/ in this path i have following directories cl03032010 cl04032010 cl05032010 cl06042010 i want to delete the folders which are 2 weeks old.. through the crontab (2 Replies)
Discussion started by: mail2sant
2 Replies

9. Shell Programming and Scripting

delete all the files in folder a which exist in folder b

Hi , I need a script which basically deltes all files in folder a which are alreasy present in folder b say folder a has files abc.txt pqr .txt and b has abc.txt pqr.txt rmr.txt then file abc.txt and pqr.txt from a should be deleted (6 Replies)
Discussion started by: viv1
6 Replies

10. Shell Programming and Scripting

Bash script to delete folder based on text file information

I have been working on a script to list all the name's of a subfolder in a text file then edit that text file and then delete the subfolder base on the edited text file so far I have been able to do every thing I just talked about but can't figure out how to delete the subfolers base on a text file... (8 Replies)
Discussion started by: bone11409
8 Replies

Featured Tech Videos