remove files with 0 size, space and double qoute


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove files with 0 size, space and double qoute
# 1  
Old 02-07-2002
remove files with 0 size, space and double qoute

os=hpux11
shell=ksh

some jokers had written thousands of empty files into my $HOME. and the files are named inconsistently that some of them include space and double qoutes. all those files are of 0 size (when i did ls -al it told me so). the naming paterns are
like e.g of ls -al output:
Quote:
-rwxr-xr-x 1 unify dba 0 Feb 4 16:48 .file
-rwxr-xr-x 1 unify dba 0 Feb 4 16:48 .file name
-rwxr-xr-x 1 unify dba 0 Feb 4 16:48 .file "name"
being new to shell scripting i wrote this script:
Code:
#!/usr/bin/ksh
for i in `ls -al | awk '$5 < 1 {print $9}'`
do
  /usr/bin/rm $i
done

thank god that my attempt worked, but removed only the files whose name without space or double qoute. while the rest i am still cracking my little brain finding a way to deal with them.

any idea, pls.
# 2  
Old 02-07-2002
i would apply different logic than yours:
Code:
#!/usr/bin/ksh
for i in `ls -a`
do
  FILESIZE=`ls -l $i|awk '{print $5}'`
  if [ $FILESIZE -eq 0 ]
  then
    /usr/bin/rm $i
  fi
done

this way rm will surely remove no matter how a file is named.
# 3  
Old 02-07-2002
emmm...it was just a matter of programming logic huh. your idea worked just like what i desperately hope. thank you brother kanang and others too. i begin to like this forum. Smilie
# 4  
Old 02-08-2002
find out who did this, pronto!

You might want to set up a cron job to run and collect user's history files and copy them to an inconspicuous directory.

Or go the $HOME directory and try to grep each user's history file for commands that you suspect were used.

This is part of being an admin. You need to find out who did this and report it if necessary. or at least document it for future ammunition.

Any user that would do this will soon try to breach root on your box. Count on it!



Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Ssh login with random qoute banner

I'll be honest here The one and only time I have done LDAP user and login configuration was for my RHCSA exam, and that was many years ago I have this interview coming up (for a linux admin position role), and while the other questions I have no problem answering I am stuck with this (image... (5 Replies)
Discussion started by: hedkandi
5 Replies

2. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

3. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

4. UNIX for Dummies Questions & Answers

Remove two delimiters, space and double quotes

I would like to know how to replace a space delimiter with a ^_ (\037) delimiter and a double quote delimiter while maintaining the spaces inside the double quotes. The double quote delimiter is only used on text fields. I'd prefer a one-liner, but could handle a function or script that accepts... (4 Replies)
Discussion started by: SteveDWin
4 Replies

5. Shell Programming and Scripting

want to remove comma present inside double qoute

Hi friends... I have a dat file like below:- test_file.dat abc,ttt,"""123,89.98",yyu,opp vvv,"23,76.68",w564,"54,98.87",985 i need the remove the comma present inside the double qoute as output:- out_test_file.dat abc,ttt,"""12389.98",yyu,opp vvv,"2376.68",w564,"5498.87",985... (6 Replies)
Discussion started by: gani_85
6 Replies

6. Shell Programming and Scripting

To remove the files in MB size

Hi, Using the shell script, I need to remove the files that are larger than 50 MB in size. I am not good in shell scripting. (1 Reply)
Discussion started by: gsiva
1 Replies

7. Shell Programming and Scripting

To remove files with 0 File Size

Dear All, I want to remove files having size of (0) that are generated once script is completed. Here is the code but i m not sure about /usr/bin do i need to write /usr/bin, or the path of my script /tmp/test please find below the script logic #!/usr/bin/ksh for i... (9 Replies)
Discussion started by: jojo123
9 Replies

8. Shell Programming and Scripting

Check file size and remove files

Hi, Here we have a situation where we have to check the file size and if the file size is greater than 0 bytes then remove the files from the directory. 1)EdwTrxn 2)EdwPost 3)EdwTndr 4)EdwSls 5)EdwSlsRej 6)EdwTndrRej Files will be created in the directory in the following manner. ... (5 Replies)
Discussion started by: srivsn
5 Replies

9. What is on Your Mind?

Hacker=Knowlegde Qoute

I don't know if anyone has seen this commercial, either on TV or on the internet, but it's an IBM Linux Prodigy commercial. Linux Prodigy 4Gf6hq8J_DQ At around 33 seconds there is a quote about collecting and sharing data. A couple of friends and I watched this and decided to try to create a... (0 Replies)
Discussion started by: Texasone
0 Replies

10. Shell Programming and Scripting

bash script working for small size files but not for big size files.

Hi, I have one file stat. Stat file contents are as follows: for example. H50768020040913,00260100,507680,13,0000000643,0000000643,00000,0000 H50769520040808,00260100,507695,13,0000000000,0000000000,00000,0000 H50770620040611,00260100,507706,13,0000000000,0000000000,00000,0000 Now i... (1 Reply)
Discussion started by: davidpreml
1 Replies
Login or Register to Ask a Question