Remove empty files in home directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove empty files in home directory
# 1  
Old 01-17-2018
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.

Code:
for x in *
 do
    if [ -s $x ]
    then
       rm $x
    fi
 done

# 2  
Old 01-17-2018
Please explain the difference between an empty and a zero byte file. Show an "empty file which is greater then zero byte".
# 3  
Old 01-17-2018
if will create emty file using touch command it will create empty file with zero size and if we will create emty file in vi editor then size will be greater then 0 with no data
# 4  
Old 01-17-2018
If you create an empty file in vi, then it will also be zero bytes in size..
# 5  
Old 01-17-2018
Any file with one or more bytes (even spaces!) in it is NOT an empty file. It may not contain meaningful or readable or interpretable data, nor even a (complete) line, but systemwise it will be treated as a non-empty file.
# 6  
Old 01-19-2018
We can find zero size file using below comand if we want search 0 size and along with empty file
(File not contain any data may be space which is greater then 0 size ) want to remove
those file in my home directory
Code:
find . -type f -size 0 -exec rm {} \;

# 7  
Old 01-19-2018
I'm not really sure of the point you're trying to make. An empty file is a zero length file. A file that isn't zero-length, whether it contains only spaces or not, is not an empty file. If you want to remove files that you consider to be "empty", then you'll need to check those those files.

I appreciate that English may not be your first language, but some punctuation would make it simpler to parse your statements.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I check, if on remote server directory is empty or have files?

I have a script, which is supposed to run 1 day of the month, connect to remote server certain directory, find files, tar the, and copy find . -ctime -1 | tar -cvf transfer_dmz_start_monthly.tar *${Today}*.*; if then echo "Cannot create a tar file, the terminated... (2 Replies)
Discussion started by: digioleg54
2 Replies

2. Shell Programming and Scripting

Shell script to remove empty files

Hi All, Can anyone please write a shell script to remove the empty files using an if condition. please help me out , urgent thanks (6 Replies)
Discussion started by: muthi_murali
6 Replies

3. UNIX for Advanced & Expert Users

cksum for all files in home directory

I know i can run cksum <filename> . However, how i can run cksum on all the files and directories in the $HOME ?? (SUNOS) (4 Replies)
Discussion started by: moe458
4 Replies

4. Shell Programming and Scripting

help with removing files from home directory

hey there folks! I cant figure out, for the life of me, how to procede in removing alll the files in my home directory that are not owned by me. would i have to list them, but after that what do i do. or is there some way I am not aware of. my employer heard i could script in unix, but i havent... (3 Replies)
Discussion started by: Ginkosu
3 Replies

5. Solaris

Newbie questions about HOME directory files

Hi, I am newbie to Solaris and system administration in general, and I have a couple of questions about files in my HOME directory. When I perform ls -la, I get the following list of files: drwxr-xr-x 7 XXXYYY staff 17 Aug 24 07:31 . drwxr-xr-x 7 root root 7... (2 Replies)
Discussion started by: JVerstry
2 Replies

6. Shell Programming and Scripting

remove empty directory

Hi, I need to delete an empty directory in a temp directory except "dir5" (keep everything that is not empty). Plese advise. Here is an example of my directory. /dir/temp/ dir1 - delete if this is empty dir2 - delete if this is empty dir3 - delete if this is empty dir4 - delete if this... (7 Replies)
Discussion started by: sirrtuan
7 Replies

7. Shell Programming and Scripting

How to empty all files in a directory

Hi all, Can you tell me how to empty all files in a directory with a "find" command? It does not seem to work the way I try it: # ls -l *.dat -rw-r--r-- 1 root root 7 Jul 20 20:51 la2.dat -rw-r--r-- 1 root root 4 Jul 20 20:51 la.dat # find... (9 Replies)
Discussion started by: majormark
9 Replies

8. Cybersecurity

Strange files keep appearing in my home directory

Hi everyone, really strange files keep appearing in my home directory. I have absolutely no idea where they come from and I'm a little concerned that they could come from some kind of malware activity or Firefox exploit. I searched Google for parts of the file names but without a result. The... (6 Replies)
Discussion started by: schallstrom
6 Replies

9. Shell Programming and Scripting

Script to remove all empty files within the directory structure?

Hi I need to write a shell script which basically searches for all the empty files within the directory structure, lists them before asking the user to confirm if they would like to delete them. If the user deletes the file then a notice would appear confirming the file is deleted. I've be... (5 Replies)
Discussion started by: cat123
5 Replies

10. Shell Programming and Scripting

deleting empty files in a directory

Hello Gurus, I want to delete only empty files (files with 0 bytes) at once from the local directory. Rightnow I need to go through all the files one by one manually and check the empty files before deleting them. Is there any unix command that finds and deletes empty files in a directory?... (5 Replies)
Discussion started by: berlin_germany
5 Replies
Login or Register to Ask a Question