Commander linux date modification fichier

Change modification date to filename

I’ve got a number of files of which I want to change the modification date in linux. The modification date is saved in the filename.

So I’ve got files, whose name is for example «IMG_20180101_010101.jpg», but the modification date is today. I want to change the modification date to 2018-01-01 01:01:01, as in the filename. I’ve tried with find and touch:

When I do this I always get an error («invalid date format: ).

What am I doing wrong?

2 Answers 2

If you want to set the file timestamp according to the filename, you can try this:

As mentionned in the touch man page, the option -t expects a format [[CC]YY]MMDDhhmm[.ss] . That’s the purpose of the sed command.

If I understood good, you would like to write the file names in your own format. What about this script:

Not the answer you’re looking for? Browse other questions tagged linux bash touch or ask your own question.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.10.8.40416

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Linux Find Files By Date And List Files Modified On a Specific Date

H ow do I find files by date under UNIX and Linux system? How search for files that created on a specific date on Linux or Unix-like system? How to get a list all files that have been modified on a specific date on Linux or Unix?

Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux or Unix
Est. reading time 4 mintues

Linux and UNIX like operating systems do not store file creation time. However, you can use file access and modification time and date to find out file by date. For example, one can list all files that have been modified on a specific date.

Let us see how to find file by date on Linux. You need to use the ls command and find command.

ls command example to find files by date

The syntax is as follows:

You need to use the grep command/egrep command to filter out info:
$ ls -lt /etc/ | grep filename
ls -lt /etc/ | grep ‘Jun 20’
A better and recommended solution is the find command:
find . -type f -ls |grep ‘2017’
find . -type f -ls |grep ‘filename’
find /etc/ -type f -ls |grep ’25 Sep’

find Command Example

If you need a specific date range many days ago, than consider using the find command. In this example find files modified between Jan/1/2007 and Jan/1/2008, in /data/images directory:

You can save list to a text file called output.txt as follows:
find /data/images -type f -newer /tmp/start -not -newer /tmp/end > output.txt

Linux find file by date using the date command

Gnu find as various command line option to list files by a modification and access date/time stamp.

Say hello to -newerXY option for find command

The syntax is as follows:
find /dir/ -type f -newerXY ‘yyyy-mm-dd’
find /dir/ -type f -newerXY ‘yyyy-mm-dd’ -ls
The letters X and Y can be any of the following letters:

  1. a – The access time of the file reference
  2. B – The birth time of the file reference
  3. c – The inode status change time of reference
  4. m – The modification time of the file reference
  5. t – reference is interpreted directly as a time

To see all files modified on the 24/Sep/2017 in the current directory:

find . -type f -newermt 2017-09-24
## pass the -ls option to list files in ls -l format ##
find . -type f -newermt 2017-09-24 -ls

OR
find . -type f -newermt 2017-09-24 ! -newermt 2017-09-25
find . -type f -newermt 2017-09-24 ! -newermt 2017-09-25 -ls
Sample outputs:

Источник

How can I change the date modified of a folder to the last changed file inside? [duplicate]

In my media center directory all modified times of my folders are somehow not the desired date.

How can I change all modified times of the main folders to the modified time of the newest media-file inside each folder?

but that gives out:

3 Answers 3

If you want to consider files in subdirectories as well:

And if you want to do it for every non-empty directory, recursively:

Beware that you’ll get «no matches found» errors if there are non-empty directories without regular files (if all the files they contain are non-regular such as directories, symlinks, fifos. ). To avoid that, you could change it to:

Remove the . glob qualifier if you don’t want to restrict to regular files, or prefix with — if you also want to consider symlinks to regular files (and the modification time of the file they point to), or replace with ^/ for non-directory files, or ^/,F for any type of file except empty directories (non-directories or F ull directories).

You can set a directory your_dir ‘s timestamp to that of its most recently modified file with this monstrosity:

