need to navigate into specified folder and delete the files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to navigate into specified folder and delete the files
# 1  
Old 10-03-2011
need to navigate into specified folder and delete the files

Hi all,

I need to write a script to naviagate into the list of specified folder and delete the files in it.

I have mentioned the list of folders in a external file so it can be reusable.

The issue is am facing now is that, i am not understating on how to navigate into the folder locations specified inside the external file.
For now i am using this mechanisum...
Code:
cat /filelist.txt | while read INTLIST
do

  rm -rf *

done

but this is throwing error as

Code:
INTLIST:  not found


here filelist.txt has the list of paths to which i have to navigate....


please help....

Thanks,
N

Last edited by Franklin52; 10-03-2011 at 03:14 AM.. Reason: Please use code tags and indentation
# 2  
Old 10-03-2011
Code:
$ awk '{print "rm "$0"/*"}' filelist.txt | sh

# 3  
Old 10-03-2011
hi,


can u plz give me a small detail of the above command...
whr to use it???

do i need to use it instead of rm - rf * or cat /filelist.txt | while read INTLIST???

i am completely new to unix...
# 4  
Old 10-03-2011
Code:
$ awk '{print "rm "$0"/*"}' /path/of/filelist.txt | sh

You can execute this line alone to remove the files inside the specified directories mentioned in filelist.txt .
This awk command will append the "rm" command syntax to your existing filelist.txt file and it passes the content to "sh" to remove it .. For testing purpose, neglect the "sh" and run the code.. If satisfies with the result then add "sh" at the end .. Hope it clears ..
# 5  
Old 10-03-2011
Quote:
Originally Posted by jayan_jay
Code:
$ awk '{print "rm "$0"/*"}' /path/of/filelist.txt | sh

You can execute this line alone to remove the files inside the specified directories mentioned in filelist.txt .
This awk command will append the "rm" command syntax to your existing filelist.txt file and it passes the content to "sh" to remove it .. For testing purpose, neglect the "sh" and run the code.. If satisfies with the result then add "sh" at the end .. Hope it clears ..
will this run even if i specify 10 to 12 paths in the filelist.txt???
# 6  
Old 10-03-2011
Yes .. It will run ..
# 7  
Old 10-03-2011
Thanks jay

Quote:
Originally Posted by jayan_jay
Yes .. It will run ..
Thanks a lot!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

For loop to accept params and delete folder/files

Hi Folks - I'm trying to build a simple for loop to accept params and then delete the folder & files on the path older than 6 days. Here is what I have: Purge () { for _DIR in "$1" do find "${_DIR}"/* -mtime +0 -exec rm {} \; done } I would be passing... (4 Replies)
Discussion started by: SIMMS7400
4 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

Script to delete files in a folder older than 2 days

hi i need a script to delete the files older than 2 days... if my input is say in a folder versions A_14122012.txt A_15122012.txt A_16122012.txt A_17122012.txt i want my output to be A_16122012.txt A_17122012.txt thanks in advance hemanth saikumar. (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

4. UNIX for Dummies Questions & Answers

Script to delete files in different folder

Hi Experts, i need a little help. i have different folder that contain files that need to be deleted. but those folder contains huge amoung of same with 3 different extention. what i used to do is to delete them using the rm commande rm *.ext *.ext1 *.ext3 what i want to do is to have... (1 Reply)
Discussion started by: yprudent
1 Replies

5. Shell Programming and Scripting

rsync delete specific files - from different target folder

Hi, I need to use rsync to delete multiple files(only specified files not all) using --delete option, these files are located in different target folders. Instead of running rsync command multiple times for each file, can we achieve this with one time execution? your help is much... (0 Replies)
Discussion started by: MVEERA
0 Replies

6. Shell Programming and Scripting

Delete files in a folder with a specific ending

Hi I have files that end with .txt.txt that i want to delete. But I also have files that end with .txt that I want to leave intact. How do I specifically delete files that end with .txt.txt in a folder. thanks (5 Replies)
Discussion started by: kylle345
5 Replies

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

8. UNIX for Dummies Questions & Answers

How to navigate previous files one by one.

Hi can you tell me if i have opened no of files using vi editior then how can i navigate previous files one by one. Suppose i have opened five files using vi editor as below vi file1 file2 file3 file4 file5 and nom i am in the last file file5 then if i want to go to previous file file 4 and... (5 Replies)
Discussion started by: ajayshukla
5 Replies

9. UNIX for Dummies Questions & Answers

How can i delete files in folder by date?

Hi, I have some files on a folder and i want to delete all the files that were created on July. Thanks, Kobi. (9 Replies)
Discussion started by: kobibn
9 Replies

10. Shell Programming and Scripting

delete all folders/files and keep only the last 10 in a folder

Hi, I want to write a script that deletes all folders and keep the last 10 recent folders. I know the following: ls -ltr will sort the folders from old to recent. ls -ltr | awk '{print $9}' will list the folder names (with a blank line at the beginning) I want to get the 10th folder from... (3 Replies)
Discussion started by: melanie_pfefer
3 Replies
Login or Register to Ask a Question