Sponsored Content
Full Discussion: Delete files in a txt file
Top Forums UNIX for Dummies Questions & Answers Delete files in a txt file Post 302968284 by Don Cragun on Monday 7th of March 2016 01:56:18 PM
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!
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
rdfind(1)							      rdfind								 rdfind(1)

NAME
rdfind - finds duplicate files SYNOPSIS
rdfind [ options ] directory1 | file1 [ directory2 | file2 ] ... DESCRIPTION
rdfind finds duplicate files across and/or within several directories. It calculates checksum only if necessary. rdfind runs in O(Nlog(N)) time with N being the number of files. If two (or more) equal files are found, the program decides which of them is the original and the rest are considered duplicates. This is done by ranking the files to each other and deciding which has the highest rank. See section RANKING for details. If you need better control over the ranking than given, you can use some preprocessor which sorts the file names in desired order and then run the program using xargs. See examples below for how to use find and xargs in conjunction with rdfind. To include files or directories that have names starting with -, use rdfind ./- to not confuse them with options. RANKING
Given two or more equal files, the one with the highest rank is selected to be the original and the rest are duplicates. The rules of rank- ing are given below, where the rules are executed from start until an original has been found. Given two files A and B which have equal content, the ranking is as follows: If A was found while scanning an input argument earlier than than B, A is higher ranked. If A was found at a depth lower than B, A is higher ranked (A closer to the root) If A was found earlier than B, A is higher ranked. The last rule is needed when two files are found in the same directory (obviously not given in separate arguments, otherwise the first rule applies) and gives the same order between the files as the operating system delivers the files while listing the directory. This is operat- ing system specific behaviour. OPTIONS
Searching options etc: -ignoreempty true|false Ignore empty files. (default) -followsymlinks true|false Follow symlinks. Default is false. -removeidentinode true|false removes items found which have identical inode and device ID. Default is true. -checksum md5|sha1 what type of checksum to be used: md5 or sha1. Default is md5. Action options: -makesymlinks true|false Replace duplicate files with symbolic links -makehardlinks true|false Replace duplicate files with hard links -makeresultsfile true|false Make a results file results.txt (default) in the current directory. -outputname name Make the results file name to be "name" instead of the default results.txt. -deleteduplicates true|false Delete (unlink) files. General options: -sleep Xms sleeps X milliseconds between reading each file, to reduce load. Default is 0 (no sleep). Note that only a few values are supported at present: 0,1-5,10,25,50,100 milliseconds. -n -dryrun displays what should have been done, dont actually delete or link anything. -h, -help, --help displays brief help message. -v, -version, --version displays version number. EXAMPLES
Search for duplicate files in home directory and a backup directory: rdfind ~ /mnt/backup Delete duplicate in a backup directory: rdfind -deletefiles true /mnt/backup Search for duplicate files in directories called foo: find . -type d -name foo -print0 |xargs -0 rdfind FILES
results.txt (the default name is results.txt and can be changed with option outputname, see above) The results file results.txt will con- tain one row per duplicate file found, along with a header row explaining the columns. A text describes why the file is considered a duplicate: DUPTYPE_UNKNOWN some internal error DUPTYPE_FIRST_OCCURRENCE the file that is considered to be the original. DUPTYPE_WITHIN_SAME_TREE files in the same tree (found when processing the directory in the same input argument as the original) DUPTYPE_OUTSIDE_TREE the file is found during processing another input argument than the original. ENVIRONMENT
DIAGNOSTICS
EXIT VALUES
0 on success, nonzero otherwise. BUGS
/FEATURES When specifying the same directory twice, it keeps the first encountered as the most important (original), and the rest as duplicates. This might not be what you want. The symlink creates absolute links. This might not be what you want. To create relative links instead, you may use the symlinks (2) com- mand, which is able to convert absolute links to relative links. Older versions unfortunately contained a misspelling on the word occurrence. This is now corrected (since 1.3), which might affect user scripts parsing the output file written by rdfind. There are lots of enhancements left to do. Please contribute! SECURITY CONSIDERATIONS
Avoid manipulating the directories while rdfind is reading. rdfind is quite brittle in that case. Especially, when deleting or making links, rdfind can be subject to a symlink attack. Use with care! AUTHOR
Paul Dreik 2006, reachable at rdfind@pauldreik.se Rdfind can be found at http://rdfind.pauldreik.se/ Do you find rdfind useful? Drop me a line! It is always fun to hear from people who actually use it and what data collections they run it on. THANKS
Several persons have helped with suggestions and improvements: Niels Moller, Carl Payne and Salvatore Ansani. Thanks also to you who tested the program and sent me feedback. VERSION
1.3.1 (release date 2012-05-07) svn id: $Id: rdfind.1 766 2012-05-07 17:26:17Z pauls $ COPYRIGHT
This program is distributed under GPLv2 or later, at your option. SEE ALSO
md5sum(1), find(1), symlinks(2) May 2012 1.3.1 rdfind(1)
All times are GMT -4. The time now is 01:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy