Linux ls order by date

Содержание
  1. Как сортировать файлы по дате с помощью команды LS в Linux
  2. 1) Каталог файлов c последней измененной датой / временем
  3. 2) Список файлов с последней измененной датой / временем (последнее внизу)
  4. 3) Отображение в удобном формате
  5. 4) Найти файлы, измененные за последние 10 минут
  6. 5) Недавно измененные 10 файлов
  7. How to Sort Output of ‘ls’ Command By Last Modified Date and Time
  8. Linux Basic ls Commands
  9. Sort Files Based on Time and Date
  10. If You Appreciate What We Do Here On TecMint, You Should Consider:
  11. How to Sort Files by Date Using LS command in Linux
  12. 1) List Files directory with Last Modified Date/Time
  13. 2) List Files with Last Modified Date/Time (most recent at bottom)
  14. 3) Display in Human Readable format
  15. 4) Find files modified in Last 10 minutes
  16. 5) Recently modified 10 files
  17. Linux / Unix: Sort ls Command Output By Last Modified Date and Time
  18. Syntax
  19. Sort by modification time, newest first and other options
  20. How to Find and Sort Files Based on Modification Date and Time in Linux
  21. Linux Utilities to Sort Files in Linux
  22. ls command
  23. sort command
  24. Some Ways to Sort Files using Date and Time
  25. 1. List Files Based on Modification Time
  26. 2. List Files Based on Last Access Time
  27. 3. List Files Based on Last Modification Time
  28. 4. Sorting Files based on Month
  29. 5. Sort Files Based on Date
  30. 6. Sorting Files Based on Time
  31. 7. Sorting Ouptut of ls -l based on Date
  32. Conclusion
  33. If You Appreciate What We Do Here On TecMint, You Should Consider:

Как сортировать файлы по дате с помощью команды LS в Linux

Команда ls используется для отображения содержимого каталога, и результаты могут быть отсортированы по нескольким критериям, например по дате, алфавитному порядку имен файлов, времени модификации, времени доступа, версии и размера файла.

В этой статье я покажу вам, как сортировать файлы по дате с помощью команды ls в Linux.

1) Каталог файлов c последней измененной датой / временем

Чтобы просмотреть файлы и отобразить последние измененные файлы сверху, мы будем использовать опции -lt с командой ls.

2) Список файлов с последней измененной датой / временем (последнее внизу)

Мы будем использовать опции -ltr с командой ls для отображения файлов определенного каталога с недавно измененными файлами внизу.

Если вы хотите отсортировать по каталогу, по датам используйте

3) Отображение в удобном формате

Мы будем использовать опции -halt с помощью команды ls для отображения файлов определенного каталога в форматах для чтения

Он использует суффиксы K, M, G и T (или без суффикса для байтов)

4) Найти файлы, измененные за последние 10 минут

Мы можем получить файлы, измененные за последние 10 минут командой ниже:

5) Недавно измененные 10 файлов

Посмотрите, как проверить недавно измененные 10 файлов в каталоге с помощью команд ls.

Мы будем использовать комбинацию команд «ls» и «head».

Ниже команда покажет измененные 10 файлов с недавно обновленным файлом вверху

с комбинацией tail, он показывает недавно обновленный файл внизу.

Спасибо, что прочитали эту статью и, пожалуйста, прокомментируйте ниже, если вы найдете какие-либо другие варианты полезными.

Источник

How to Sort Output of ‘ls’ Command By Last Modified Date and Time

One of the commonest things a Linux user will always do on the command line is listing the contents of a directory. As we may already know, ls and dir are the two commands available on Linux for listing directory content, with the former being more popular and in most cases, preferred by users.

When listing directory contents, the results can be sorted based on several criteria such as alphabetical order of filenames, modification time, access time, version and file size. Sorting using each of these file properties can be enabled by using a specific flag.

In this brief ls command guide, we will look at how to sort the output of ls command by last modification time (date and time).

Let us start by executing some basic ls commands.

