Home > Article > System Tutorial > Master Linux file dates - make your file management more efficient
In daily file management, we will inevitably encounter situations where we need to check file creation time, modification time, access time and other information. For Linux systems, mastering file dates is very important for file management and maintenance. This article will introduce common file date types in Linux systems and how to use commands to view and modify them.
Sometimes you may need to check details about a file, such as the file's modification date. This article may come in handy when you want to check when a file was last edited. In this article, you will learn 4 ways to check the modification date of a file.
Use stat command
The stat command can display detailed information about file attributes, such as the time when the file was last accessed and modified, file size and other information. It is relatively simple to use. You only need to add the file name after the command:
[root@localhost ~]# stat hello_script.sh File: ‘hello_script.sh’ Size: 31 Blocks: 8 IO Block: 4096 regular file Device: fd00h/64768d Inode: 67169379 Links: 1 Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2020-10-15 19:13:24.628009932 +0800 Modify: 2020-10-15 19:07:18.266426499 +0800 Change: 2020-10-15 19:11:48.227856412 +0800 Birth: -
From the above output, we can see the access date of the file, the modification date of the file, the modification date of the file permissions, and other parameters.
If you only want to see the modification date of a file, regardless of all other information, run the following command:
[root@localhost ~]# stat -c %y hello_script.sh 2020-10-15 19:07:18.266426499 +0800The
-c
option is used to specify a custom format instead of the default output, and the '%y' flag displays the last modification time. For folders, the syntax remains the same. Just replace the file name with the folder name.
Use date command
The usage ofdate command is to display the current date. But when used with the -r
option, the last modified date of the file can be displayed as follows:
[root@localhost ~]# date -r hello_script.sh Thu Oct 15 19:07:18 CST 2020
Use ls -l command
Thels -l
command is typically used to display additional information about a file using a long list, such as file permissions and owners, size, and creation date. You can add the -t option
so that the files can be sorted according to their modification time:
[root@localhost ~]# ls -lt 或者 [root@localhost ~]# ll -t total 288 drwxr-xr-x. 2 root root 177 Oct 16 14:36 b drwxr-xr-x. 2 root root 177 Oct 16 14:36 a -rwxr-xr-x. 1 root root 119 Oct 15 19:20 backup_script.sh -rwxr-xr-x. 1 root root 31 Oct 15 19:07 hello_script.sh -rw-r--r--. 1 root root 227 Oct 13 16:39 content.txt -rw-r--r--. 1 root root 277159 Oct 12 14:37 a.txt drwxr-xr-x. 2 root root 195 Aug 6 14:12 Files -rw-------. 1 root root 1284 Dec 29 2019 anaconda-ks.cfg
Use httpie tool
Another way to check the modification date of a file is to use httpie, which is an HTTP command line client tool. This tool is commonly used to interact with HTTP servers and APIs and can also check the modification time of files residing on web servers.
First you need to ensure that python’s pip package management tool is installed, and then install the httpie tool:
In Centos7/RHEL7, run the following command to install httpie:
[root@localhost ~]# yum -y install python-pip [root@localhost ~]# pip install --upgrade pip [root@localhost ~]# pip install httpie
Run the following command to install httpie in Ubuntu/Deepin/Debian:
$ sudo apt install httpie
After the installation is completed, how to check the modification time of the files on the web server? The syntax is as follows:
http -h [url] | grep 'Last-Modified'
For example, from the www.linuxprobe.com website, view the modification time of a picture in .png format:
[root@localhost ~]# http -h https://pic1.imgdb.cn/item/644d3ca70d2dde5777f6041c.png | grep -i 'Last-Modified' Last-Modified: Fri, 05 Jun 2020 14:26:11 GMT
Through the introduction of this article, we not only understand the common file date types in Linux systems, but also learn how to use commands to view and modify them. These techniques not only allow us to manage and maintain files more efficiently, but also meet some special needs, such as finding files modified within a certain time period. Whether you are a system administrator or a developer, mastering Linux file date technology is essential.
The above is the detailed content of Master Linux file dates - make your file management more efficient. For more information, please follow other related articles on the PHP Chinese website!