Determining File Size and Modification Time
As discussed in the previous sections, the ls -l
command provides valuable information about the files and directories in your Linux system, including the file size and modification time. Let's explore how to use this command to determine these file attributes.
Viewing File Size
To view the size of a file, you can use the ls -l
command. The file size is displayed in the fifth column of the output:
$ ls -l example.txt
-rw-r--r-- 1 user group 1024 Apr 15 12:34 example.txt
In this example, the file size of example.txt
is 1024 bytes.
If you prefer to see the file size in a more human-readable format (e.g., KB, MB, GB), you can use the -h
option:
$ ls -lh example.txt
-rw-r--r-- 1 user group 1.0K Apr 15 12:34 example.txt
Now the file size is displayed as 1.0K, which represents 1024 bytes.
Determining Modification Time
The modification time of a file is also displayed in the ls -l
output, in the sixth and seventh columns:
$ ls -l example.txt
-rw-r--r-- 1 user group 1024 Apr 15 12:34 example.txt
In this example, the modification time of example.txt
is April 15 at 12:34.
If you need to sort the files based on their modification time, you can use the -t
option:
$ ls -lt
-rw-r--r-- 1 user group 1024 Apr 15 12:34 example.txt
drwxr-xr-x 2 user group 4096 Apr 16 15:22 documents
This will list the files in the current directory sorted by modification time, with the most recently modified file first.
By understanding how to use the ls -l
command to determine file size and modification time, you can effectively manage and interact with files and directories in your Linux system.