The find utility can not by itself distinguish between a "shell script", "JPEG image file" or any other type of regular file. These are the type of files that find can filter on with its -type option. Resources: Banner images from Office illustrations by Storyset and Canva."File types" on a Unix system are things like regular files, directories, named pipes, character special files, symbolic links etc. In this article, we have studied the find command in detail and learned how to search files by name, type, size and modification time. The shared script is very useful in archiving and removing logs. As we do not want the shell to interpret the semicolon, we escape it with \. # Script to move from logs older than 7 days to backup logs path: /app/backup_logs/ESB0*įind /logs/esb01/audit -name "*.tar.gz" -mtime 7 -exec mv is the placeholder which holds the results of the command. We can create a script and schedule it with cron. From there, it deletes log files older that older than 30 days. Let's say we want to create a script that moves log files older than 7 days to a backup path. We can combine find with rm or mv to create meaningful bash scripts that can be automated. Practical examples of find with bash scripts type f -name ".*" -mtime 10 Here we have files that were modified more than 10 days ago. Let's apply an example in my home directory.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |