Sponsored Content
Homework and Emergencies Homework & Coursework Questions Find and delete empty files and directories Post 302590790 by Itixop on Tuesday 17th of January 2012 02:31:58 PM
Old 01-17-2012
Question Find and delete empty files and directories

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
Need to make a script, to remove all empty files and folders from current category.
It also should show the name and creation date of those items.

2. Relevant commands, code, scripts, algorithms:
Must be bash script.


3. The attempts at a solution (include all code and scripts):

Tried this, but it shows only name of deleted folders...
Code:
echo Removed files:
find . -maxdepth 1 -type f -empty;
find . -maxdepth 1 -type f -empty -exec rm {} \;
echo Removed directories:
find . -maxdepth 1 -type d -empty;
find . -maxdepth 1 -type d -empty -exec rmdir {} \;

Then I tried using
Code:
ls

... But it gave too much information.. I just need name and creation time (Ok.. Creation time isn't stored in UNIX.. So I think a date of last modification would be enough.. )

Code:
echo Removed files:
find . -maxdepth 1 -type f -empty -exec ls -l;
find . -maxdepth 1 -type f -empty -exec rm {} \;
echo Removed directories:
find . -maxdepth 1 -type d -empty -exec ls -l ;
find . -maxdepth 1 -type d -empty -exec rmdir {} \;

But in this code first of all it shows only info about files.. For some reason it doesn't show anything about folders. And secondly: That's not that I need. I need name and date (maybe date, maybe date+time) of creation (last modification).

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Vilniaus Kolegija, Vilnius, Lithuania, M.Liogys, PIN11.

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how to delete empty files in a shell script

I'm trying to figure out a way to delete empty files in a directory. I have a cron that runs and creates a flat file every 15 mins. However, most times at night the flat file will be empty. I'd like to run a script to delete empty files that end with *.dat Any suggestions? Rich (1 Reply)
Discussion started by: rpnuge
1 Replies

2. Red Hat

Find files older than 30 days in directories and delete them

Hi, I have dummies questions: My script here can find the files in any directories older than 30 days then it will delete the files but not the directories. I would like to also be able to delete the directories that hold old files more than 30 days not just the files itself. find . -type f... (2 Replies)
Discussion started by: lamoul
2 Replies

3. Shell Programming and Scripting

Deleting all empty files in sub directories with a command

Hello Friends, Im trying to delete empty files in subdirectories with a command. I can find them checking only one directory in each step and then show them with my command like below moreover i could not add removing part: ls -l */* | awk '{if ($5==0) printf "%3s %2d %s... (5 Replies)
Discussion started by: EAGL€
5 Replies

4. Shell Programming and Scripting

Deleting empty directories using find

Hello, I'm submitting this thread, because I was looking a way to delete empty directories using find and I found a thread from 2007 that helped me. I have worked from that threat, but I found that the command sent would analyze original directory and may delete it to. I have come up with expanded... (3 Replies)
Discussion started by: lramirev
3 Replies

5. Shell Programming and Scripting

Find directories only and delete them created 3 days before

Hello I have some directories and files created under /export/local/user I would like to delete directories only under /export/local/user, created before 3 days Can someone help me with command to do this task? Thanks (4 Replies)
Discussion started by: needyourhelp10
4 Replies

6. Shell Programming and Scripting

Script to delete empty files

I'm trying to write a shell script to files of zero length in a specified directory, but I keep getting errors. Would anybody be kind enough to look it over for issues? Thanks a bunch in advance. #!/bin/sh if then if then find $1 -type f -size 0 -print|xargs rm exit 0... (1 Reply)
Discussion started by: ScriptingIssues
1 Replies

7. UNIX for Advanced & Expert Users

Delete empty directories recursively - HP-UX

Hi, I want to delete all empty directories in a long directore tree structure. I want to use that from a script that will run on HP-UX 11. My definition of empty directory is that there is no regular file under it and directly beneath it. To elaborate, I have below directories. /app/dev/java... (14 Replies)
Discussion started by: asutoshch
14 Replies

8. Shell Programming and Scripting

Delete empty files from a directory entered in command prompt

My code to "Delete empty files from a directory entered in command promt" #/bin/sh echo "Enter directory" read gh for file in `ls $gh` do # to get the size of file a=$( ls -l file | awk ' {print $7} '); echo $a if then echo "removing file " rm file fi done (6 Replies)
Discussion started by: adirajup
6 Replies

9. Shell Programming and Scripting

Script to go Into Directories and Find/Delete files

I have a task, I usually do manually, but with growing responsibilities I tend to forget to do this weekly, I want to write a script that automates this, but I cant seem to work it out in my head, I have the shell of it out, but need help, and you guys have helped me with EVERY problem I have... (5 Replies)
Discussion started by: gkelly1117
5 Replies

10. Shell Programming and Scripting

Shell script to delete empty files from specific locations

Hi, I need help in regard to developing a shell script to delete empty files from multiple specific locations. The directory paths will be stored in a text file. So the requirement is to read the text file for one specific path and then remove empty files from that particular path. Looping through... (4 Replies)
Discussion started by: Khan28
4 Replies
smd-push(1)						 Sync Mail Dir (smd) documentation					       smd-push(1)

NAME
smd-push - syncs the remote mail dir letting the local one untouched SYNOPSIS
smd-push [-d|--dry-run] [-v|--verbose] [-s|--show-tags] [-t|--template-only] [-n|--no-delete] [endpoint] DESCRIPTION
smd-push performs in the remote maildir all the changes that were performed on the local one. No changes are made on the local maildir. Use smd-pull(1) for that. Refer to smd-config(5) for the configuration file format. OPTIONS
-v --verbose Verbose output -s --show-tags Machine readable output -d --dry-run Do not perform any action for real -n --no-delete Do not propagate deletions -t --template-only Just create a template configuration file if none endpoint Is the suffix for the name of the configuration file to use. If it is omitted, the configuration file ~/.smd/config.default is used. FILES
~/.smd/config.* ~/.smd/hooks/pre-push.d/ ~/.smd/hooks/post-push.d/ SEE ALSO
mddiff(1), smd-server(1), smd-client(1), smd-pull(1), smd-loop(1), smd-config(5) AUTHOR
Enrico Tassi <gares@fettunta.org> 11 June 2012 smd-push(1)
All times are GMT -4. The time now is 01:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy