Visit Our UNIX and Linux User Community


remove files from a directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers remove files from a directory
# 15  
Old 07-24-2009
Hiya,

I am also kind of new, so may be an 'apprentice' look can help,

Why do not you delete whole directory whereever you create those files?
rm -r 'directory_name'
would delete the directory including its contents.

If there are other files in the directory, that you may need, do not use the command above.

Can you carry out other tasks with the files? mv, cp, etc?
# 16  
Old 07-24-2009
Yes. That's a great idea.

I'd add "ls" to your list of what other commands you can do.

But without knowing why it happened, it might happen again, which is why I'd like to see the code that created the files.
# 17  
Old 07-24-2009
Yes, by all means, seeing the script will help experienced users identify the problem.
# 18  
Old 07-24-2009
ls -lia | sed -n l

Code:
 $ls -lia | sed -n l
total 27$
 8245 drwxr-xr-x    2 schroeks x_exp           512 Jul 23 12:58 .$
 8242 drwxr-xr-x    4 root     x_exp           512 Jun 03 21:32 ..$
 8261 -rw-------    1 schroeks x_exp           333 Jul 10 09:40 .bash_h\
istory$
 8257 -rw-r--r--    1 schroeks x_exp          2525 Jun 04 11:42 .dircol\
ors$
 8246 -rwxr-----    1 schroeks x_exp           824 May 20 23:10 .profil\
e$
 8267 -rw-------    1 schroeks x_exp          5544 Jul 24 15:15 .sh_his\
tory$
 8259 -rw-------    1 schroeks x_exp           124 Jul 23 13:22 .vi_his\
tory$
 8258 -rwxr-xr-x    1 schroeks x_exp           768 Jul 21 13:16 cdrrd$
 8273 -rwxr-----    1 schroeks x_exp          1492 Jul 23 12:56 cdrrd1$
 8263 -rw-r--r--    1 schroeks x_exp             0 Jul 23 10:00 rrd$
 8260 -rw-r--r--    1 schroeks x_exp             0 Jul 21 08:24 rrd15CC\
