Sponsored Content
Special Forums UNIX Desktop Questions & Answers Trying to delete a directory pattern-selective deletion Post 302518581 by herberwz on Saturday 30th of April 2011 10:47:34 AM
Old 04-30-2011
A script that deletes files.

I want to write a script that deletes files inside the dir. However, the script
should also allow the user to confirm by pressing (d) key.
Code:
#!/bin/bash
for file in $1/*
do
        size='ls -l $file | cut -f 5 -d " "'
        name='ls -l $file | cut -f 9 -d " "'
        let "rem=$size%2"
        if [ $rem -eq 0 ]; then
                echo "file $name is to be deleted"
                read -p "press <d> to confirm" answer
                if [ "$answer" == "d" ]; then
                        rm $name
                fi
        fi
done


Last edited by Scott; 04-30-2011 at 12:04 PM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

vi part-pattern matching and deletion

Hi, I have a log file which shows the files which has been changed over the last week. They follow this pattern: old_file_version_number@@new_file_version_number Now I need to know how to delete from each line parts starting from @@. I would be issuing the command inside vi(m). So... (5 Replies)
Discussion started by: vino
5 Replies

2. Shell Programming and Scripting

file and directory deletion script

I saw many post about this but could not find a specific answer to this question. i have the following code find . -depth -name "$FILEEXT" -ctime -30 -exec rm {} \; when i type ./deletefiles.sh *.txt for example, it will find all the txt files less than 30 days old and delete them. my... (9 Replies)
Discussion started by: new2learn09
9 Replies

3. Shell Programming and Scripting

Pattern Matching and text deletion using VI

Can someone please assist me, I'm trying to get vi to remove all the occurences of the text in a file i.e. "DEVICE=/dev/mt??". The "??" represents a number variable. Is there a globel search and delete command that I can use? Thank You in Advance. (3 Replies)
Discussion started by: roadrunner
3 Replies

4. Shell Programming and Scripting

Sed for selective pattern replacement

Hi I am having a code snippet grant permission to all user sts|ln|uSe|PSG sajncht|se|Use|PPSPSG psg|ln|use|TSPSG sts_user.Me revoke I need to change all occurance of use (uSe,Use,use) with USE. I am using the following sed command for this sed 's//USE/g' s_sample.txt Output: (7 Replies)
Discussion started by: sudeep.id
7 Replies

5. Shell Programming and Scripting

RegEx - selective delete around a pattern

I need RegEx to delete text block delimited by "^--" and "^request saved" if the block contained the pattern "FAILED:No air,rail,hotel or car" in the following. Many thanks in advance! company_id=9292 queue_id=72 internationalOnly=0 Building XML... ABC123 Adding passenger first=First ... (1 Reply)
Discussion started by: roshansharma
1 Replies

6. UNIX for Dummies Questions & Answers

sed - combination of line deletion and pattern matching

I want to delete all the blank lines from a file before a certain line number. e.g. Input file (n: denotes line number) 1: a 2: 3: b 4: c 5: 6: d I want to delete all blank lines before line number 3, such that my output is: a b c d I see that sed '/^$/d' in_file works... (9 Replies)
Discussion started by: jawsnnn
9 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Selective delete command

Hi All. I didnt know how to put this question as but i want to delete my values following string_X but need to retain the data in it. I hope the following might help me in conveying my doubt. My sequence looks like this. >string_1 CAJW010000001... (3 Replies)
Discussion started by: sonia102
3 Replies

8. UNIX for Dummies Questions & Answers

Selective delete in SQL

Hi All This might be a weird query but its related to deleting specific details in database. Bascially I had built a database using a set of files seq1 of 300 mb seq2 of 200 mb seq3 of 350 mb seq4 of 300 mb and after building the database i realized that i didn't need the whole data.... (6 Replies)
Discussion started by: sonia102
6 Replies

9. Shell Programming and Scripting

How to copy selective list of files to a directory?

Hi I have 3 directories indexes_with_ts indexes_without_ts process_indexes in each directories it contains *.sql how do I accomplish this: for all the files found in indexes_without_ts, copy the corresponding file in indexes_with_ts to process_indexes. i.e. for... (2 Replies)
Discussion started by: jediwannabe
2 Replies

10. UNIX for Dummies Questions & Answers

Selective replace and delete

Hi My input file looks like this: >BAHMI01000090.1 Details of the shopping list 9800 item00090, whole set of listed artifacts and objects >BAHMI01050012.1 Details of the shopping list 9800 item02310, whole set of listed artifacts and objects >BAHMI01070078.1 Details of the shopping list ... (5 Replies)
Discussion started by: sonia102
5 Replies
IMAP_DELETE(3)								 1							    IMAP_DELETE(3)

imap_delete - Mark a message for deletion from current mailbox

SYNOPSIS
bool imap_delete (resource $imap_stream, int $msg_number, [int $options]) DESCRIPTION
Marks messages listed in $msg_number for deletion. Messages marked for deletion will stay in the mailbox until either imap_expunge(3) is called or imap_close(3) is called with the optional parameter CL_EXPUNGE. PARAMETERS
o $ imap_stream -An IMAP stream returned by imap_open(3). o $msg_number - The message number o $options - You can set the FT_UID which tells the function to treat the $msg_number argument as an UID. RETURN VALUES
Returns TRUE. EXAMPLES
Example #1 imap_delete(3) example <?php $mbox = imap_open("{imap.example.org}INBOX", "username", "password") or die("Can't connect: " . imap_last_error()); $check = imap_mailboxmsginfo($mbox); echo "Messages before delete: " . $check->Nmsgs . "<br /> "; imap_delete($mbox, 1); $check = imap_mailboxmsginfo($mbox); echo "Messages after delete: " . $check->Nmsgs . "<br /> "; imap_expunge($mbox); $check = imap_mailboxmsginfo($mbox); echo "Messages after expunge: " . $check->Nmsgs . "<br /> "; imap_close($mbox); ?> NOTES
Note IMAP mailboxes may not have their message flags saved between connections, so imap_expunge(3) should be called during the same con- nection in order to guarantee that messages marked for deletion will actually be purged. SEE ALSO
imap_undelete(3), imap_expunge(3), imap_close(3). PHP Documentation Group IMAP_DELETE(3)
All times are GMT -4. The time now is 02:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy