Bash 파일 생성 일자 확인

When working with Bash scripts in Linux, it is often useful to determine the creation date of a file. Here’s a quick guide on how to achieve this using various commands and techniques in Bash.

Using ls command

The ls command, by default, displays the modification date and time of files. However, you can use the -l option to display additional information including the creation date. Here’s an example:

ls -l --time=creation <filename>

Replace <filename> with the name of the file you want to check. This command will output the file details, including the creation date and time.

Using stat command

The stat command provides detailed information about files, including the creation date. You can use it to get the creation date of a file. Here’s an example:

stat -c %w <filename>

Replace <filename> with the name of the file you want to check. The %w option specifies the output format to display the creation date and time.

Using ls -lt command

If you have a directory and want to list files sorted by creation date, you can combine the ls and sort commands like this:

ls -lt <directory> | head -n 10

Replace <directory> with the name of the directory you want to check. The command above will list the 10 most recently created files in the directory.

Using find command

The find command is useful for searching files based on various criteria, including the creation date. Here’s an example of how to find files created in the last 7 days:

find <directory> -type f -ctime -7

Replace <directory> with the name of the directory you want to search. The command will find files within the specified directory that were created in the last 7 days.

Conclusion

By using the commands mentioned above, you can easily determine the creation date of a file in a Bash script or when working with the command line in Linux. Whether you need this information for troubleshooting or organization purposes, these commands will help you effectively retrieve the required information.