It’s unclear what you mean by ‘main folders’, so I haven’t included any recursion.

Using ls(1) to order a directory by modification time, head(1) to get the first of the files, and touch(1) to change the modification time of your target directory, it’s pretty easy.

Usually it is not advisable to parse the output of ls since it is rarely necessary and easy to be caught up on special characters, however in this case I cannot think of another tool that will as easily give you the file with the latest timestamp in a directory.

Run that with an argument that is a directory, and it should set the modification time of the directory to the latest modification time of any file in the directory.

It will fail if there are no files in the directory (easy to test a number of ways) or if the latest filename has an embedded newline — head will only get the part before the new line.

To update many directories, just run it in a loop.

Источник

Changing a file’s «Date Created» and «Last Modified» attributes to another file’s

I’m using merge cap to create a merge pcap file from 15 files. For the merged file, I have changed the name to that of the first of the 15 files. But I would also like to change the merged file’s attributes like «Date Created» and «Last Modified» to that of the first one. Is there anyway to do this?

I try to access the merged files over a samba server (Ubuntu). So that an extractor function can access auto extract the files to D folder. But as the created date will be changed for the merged file the extraction fails. Is there anyway to fix this?

3 Answers 3

You can use the touch command along with the -r switch to apply another file’s attributes to a file.

NOTE: There is no such thing as creation date in Unix, there are only access, modify, and change. See this U&L Q&A titled: get age of given file for further details.

Example

For example purposes here’s a goldenfile that was created with some arbitrary timestamp.

Now I make some new file:

Now apply goldenfile ‘s attributes to newfile .

Now newfile has the same attributes.

Modify via Samba

I just confirmed that I’m able to do this using my Fedora 19 laptop which includes version 1.16.3-2 connected to a Thecus N12000 NAS (uses a modified version of CentOS 5.x).

I was able to touch a file as I mentioned above and it worked as I described. Your issue is likely a problem with the either the mounting options being used, which may be omitting the tracking of certain time attributes, or perhaps it’s related to one of these bugs:

Источник

Find Files By Access, Modification Date / Time Under Linux or UNIX

I do not remember where I saved pdf and text files under Linux. I have downloaded files from the Internet a few months ago. How do I find my pdf or text files?

You need to use the find command. Each file has three time stamps, which record the last time that certain operations were performed on the file:

You can search for files whose time stamps are within a certain age range, or compare them to other time stamps.

You can use -mtime option. It returns list of file if the file was last accessed N*24 hours ago. For example to find file in last 2 months (60 days) you need to use -mtime +60 option.

  • -mtime +60 means you are looking for a file modified 60 days ago.
  • -mtime -60 means less than 60 days.
  • -mtime 60 If you skip + or – it means exactly 60 days.

So to find text files that were last modified 60 days ago, use
$ find /home/you -iname «*.txt» -mtime -60 -print

Display content of file on screen that were last modified 60 days ago, use
$ find /home/you -iname «*.txt» -mtime -60 -exec cat <> \;

Count total number of files using wc command
$ find /home/you -iname «*.txt» -mtime -60 | wc -l

You can also use access time to find out pdf files. Following command will print the list of all pdf file that were accessed in last 60 days:
$ find /home/you -iname «*.pdf» -atime -60 -type -f

List all mp3s that were accessed exactly 10 days ago:
$ find /home/you -iname «*.mp3» -atime 10 -type -f

There is also an option called -daystart. It measure times from the beginning of today rather than from 24 hours ago. So, to list the all mp3s in your home directory that were accessed yesterday, type the command
$ find /home/you -iname «*.mp3» -daystart -type f -mtime 1

  • -type f – Only search for files and not directories

-daystart option

The -daystart option is used to measure time from the beginning of the current day instead of 24 hours ago. Find out all perl (*.pl) file modified yesterday, enter:

Источник

Читайте также:  Драйвер для принтера ricoh aficio sp 100su для windows 10
Оцените статью