• About Us
  • Privacy & Policy
HowTo's
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
HowTo's
No Result
View All Result
Home Linux

Find Files Based on Last Access Time: Using -amin in find Command

August 21, 2024
in Linux, Linux Commands Examples, Linux Commands Tutorial, Linux Tutorial
A A
0
11
SHARES
100
VIEWS
Share on FacebookShare on Twitter

This post will cover topic related to find command particularly about ‘Find Files Based on Last Access Time: Using -amin in find Command’ with multiple find command examples and different find scenerios. So this find commandd article will help you to understand find command and options available in find command. End of the post, you will have better understanding of find command and how to use find command in better way.

The find command is a powerful tool for searching files and directories in Unix-like operating systems. When it comes to locating files based on their last access time, the -amin N option is particularly useful. This option allows users to find files that were last accessed exactly N minutes ago. This can be useful for managing files that have been recently used, checking for stale files, or performing system maintenance tasks. Below are several examples demonstrating how to use the -amin option with the find command.

Example 1: find /path/to/dir -amin 30
This command searches for files in the directory /path/to/dir that were last accessed exactly 30 minutes ago. If a file was accessed precisely 30 minutes prior, it will be listed in the output.

Example 2: find /var/log -amin -60
Here, the -amin -60 option finds files in the /var/log directory that have been accessed within the last 60 minutes. The minus sign before 60 indicates “less than,” so it retrieves files accessed within the last hour.

Example 3: find /home/user -amin +120
This command looks for files in the /home/user directory that were accessed more than 120 minutes ago. The plus sign before 120 indicates “more than,” so it lists files that haven’t been accessed in the last 2 hours.

Example 4: find /tmp -amin 15 -type f
With this command, only regular files (not directories or other types) in the /tmp directory that were accessed exactly 15 minutes ago are listed. The -type f option ensures only files are considered.

Example 5: find . -amin 5 -exec ls -l {} \;
This command finds files in the current directory (.) accessed exactly 5 minutes ago and then executes the ls -l command on each of those files. This provides a detailed listing of each file found.

Example 6: find /etc -amin -30 -print
This command locates files in the /etc directory that were accessed within the last 30 minutes and prints their paths. The -print option explicitly specifies that the file paths should be printed to the standard output.

Example 7: find /usr/local -amin +10 -size +1M
Here, files in the /usr/local directory accessed more than 10 minutes ago and larger than 1 megabyte are found. The -size +1M option specifies that only files larger than 1 MB are considered.

Example 8: find /var/cache -amin 45 -not -name "*.log"
This command searches for files in the /var/cache directory that were accessed exactly 45 minutes ago but excludes files with the “.log” extension. The -not -name "*.log" combination filters out log files.

Example 9: find /home/user/docs -amin -120 -print | grep "report"
In this example, the command finds files accessed within the last 120 minutes in the /home/user/docs directory and then filters the results to include only those whose paths contain the word “report”.

Example 10: find /mnt -amin +30 -exec du -h {} \;
This command finds files in the /mnt directory accessed more than 30 minutes ago and executes the du -h command on each, which reports the disk usage of each file in human-readable format.

Verification Steps:

1. Run the command in your terminal.

2. Check the output to see if the listed files match your criteria based on access time.

3. Verify file access times using the stat command to confirm they meet the expected times. For example, stat filename will display file attributes including the last access time.

Also check similar articles.

How -noignore_readdir_race Can Affect Your find Command Results
Avoid Race Conditions with -ignore_readdir_race in find Command
Improve find Accuracy with -noleaf to Avoid Issues with Hard Links
Limit Your Search to a Single Filesystem with -mount Option in find Command
How to Use -mindepth in find to Skip Initial Levels in Directory Searches

Tags: LinuxLinux Commands ExamplesLinux Commands TutorialLinux Tutorial
Previous Post

How -noignore_readdir_race Can Affect Your find Command Results

Next Post

Use -anewer to Find Files Newer Than a Specific File with find Command

Related You may like!

howto

How to Use -iname for Case-Insensitive Filename Searches in find

August 21, 2024
howto

Search for Files with Case-Insensitive Pattern Matching Using -ilname in find

August 21, 2024

Find Files by Group Name with -group in find Command

August 21, 2024

Locate Files by Group ID Using -gid in find Command

August 21, 2024

How to Search for Filesystems with -fstype in find Command

August 21, 2024

Use -false to Test Conditional Expressions in find Command

August 21, 2024
Next Post
howto

Use -anewer to Find Files Newer Than a Specific File with find Command

howto

How to Search for Files by Last Access Time Using -atime in find

howto

Find Files Changed Within Minutes Using -cmin Option in find Command

Discussion about this post

Latest Updated

howto

How to Use -iname for Case-Insensitive Filename Searches in find

August 21, 2024
howto

Search for Files with Case-Insensitive Pattern Matching Using -ilname in find

August 21, 2024
howto

Find Files by Group Name with -group in find Command

August 21, 2024
howto

Locate Files by Group ID Using -gid in find Command

August 21, 2024
howto

How to Search for Filesystems with -fstype in find Command

August 21, 2024

Trending in Week

  • howto

    Using BTRFS Subvolume for User Home Directory in Linux

    22 shares
    Share 9 Tweet 6
  • Downloading Docker Images from a Registry

    13 shares
    Share 5 Tweet 3
  • Configuring SSL Connection Mode in mysqldump

    17 shares
    Share 7 Tweet 4
  • Omit Tablespace Information in mysqldump Output

    13 shares
    Share 5 Tweet 3
  • Setting MySQL Dump Compatibility Mode

    18 shares
    Share 7 Tweet 5
  • Setting Network Buffer Length in mysqldump

    13 shares
    Share 5 Tweet 3
  • Logging out from Docker Registries

    13 shares
    Share 5 Tweet 3
  • Scheduling Nodes in Kubernetes with kubectl uncordon

    12 shares
    Share 5 Tweet 3
  • Managing Default User Creation Settings in Linux

    15 shares
    Share 6 Tweet 4
  • Using Extended INSERT Syntax in mysqldump

    12 shares
    Share 5 Tweet 3
  • About Us
  • Privacy & Policy

© 2024 All Rights Reserved. Howto.swebtools.com.

No Result
View All Result

© 2024 All Rights Reserved. Howto.swebtools.com.