The ls command is one of the most frequently used Linux commands. It allows users to list information about files and directories within a file system. The ls -lrt command is an extension of this, providing more control over the type and order of output displayed.
Also read: How to Use ls Command in Linux/Unix
What is the ls -ltr command
The ‘ls -lrt’ command stands for “list in long format, reverse sorted by modification time”. This means that it will provide detailed information about each file or directory, as well as sort them in reverse order based on their last modified date/time stamp.
This particular variant of the ‘ls’ command provides a useful way to quickly view recently created or modified files within a directory structure without having to manually sort through everything else present. It can also be used to identify which files are taking up too much storage space when disk quotas are enabled on certain systems.
Breakdown of the Command
Here’s what each argument (flag) included with this particular variant of the ‘ls’ command does:
- -l: Long list format – Displays additional details such as file size, modified date/time stamp, etc., for each item listed
- -r: Reverse order while sorting – Sorts items in reverse alphabetical/numerical order
- -t: Sort by modification time – Orders items based on their last-modified timestamp
Examples of Usage
Here are some examples of how the ‘ls -lrt’ command can be used on Linux systems:
1. To list all files and subdirectories within the current working directory, sorted by modification time in reverse order:
ls -lrt
2. To list all files and subdirectories in a specific directory, sorted by modification time in reverse order:
ls -lrt /path/to/directory
3. To list all regular files (not directories) within the current working directory, sorted by modified date/time stamp in reverse order:
ls -ltr | grep ^-
Various Arguments of ls Command Explained
- ls path – This command will list information about the specified path.
- ls / – This command will list all items within the root directory (/).
- ls .. – This command will list information about the parent directory relative to your current working location.
- ls ~ – This command will list all items present in your home directory (~).
- ls -R – This command will recursively display any subdirectories within the specified path in addition to their respective contents.
- ls -A – This command will display hidden files and directories (those whose names begin with a dot ‘ . ’) along with other visible ones.
- ls -C – This command will sort output by filename instead of modification date/time stamp, making it easier to locate specific entries if you know their name but not when they were created or modified lastly.
- ls-d – This command will only display directories instead of both directories and regular files present at a given location (useful for quickly navigating around a file system). But using it alone would yeild not so useful outputs but it is quite useful when used with */ operator to list only directories.
- ls -F –This command adds an extra character at the end of each entry to indicate its type; for example ‘ / ’ is added after any directory name while ‘ * ’ is added after executables etc., making it easier to differentiate between different types of entries at a glance without having to open them or use other tools such as ‘file’ .
- ls -lrta – This command will display all entries in long format, sorted by modification date/time stamp in reverse order while also including hidden files and directories.
- ls -lrtS – This command is similar to the above but sorts output based on file size instead of modification date/time.
- ls -rltuR – This command will recursively list all subdirectories within a given path and sort output by modification time in reverse order.
- ls -F – This command is a combination of the ‘ls -F’ and ‘ls -l’ commands; it displays detailed information about each entry along with an extra character at the end indicating its type.
Summary
The ‘ls -lrt’ command is an extension of the ‘ls’ command which provides users with more control over the type and order of output displayed. By including additional arguments such as ‘-l’, ‘-r’, and ‘-t’, users can quickly view recently created or modified files within a directory structure without having to manually sort through everything else present, making this particular variant of the ‘ls’ command very useful for tasks such as identifying large files or quickly navigating around a file system.