Bash 파일 수정 일자 확인

When working with Bash scripts in Linux, it is often important to know when a file was last modified. This information can help you track changes, troubleshoot issues, or perform conditional operations based on file modification dates.

In this blog post, we will explore different ways to check the modification date of a Bash file in Linux.

Method 1: Using stat command

The stat command is a powerful tool that provides detailed information about files and directories. To check the modification date of a Bash file, you can use the following command:

stat -c%y /path/to/file.sh

This will display the file’s last modification date and time in the format YYYY-MM-DD HH:MM:SS.

Method 2: Using ls command

Another way to check the modification date of a Bash file is by using the ls command with the --time=modification (or simply -T) option:

ls -l --time=modification /path/to/file.sh

This will display the file’s detailed information along with the modification date and time.

Method 3: Using find command

If you need to check multiple files or search for files based on a specific modification date, the find command can be very handy. You can use the following command to find all Bash files modified within the last 7 days:

find /path/to/directory -name "*.sh" -mtime -7

This will search for all Bash files (*.sh) in the specified directory and list only those files that have been modified within the last 7 days.

Conclusion

Checking the modification date of Bash files in Linux can be easily done using the stat, ls, or find commands. Depending on your requirements, you can choose the method that suits your needs.

By knowing file modification dates, you can efficiently manage and track changes to your Bash scripts, ensuring that you stay organized and up-to-date with your codebase.