\033[DEC$
 8265 -rw-r--r--    1 schroeks x_exp             0 Jul 21 11:37 rrd15CC\
\177EC$
 8266 -rw-r--r--    1 schroeks x_exp             0 Jul 21 11:59 rrd15CE\
V\033[DC$
 8253 -rw-r--r--    1 schroeks x_exp             0 Jul 21 08:47 rrd15E\
\177CEC$
 8279 -rw-r--r--    1 schroeks x_exp             0 Jul 21 15:48 rrd21CE\
<\177M$
 8276 -rw-r--r--    1 schroeks x_exp             0 Jul 21 15:39 rrd21CE\
C$
 8275 -rw-r--r--    1 schroeks x_exp             0 Jul 23 08:12 rrd21CM\
\177EM$



---------- Post updated at 03:32 PM ---------- Previous update was at 03:26 PM ----------

unfortunatley the script has been changed and I am not creating any more of the files in question but would like to clean up bad files.

just so you can see what I was doing although this may not help now.

Code:
#!/bin/bash

clear

echo "Please enter the date for CD info wanted: \c"
read rrd_date

echo "Please enter CEC CEM or CEP: \c"
read file_name

sleep 2

# Create the output file with CEC CEP or CEM information

echo "Creating $file_name file"

cd /opt/cdunix/work/vcndm

 sleep 2

grep $file_name S2*$rrd_date.* >~/rrd$rrd_date$file_name                S20090722.045

echo "output rrd$rrd_date$file_name file created"

 sleep 2

FILE=~/rrd$rrd_date$file_name

echo $FILE

FS="|"

while read line
do
        # store field 1
        F1=$(echo $line | cut -d$FS -f1)
        echo "$F1" > cdrrdout	
        # store field 2
        F2=$(echo $line | cut -d$FS -f2)
        echo "$F2" > cdrrdout	
        # store field 18
        F18=$(echo $line | cut -d$FS -f18)
        echo "$F18" > cdrrdout
        # store field 19
        F19=$(echo $line | cut -d$FS -f19)
        echo "$F19" > cdrrdout$rrd_date$file_name
        echo "cdrrdout file $rrd_date$file_name has been created"

done < $FILE

# 19  
Old 07-24-2009
---------- Post updated at 10:40 PM ---------- Previous update was at 10:36 PM ----------

[/COLOR]
Quote:
unfortunatley the script has been changed and I am not creating any more of the files in question
Thanks for letting us know Smilie
# 20  
Old 07-25-2009
Thank you for posting the output from

Code:
ls -lia | sed -n l

As I am sure you now realise this shows trailing characters which are not usual in filenames but are allowed in unix. There are no identical inode numbers - which would have told us to run fsck immediately (as was correctly advised in an earlier post).
In this context where we know the name of every file in the directory we don't need to go out of our way to generate an exact match to the filename in order to remove or rename the file.
If for example you need to remove the file called:

Quote:
rrd15CC\033[DEC

There are 5 characters after the visible string "rrd15CC".
Escape, left square bracket, dee, eee, cee .

Code:
rm -i rrd15CC?????

Only delete the file if you are sure !

With some of your wonky filenames we could get multiple matches on a "rm -i filename??" command, though in this context you may wish to choose to remove each match (your decision).

BTW: If you are wondering how I translated "\033" into an Escape character, see "man ascii".

Last edited by methyl; 07-25-2009 at 06:59 PM.. Reason: BTW & and editing problem
# 21  
Old 07-25-2009
If I were you I would check this line:
Code:
grep $file_name S2*$rrd_date.* >~/rrd$rrd_date$file_name                S20090722.045

What is that "S20090722.045"
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #816
Difficulty: Medium
In CSS, E#myid matches an E element with a 'myid' class name.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove empty files in home directory

how to remove empty files tried below command its remove only zero bytes not empty file which is greater then zero byte. for x in * do if then rm $x fi done (8 Replies)
Discussion started by: Kalia
8 Replies

2. Shell Programming and Scripting

remove a whole directory tree WITH files inside?

Assume I want to remove a whole directory tree beginning with /foo/bar/ The directory or sub-directories may contain files. The top directory /foo/bar/ itself should not be deleted. rm -f- r /foo/bar does not work because it requires a directory tree without files. How does it work... (3 Replies)
Discussion started by: pstein
3 Replies

3. Shell Programming and Scripting

Remove two types of files from a directory

Hi All, i need to move two types of files from a directory. I have used the below command to find the files from the directory.. SOURCE_DIR="some directory path" TARGET_DIR="Target Dir" Datestamp=Date_format find $SOURCE_DIR \( -name "*.log" -o -name "*.out" ) - exec ls -1 {} \; now i... (9 Replies)
Discussion started by: ch33ry
9 Replies

4. Shell Programming and Scripting

Remove duplicate files in same directory

Hi all. Am doing continuous backup of mailboxes using rsync. So whenever a new mail arrives it is automatically copied on backup server. When a new mail arrives it is named as xyz:2, when it is read by the email client an S is appended xyz:2,S Eventually , 2 copies of the same file exist on... (7 Replies)
Discussion started by: coolatt
7 Replies

5. UNIX for Dummies Questions & Answers

How to remove directory with subdirectories and files?

I'm trying to remove several directories which contains sun-dirs and files inside. I used the command rm -r <dirname> But, it always ask "examine file in directory <dirname> yes/no?" line by line. So, i need to write "y" for every line. How can i skip this step and remove all directories with... (9 Replies)
Discussion started by: ppa108
9 Replies

6. Shell Programming and Scripting

Remove files from a directory using perl

Hi all, I have the following question. Considder that in the directory /code the script remove.pl exists. What i want is to run this script and remove some files that exist in the directory /dir/tmp. I use the below code but it does not work. system("cd /dir/code"); system("rm FileName"); ... (6 Replies)
Discussion started by: chriss_58
6 Replies

7. UNIX for Advanced & Expert Users

Can't list or remove files from a directory

Hi I have a problem. One of the directories in /var, on one of my servers, has filled up with loads of files. I have tried to list the directory to see what is in it, but the 'ls' command just hangs. Same thing happens when I try to use 'rm' to remove files from that directory. I can see what... (2 Replies)
Discussion started by: m_smith
2 Replies

8. UNIX for Dummies Questions & Answers

remove old files from a directory

Hello I'm new to this forum, so I did a quick scan of the FAQs to see if my problem had been addressed already, since I believe it is probably a very common need. I was surprised that I did not see anything obvious. I need to remove all files from a directory that have a last modified date... (2 Replies)
Discussion started by: 2davidc8
2 Replies

9. Shell Programming and Scripting

remove duplicate files in a directory

Hi ppl. I have to check for duplicate files in a directory . the directory has following files /the/folder /containing/the/file a1.yyyymmddhhmmss a1.yyyyMMddhhmmss b1.yyyymmddhhmmss b2.yyyymmddhhmmss c.yyyymmddhhmmss d.yyyymmddhhmmss d.yyyymmddhhmmss where the date time stamp can be... (1 Reply)
Discussion started by: asinha63
1 Replies

10. HP-UX

Want to remove files from unix directory

Dear All I am basic user of Unix. i woul like to delete some files (basically 05 and 0801111105) from unix directories but unable to delete it I tried all option. rm , rm -f etc.. but not succeed. Infact it also not allowing me to use chmod option so that i can grant 777 option to... (1 Reply)
Discussion started by: yogi_chavan
1 Replies

Featured Tech Videos