In this article, we will explain two, simple command line tips that enable you to only list all today’s files.
One of the common problems Linux users encounter on the command line is locating files with a particular name, it can be much easier when you actually know the filename.
However, assuming that you have forgotten the name of a file that you created (in your
home
folder which contains hundreds of files) at an earlier time during the day and yet you need to use urgently.
Below are different ways of only listing all files that you created or modified (directly or indirectly) today.
1. Using the ls command, you can only list today’s files in your home folder as follows, where:
-a
– list all files including hidden files-l
– enables long listing format--time-style=FORMAT
– shows time in the specified FORMAT+%D
– show/use date in %m/%d/%y format
In addition, you can sort the resultant list alphabetically by including the
-X
flag:
You can also list based on size (largest first) using the
-S
flag:
2. Again, it is possible to use the find command which is practically more flexible and offers plenty of options than ls, for the same purpose as below.
-maxdepth
level is used to specify the level (in terms of sub-directories) below the starting point (current directory in this case) to which the search operation will be carried out.-newerXY
, this works if timestamp X of the file in question is newer than timestamp Y of the file reference. X and Y represent any of the letters below:- a – access time of the file reference
- B – birth time of the file reference
- c – inode status change time of reference
- m – modification time of the file reference
- t – reference is interpreted directly as a time
No comments:
Post a Comment