Raspberry Pi

How to Find File Creation Time in Raspberry Pi from Command Line Terminal

File creation time is a specific time and date when a particular file is created or copied or moved to a destination in the system; sometimes users may create important files for which they require the file creation time to get the file information. Just like other Linux-based systems, in Raspberry Pi, the file creation time can be found using the command line.

In this article, the methods to find file creation time in Raspberry Pi by using the command lines are discussed.

How to Find File Creation Time in Raspberry Pi from Command Line Terminal

There are two methods to find the file creation time and date on the Raspberry Pi terminal:

I will explain each of these methods with an example. For instance, I want to find the creation time of a file “myfile.txt” which is present in the Documents directory.

Method 1: Using the ls Command

The first method is finding the file creation time by using the list command, which is one of the most used commands in Raspberry Pi. Now let’s find out the creation time of “myfile.txt” using the list command.

Since the desired file is in the Documents directory, so I will change the directory to the Documents by using the below-mentioned command:

cd Documents

You can do the same for your desired file by just replacing the Documents directory with the destination directory of your file.

Then by using the below-mentioned ls command the list of all the files present inside the Documents directory will display along with their creation time and date:

ls -l


I had very few files in my Documents directory due to which the above command worked fine for me, but if you have a lot of files in your directory and you do not want to display the entire list of files then you can use the below-mentioned command to specifically find the creation time of the desired file:

ls -l <file-name>

In my case, I have run the below-mentioned command and in the output, you can see that the creation time of “myfile.txt” is displayed:

ls -l myfile.txt

Method 2: Using the stat Command

The second method to find the creation time of a file in Raspberry Pi is by using the “stat” command. The advantage of using this command is that it gives more detailed time information. Let’s use this to find the creation time for “myfile.txt”.

Just as we did in the previous method, changing the directory to Documents because “myfile.txt” is present there:

cd Documents

After that run the below-mentioned stat command to find file creation time using stat, the “%w” specifier is used to get the output of stat command in a more human-readable form:

stat -c '%w' <file-name>

For example; to find the creation time of my desired file “myfile.txt” I have run the below-written command, and in the output, you can see more detailed information about the file creation time and date is displayed:

stat -c '%w' myfile.txt

Note: The output displays creation date by following the syntax [Year-Month-Day] and creation time as [Hours: Minutes: Seconds].

Conclusion

To find the file creation time in Raspberry Pi, two commands are used: the “ls” command and the “stat” command. The ls is one of the most used commands in Raspberry Pi to list the files along with their creation time. But the stat command provides more detailed information about the creation time of a file in Raspberry pi.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.