Linux Basic ls Commands

1. Running ls command without appending any argument will list current working directory contents.

List Content of Working Directory

2. To list contents of any directory, for example /etc directory use:

List Contents of Directory

3. A directory always contains a few hidden files (at least two), therefore, to show all files in a directory, use the -a or —all flag:

List Hidden Files in Directory

4. You can as well print detailed information about each file in the ls output, such as the file permissions, number of links, owner’s name and group owner, file size, time of last modification and the file/directory name.

Читайте также:  Windows 10 чистка appdata

This is activated by the -l option, which means a long listing format as in the next screenshot:

Long List Directory Contents

Sort Files Based on Time and Date

5. To list files in a directory and sort them last modified date and time, make use of the -t option as in the command below:

Sort ls Output by Date and Time

6. If you want a reverse sorting files based on date and time, you can use the -r option to work like so:

Sort ls Output Reverse by Date and Time

We will end here for now, however, there is more usage information and options in the ls command, so make it a point to look through it or any other guides offering ls command tricks every Linux user should know or use sort command. Last but not least, you can reach us via the feedback section below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

How to Sort Files by Date Using LS command in Linux

The ls command is used to list directory contents and the results can be sorted upon several criteria such as by date, alphabetical order of filenames, modification time, access time, version and file size.

In this article, I will show you how to sort files by date using ls command in Linux.

1) List Files directory with Last Modified Date/Time

To list files and shows the last modified files at top, we will use -lt options with ls command.

2) List Files with Last Modified Date/Time (most recent at bottom)

We will use -ltr options with ls command to list files of a specific directory with recently modified files at the bottom.

If you want to sort by directory, then by dates use

3) Display in Human Readable format

We will use -halt options with ls command to list files of a specific directory in human readable file sizes, long format. It uses K, M, G, and T suffixes (or no suffix for bytes)

4) Find files modified in Last 10 minutes

We can get files modified in last 10 minutes with command below:

5) Recently modified 10 files

Let see how to check recently modified 10 files in a directory using ls commands. We will use a combination of ‘ls» and ‘head’ command.

Below command will show modified 10 files with the recently updated file at the top

with tail combination, it shows recently updated file at the bottom.

Thanks for reading this article and please comment below if you find any other options useful.

Источник

Linux / Unix: Sort ls Command Output By Last Modified Date and Time

/Downloads/ folder in Ubuntu Linux and OS X desktop. How do I show last downloaded file first using the ls command? How do I sort the output of ls command by last modified date?

You need to pass the -t option to the ls command. The -t option sort by time modified i.e. most recently modified first before sorting the operands by lexicographical order.

Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time 1m

In other words, last downloaded file can be displayed using the following command. Open the Terminal application and type the following command.

Syntax

The syntax is:
ls -t
ls -lt | less
ls -lt

/Downloads/ | less
Sample outputs:

Pass the -r option to reverse the order of the sort to get reverse lexicographical order or the oldest entries first (or largest files last, if combined with sort by size), enter:
ls -tr
ls -ltr | less
ls -ltr

/Downloads/ | less
Sample outputs:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Sort by modification time, newest first and other options

Make sure you pass the -A (list all entries except for . and ..) or -a (include directory entries whose names begin with a dot) option to see hidden files:
ls -Altr

/Downloads/ | less
ls -alt

/Downloads/ | less
The following option turned on human readable output:
$ ls -halt
$ ls -halt | more
Sample outputs:

Fig.01: Print human readable sizes when used with the -l/-s option

Recommended readings
  • See the ls command man page for more information.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

This will the most recently modified files (and other file system objects) first. You may want to add a -l switch for details on the files. Pipe the output through `tac` to reverse the order. Select the newest (oldest) files by piping the output through `head`. Example:

ls -lt | head -n 3 # displays the three most recently modified files.

Источник

How to Find and Sort Files Based on Modification Date and Time in Linux

