Sponsored Content
Top Forums Shell Programming and Scripting How to delete files in UNIX using shell script Post 302069296 by theguy16 on Friday 24th of March 2006 03:55:24 AM
Old 03-24-2006
Question How to delete files in UNIX using shell script

Hi,

find /path/to/directory -mtime -5 -ok rm -f {} \

is working fine. But there is one more concern. This command deletes all the files in the specified directory along with files in sub-directories also.

The requirement is like, it should delete files that are 5 Days old only in the directory specified and not the subdirectories within it.

Any idea on how to do that?

Thanks in advance
 

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. Shell Programming and Scripting

shell script for delete old files

i want to delete all the files in my directory except the latest one. i need to do this from shell script. say i have a.txt - latest file b.txt, c.txt.. it should delete all the files except a.txt? (4 Replies)
Discussion started by: krishnarao
4 Replies

3. Shell Programming and Scripting

Delete files older than 2 days using shell script in Unix

I'm new to shell script.... can any one help... What is the shell script to delete the files older than 2 days ? (3 Replies)
Discussion started by: satishpabba
3 Replies

4. Shell Programming and Scripting

delete old files thru unix script

I have to delete files older than 60 days from a windows directory. So I tried to include this script FTP_LOG=${DATA_TOP}/data_tmp/logfile FTP_CMDS=${DATA_TOP}/data_tmp/cmdfile echo "open ftp1" > ${FTP_CMDS} echo "user anonymous local" >> ${FTP_CMDS} echo "cd ${SRC_DIR}" >> ${FTP_CMDS} echo... (3 Replies)
Discussion started by: snair001
3 Replies

5. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

6. Shell Programming and Scripting

Unix shell script to delete files on windows server

Hi experts, can anyone suggest me on the below: how to write a shell script to search and delete files on windows server. -script runs on unix box -it should search for specific files on windows server and delete them periodically. (2 Replies)
Discussion started by: chpradeepch
2 Replies

7. Shell Programming and Scripting

Shell Script to delete the protected files.

Hello, we have more than 100000 files in a directory which are write-protected regular file, these files are quite old and would like to delete them completely, Kindly let me know the command or peice of code to automate the process. The filenames are like below MPNT_... (6 Replies)
Discussion started by: Hadoop_Master
6 Replies

8. Shell Programming and Scripting

Shell script to check a file and delete old files

Hello, I needed help with a shell script where in it checks if a file exists under a directory and also checks the age of the file and delete it if it is older than 3 weeks. thanks (10 Replies)
Discussion started by: hasn318
10 Replies

9. Shell Programming and Scripting

Shell Script to delete files from 5 different servers

Hello, I'm new to shell scripting and need a quick note on how to write a shell script to perform deletion of files from 5 different hostnames in various locations. Found out to delete files from one path by using below command and made it to work on cron job but need to do it in a shell... (2 Replies)
Discussion started by: Teja G
2 Replies

10. Shell Programming and Scripting

Shell script to delete the ip address from files

Hello, I am new to shell scripting, need help, my requirement is to delete the ip address from serveral files, please suggest (2 Replies)
Discussion started by: manoj.solaris
2 Replies
removeuser(8)						      System Manager's Manual						     removeuser(8)

NAME
removeuser - Deletes user accounts interactively SYNOPSIS
/usr/sbin/removeuser DESCRIPTION
Security Note If you have enhanced security installed on your system, you should use the dxaccounts command to remove users. See the Security manual and the dxaccounts(8) reference page for more information. The removeuser command is an interactive command for deleting user accounts from your system. It also gives the option of deleting the user's home directory, files and mail. The command prompts you for specific information and informs you of its activity and error condi- tions. The removeuser command invokes /usr/sbin/userdel to delete the user account information from /etc/passwd and the hashed password database (if present). Only the superuser can execute this command. The command performs the following tasks: Asks for a login name for the user to be deleted. Enter the login name. If this entry does not exist in the /etc/passwd file, the command informs you of this and exits. If the entry does exist, the command continues. Displays the entry for the user from the /etc/passwd file and asks if this is the entry you want to delete. If the answer to this query is no, the com- mand indicates that the user was not deleted and then exits. If the answer to this query is yes, the command deletes the user's entry from the /etc/passwd file and any occurrences of the user from the /etc/group file. It then states that the user was deleted. Searches several administrative directories and files for occurrences of the user and informs you if they exist. If so, it suggests that you may want to delete these occurrences when the command is finished. If no occurrences of the user are found in these directories and files, the command indicates so. Asks if you want to delete the home directory, all subdirectories, and all mail files for the user. If the answer to this query is no, the command indicates that the user's home directory was not deleted and then exits. If the answer to this query is yes, the command continues. As a precaution, the command reminds you that you should have backed up the files for the user before removing them if you do not want to lose them. It then asks if you are sure that you want to delete the files for this user. If the answer to this query is no, the command indicates that the user's home directory was not deleted and then exits. If the answer to this query is yes, the command states that it is removing the user's home directory, its contents and the user's mail file. It then deletes these items. At this point, the command ends. NOTES
Users are advised to migrate to the /usr/sbin/userdel utility or the dxaccounts utility as this command may be removed in a future version of the operating system. EXAMPLES
Enter a login name to be removed or <Return> to exit: john This is the entry for (john) in the /etc/passwd file: john:VSh6/xbMqPDcY:5006:15:sdf:/usr/users/john: Is this the entry you want to delete (y/n)? y Working ... Entry for (john) removed. Searching relevant directories and files for (john) ... None found. Do you want to remove the home directory, all subdirectories, files, and mail for (john) (y/n)? y The files for (john) will be lost if not backed up. Are you sure you want to remove these files (y/n)? y Deleting /usr/users/john Deleting /usr/spool/mail/john FILES
Specifies the command path Group file Password file SEE ALSO
Commands: addgroup(8), adduser(8), dxaccounts(8), finger(1), mkpasswd(8), passwd(1), useradd(8), userdel(8), vipw(8) Files: group(4), passwd(4) removeuser(8)
All times are GMT -4. The time now is 09:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy