delete – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Thu, 24 Nov 2022 10:21:07 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How to Delete a Let’s Encrypt Certificate using Certbot https://tecadmin.net/delete-lets-encrypt-certificates-using-certbot/ https://tecadmin.net/delete-lets-encrypt-certificates-using-certbot/#comments Thu, 02 Jun 2022 08:50:48 +0000 https://tecadmin.net/?p=29573 Certbot is a free and open-source software tool used for managing the Let’s Encrypt certificates. This tool allows users to issue certificates in a single command and also configure the web servers. The default certbot stores all the client certificates under the below-mentioned directories. We are not recommending you delete files manually. In this tutorial, [...]

The post How to Delete a Let’s Encrypt Certificate using Certbot appeared first on TecAdmin.

]]>
Certbot is a free and open-source software tool used for managing the Let’s Encrypt certificates. This tool allows users to issue certificates in a single command and also configure the web servers.

The default certbot stores all the client certificates under the below-mentioned directories. We are not recommending you delete files manually. In this tutorial, we will discuss deleting unused SSL certificates using the Certbot command line.

  • /etc/letsencrypt/live
  • /etc/letsencrypt/renewal
  • /etc/letsencrypt/archive

Delete a Let’s Encrypt SSL Certificate

The Certbot also provides you an option to delete certificates automatically for you. To delete an SSL certificate, run the following command.

sudo certbot delete 

This command will show you an index from which you can select the domain name to delete the associated certificate. Just type the index number of the domain name, that you want to delete and hit enter. The issued certificate including other associated files will be deleted.

Deleting Let's Encrypt Certificate using Certbot
Deleting Let’s Encrypt certificate using certbot

You can also specify the domain name with the certbot command as below. This could be helpful if the domain name does not appear in the index list.

sudo certbot delete --cert-name example.com

That’s it.

Conclusion

This tutorial helped you to delete a Let’s Encrypt SSL certificate using certbot command-line tool.

The post How to Delete a Let’s Encrypt Certificate using Certbot appeared first on TecAdmin.

]]>
https://tecadmin.net/delete-lets-encrypt-certificates-using-certbot/feed/ 3
How to Delete a Line Containing Specific String using SED https://tecadmin.net/delete-a-line-containing-specific-string-using-sed/ https://tecadmin.net/delete-a-line-containing-specific-string-using-sed/#comments Sat, 10 Jan 2015 10:25:47 +0000 https://tecadmin.net/?p=6910 Syntax: sed -i '/string_to_delete/d' /path/to/file SED is a Stream Editor having the capability to remove lines from files containing a specific string. Using -i with sed we can remove lines in the same file. Example 1: Remove all lines from /var/log/messages containing the string “DELETE THIS TEXT” and restore output in a new file. Do [...]

The post How to Delete a Line Containing Specific String using SED appeared first on TecAdmin.

]]>
Syntax:
sed -i '/string_to_delete/d' /path/to/file

SED is a Stream Editor having the capability to remove lines from files containing a specific string. Using -i with sed we can remove lines in the same file.

Example 1:

Remove all lines from /var/log/messages containing the string “DELETE THIS TEXT” and restore output in a new file. Do not make any changes to the original line.

$ sed "/DELETE THIS TEXT/d" /var/log/messages > messages.txt

Example 2:

Remove all lines from /var/log/messages containing the string “DELETE THIS TEXT” in the same file.

$ sed -i "/DELETE THIS TEXT/d" /var/log/messages

The post How to Delete a Line Containing Specific String using SED appeared first on TecAdmin.

]]>
https://tecadmin.net/delete-a-line-containing-specific-string-using-sed/feed/ 2
How to Delete Files Older than 30 days in Linux https://tecadmin.net/delete-files-older-x-days/ https://tecadmin.net/delete-files-older-x-days/#comments Mon, 05 Aug 2013 06:35:15 +0000 https://tecadmin.net/?p=2450 Regularly cleaning out old unused files from your server is the best practice. For example, if we are running a daily/hourly backup of files or databases on the server then there will be much junk created on the server. So clean it regularly. To do it you can find older files from the backup directory [...]

The post How to Delete Files Older than 30 days in Linux appeared first on TecAdmin.

]]>
Regularly cleaning out old unused files from your server is the best practice. For example, if we are running a daily/hourly backup of files or databases on the server then there will be much junk created on the server. So clean it regularly. To do it you can find older files from the backup directory and clean them.

This article describes you to how to find and delete files older than 30 days. Here 30 days older means the last modification date is before 30 days.

1. Delete Files older Than 30 Days

Using the find command, you can search for and delete all files that have been modified more than X days. Also, if required you can delete them with a single command.

First of all, list all files older than 30 days under /opt/backup directory.

find /opt/backup -type f -mtime +30 

Verify the file list and make sure no useful file is listed in the above command. Once confirmed, you are good to go to delete those files with the following command.

find /opt/backup -type f -mtime +30 -delete 

2. Delete Files with Specific Extension

You can also specify more filters to locate commands rather than deleting all files. For example, you can only delete files with the “.log” extension and modified before 30 days.

For the safe side, first, do a dry run and list files matching the criteria.

find /var/log -name "*.log" -type f -mtime +30 

Once the list is verified, delete those files by running the following command:

find /var/log -name "*.log" -type f -mtime +30 -delete 

The above command will delete only files with a .log extension and with the last modification date older than 30 days.

3. Delete Old Directory Recursively

The -delete option may fail if the directory is not empty. In that case, we will use the Linux rm command with find to accomplish the deletion.

Searching all the directories under /var/log modified before 90 days using the command below.

find /var/log -type d -mtime +90 

Here we can execute the rm command using -exec command line option. Find command output will be sent to rm command as input.

find /var/log -type d -mtime +30 -exec rm -rf {} \; 
WARNING: Before removing the directory, Make sure no user directory is being deleted. Sometimes parent directory modification dates can be older than child directories. In that case, recursive delete can remove the child directory as well.

Conclusion

You have learned how to find and delete files in the Linux command line that have been modified more than a specified number of days ago. That will help you clean up your system from unwanted files.

The post How to Delete Files Older than 30 days in Linux appeared first on TecAdmin.

]]>
https://tecadmin.net/delete-files-older-x-days/feed/ 15