Usually, we are in habit of saving a lot of information in form of files on our system. Some, hidden files, some kept in a separate folder created for our ease of understanding, while some as it is. But, this whole stuff fills our directories; usually desktop, making it look like a mess. But, the problem arises when we need to search for a particular file modified on particular date and time in this huge collection.

Find and Sort Files by Date and Time in Linux

People comfortable with GUI’s can find it using File Manager, which lists files in long listing format, making it easy to figure out what we wanted, but those users having habit of black screens, or even anyone working on servers which are devoid of GUI’s would want a simple command or set of commands that could ease out their search.

Real beauty of Linux shows here, as Linux has a collection of commands which if used separately or together can help to search for a file, or sort a collection of files according to their name, date of modification, time of creation, or even any filter you could think of applying to get your result.

Here, we will unveil the real strength of Linux by examining a set of commands which can help sorting a file or even a list of files by Date and Time.

Linux Utilities to Sort Files in Linux

Some basic Linux command line utilities that are just sufficient for sorting a directory based on Date and Time are:

ls command

ls – Listing contents of directory, this utility can list the files and directories and can even list all the status information about them including: date and time of modification or access, permissions, size, owner, group etc.

We’ve already covered many articles on Linux ls command and sort command, you can find them below:

sort command

sort – This command can be used to sort the output of any search just by any field or any particular column of the field.

We’ve already covered two articles on Linux sort command, you can find them below:

These commands are in themselves very powerful commands to master if you work on black screens and have to deal with lots of files, just to get the one you want.

Some Ways to Sort Files using Date and Time

Below are the list of commands to sort based on Date and Time.

1. List Files Based on Modification Time

The below command lists files in long listing format, and sorts files based on modification time, newest first. To sort in reverse order, use ‘-r’ switch with this command.

2. List Files Based on Last Access Time

Listing of files in directory based on last access time, i.e. based on time the file was last accessed, not modified.

3. List Files Based on Last Modification Time

Listing of files in directory based on last modification time of file’s status information, or the ‘ctime’ . This command would list that file first whose any status information like: owner, group, permissions, size etc has been recently changed.

If ‘-a’ switch is used with above commands, they can list and sort even the hidden files in current directory, and ‘-r’ switch lists the output in reverse order.

For more in-depth sorting, like sorting on Output of find command, however ls can also be used, but there ‘sort’ proves more helpful as the output may not have only file name but any fields desired by user.

Below commands show usage of sort with find command to sort the list of files based on Date and Time.

To learn more about find command, follow this link: 35 Practical Examples of ‘find’ Command in Linux

4. Sorting Files based on Month

Here, we use find command to find all files in root (‘/’) directory and then print the result as: Month in which file was accessed and then filename. Of that complete result, here we list out top 11 entries.

The below command sorts the output using key as first field, specified by ‘-k1’ and then it sorts on Month as specified by ‘M’ ahead of it.

5. Sort Files Based on Date

Here, again we use find command to find all the files in root directory, but now we will print the result as: last date the file was accessed, last time the file was accessed and then filename. Of that we take out top 11 entries.

The below sort command first sorts on basis of last digit of the year, then sorts on basis of last digit of month in reverse order and finally sorts on basis of first field. Here, ‘1.8‘ means 8th column of first field and ‘n’ ahead of it means numerical sort, while ‘r’ indicates reverse order sorting.

6. Sorting Files Based on Time

Here, again we use find command to list out top 11 files in root directory and print the result in format: last time file was accessed and then filename.

The below command sorts the output based on first column of the first field of the output which is first digit of hour.

7. Sorting Ouptut of ls -l based on Date

This command sorts the output of ‘ls -l’ command based on 6th field month wise, then based on 7th field which is date, numerically.

Conclusion

Likewise, by having some knowledge of sort command, you can sort almost any listing based on any field and even its any column you desire. These were some of tricks to help you sort files based on Date or Time. You can have your own tricks build based on these. However, if you have any other interesting trick, you can always mention that in your comments.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

Читайте также:  Как написать свой плеер для windows
Оцените статью