Trying to delete a directory pattern-selective deletion


 
Thread Tools Search this Thread
Special Forums UNIX Desktop Questions & Answers Trying to delete a directory pattern-selective deletion
# 1  
Old 04-02-2011
Trying to delete a directory pattern-selective deletion

Trying to delete a directory or a file using a pattern-selective deletion (using “*” and “?” )
# 2  
Old 04-04-2011
By respect for people who read you, could you please take the time to post something that make sens ?
Thanks in advance for your time
# 3  
Old 04-04-2011
As ctsgnb says, could you please rephrase this question and post a practical example, what you have to deal with? Thanks.
# 4  
Old 04-05-2011
You can create directories, subdirectories and subsubdirectories in one swoop with the mkdir -p command (brace expansions) using the bash shell (3.0 or higher!).

Code:
mkdir -p newdir{1..2}/subdir{1..3}/subsubdir{1..2}

You can delete them again with rm -r:

Code:
rm -r new*

Does that help?
This User Gave Thanks to sgruenwald For This Post:
# 5  
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
Login or Register to Ask a Question