Delete files in a txt file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Delete files in a txt file
# 1  
Old 03-07-2016
Delete files in a txt file

Hi, I have very old files in my server like from 2012 and i want to delete them,

Please help.

Thanks in advance..

Last edited by nanz143; 03-07-2016 at 08:05 AM..
# 2  
Old 03-07-2016
Hello nanz143,

Could you please try and let me know if this helps you.
Code:
while read file
do
    if [[ -f $file ]]
    then
           echo $file
    else
           echo "File " $file " is not present."
    fi
done < "Input_file"

In above solution if you are getting correct results then you could replace echo $file with rm $file.

Thanks,
R. Singh
# 3  
Old 03-07-2016
Unless you have a list of files (as assumed in the code RavinderSingh13 suggested), you could try something like:
Code:
find /dir1 /dir2 ... /dirN -type f ! -newer trigger_path -exec echo rm {} +

where /dir1 ... /dirN are pathnames to the roots of the file hierarchies you want to process and trigger_path is the pathname of a file (not located in any of the file hierarchies you want to process) that has a timestamp indicating the oldest file you want to keep. (You can create such a file using the touch command using a -t option to specify the boundary date and time.) If the pathnames printed by this looks right, take out the echo to actually remove the files.

Note that if you use this with any file hierarchies containing files that are part of your system's initial installation, this can turn your system into a doorstop that will no longer run and won't boot. Don't try this if you don't know what you're doing. There is a huge difference between very old and not needed!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to delete files line by line in .txt document

Friends, I am in need to delete files from a directory on a regular basis. I want to place all the files to be deleted in delete .txt file and require a script to delete files, line by line from this delete.txt file. Please help me with this script as am new to unix scripting. (3 Replies)
Discussion started by: fop4658
3 Replies

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

3. Shell Programming and Scripting

Compare two txt files,mismatches will be in new txt files

Hi, Below are the sample data for txt files. txt file 1 Partnumber|catgroup_id 10001082|46016 10001093|4680 10001093|386003 10001093|463004 10003251|683 10003251|63005 10003252|463005 10003252|4683 10003260|463005 10003260|4683 10003264|4683 10003264|463005 13420000|67... (5 Replies)
Discussion started by: Ankita Talukdar
5 Replies

4. Shell Programming and Scripting

Delete specific parts in a .txt file

Hi all, I desperately need a small script which deletes everything in a particular .txt file when "Abs = {" appears till "},", and also when "B-1 = {" appears till "}," I would like all the text in between of those instances to be deleted, however, other text to be unedited (kept as it is).... (12 Replies)
Discussion started by: c_lady
12 Replies

5. UNIX for Dummies Questions & Answers

Delete files whose file names are listed in a .txt file

hi, I need a help. I used this command to list all the log files which are for more than 10 days to a text file. find /usr/script_test -type f -mtime +10>>/usr/ftprm.txt I want all these files listed in the ftprm.txt to be ftp in another machine and then rm the files. Anyone can help me... (8 Replies)
Discussion started by: kamaldev
8 Replies

6. Shell Programming and Scripting

Delete file2.txt from file1.txt using scripting

Hi, I`m a total newbie, well my requirement is that i have 2 files I want to identify which countries i do not currently have in db.. how can i use the grep or another command to find this file .. i want to match all-countries.txt with countries-in-db.txt so the output is equal to... (11 Replies)
Discussion started by: beanbaby
11 Replies

7. Shell Programming and Scripting

script to delete lines from a txt file if pattern matches

File 6 dbnawldb010-b office Memphis_Corp_SQL_Diff Memphis-Corp-SQL-Inc-Application-Backup 03/09/11 03:24:04 42 luigi-b IPNRemitDB Memphis_Corp_SQL_Diff Memphis-Corp-SQL-Inc-Application-Backup 03/10/11 00:41:36 6 ebs-sqldev1-b IPNTracking Memphis_Corp_SQL_Diff... (4 Replies)
Discussion started by: ajiwww
4 Replies

8. UNIX for Dummies Questions & Answers

recursive delete files from txt file or?

i have a txt file of image names that have to be deleted in pwd how can i use the txt file to delete the files in pwd and is it possible?--i might be able to import the txt files into a spreadsheet ahd same it as a csv file. i want it to be done recursive lly --what i mean is teh sysem goes thru... (4 Replies)
Discussion started by: plener
4 Replies

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

10. UNIX for Dummies Questions & Answers

Command to delete numbers at beginning of txt file line

Hello. I have the following issue: my txt file has the following format: train/dr4/fklc0/sx175.txt 0 80282 Severe myopia contributed to Ron's inferiority complex. train/dr4/fklc0/sx355.txt 0 42906 Dolphins are intelligent marine mammals. train/dr4/fklc0/sa2.txt awk 'NR%2==0' test1.txt >... (4 Replies)
Discussion started by: li_bi
4 Replies
Login or Register to Ask a Question