I'm having a problem where when I edit a file, it's modified timestamp is set to a time in the future
Illustration of the problem:
$ make
make: Nothing to be done for `all'.
$ touch makefile
$ make
make: Warning: File `makefile' has modification time 19 s in the future
make: Nothing to be done for `all'.
make: warning: Clock skew detected. Your build may be incomplete.
If I edit the file that same thing happens (ie: this is not a problem unique to touch)
More details:
$ date
Thu Jan 24 20:18:19 EST 2013
$ ls -l
total 24
-rw-rw-r--. 1 steve steve 13907 Jan 24 20:18 makefile
-rw-rw-r--. 1 steve steve 23 Jan 24 19:54 modules.mk
drwxrwxr-x. 3 steve steve 4096 Jan 24 19:54 test
$ touch makefile
$ ls -l
total 24
-rw-rw-r--. 1 steve steve 13907 Jan 24 2013 makefile <-- in the future!
-rw-rw-r--. 1 steve steve 23 Jan 24 19:54 modules.mk
drwxrwxr-x. 3 steve steve 4096 Jan 24 19:54 test
$ ls -l
total 24
-rw-rw-r--. 1 steve steve 13907 Jan 24 20:18 makefile
-rw-rw-r--. 1 steve steve 23 Jan 24 19:54 modules.mk
drwxrwxr-x. 3 steve steve 4096 Jan 24 19:54 test
$ date
Thu Jan 24 20:18:48 EST 2013
How can I edit the file and have it's modified time set to now?
I had the same problem a long time ago using NFS. It drove me crazy! The host where the files were stored and my own computer where not syncronized in time. I had to request the system managers to install NTP.
Related
Scenario;
AWS EC2 running Red Hat 8.2 with an EBS volume mounted at /data
mount | grep -i data
/dev/nvme1n1 on /data type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
Created a test user with home directory on the external EBS volume /data/home/test and copied authorized_keys from ec2-user. SSH fails, 'Server refused our key'. However, when the home directory is moved to root volume; /home, it is possible to login.
The permissions are the same, what am I missing? Thanks!
# ls -Rla /data/home/test/
/data/home/test/:
total 16
drwx------. 3 test test 88 Oct 19 10:16 .
drwxr-xr-x. 4 root root 30 Oct 19 10:15 ..
-rw-r--r--. 1 test test 18 Aug 30 2019 .bash_logout
-rw-r--r--. 1 test test 141 Aug 30 2019 .bash_profile
-rw-r--r--. 1 test test 312 Aug 30 2019 .bashrc
-rw-r--r--. 1 test test 172 Feb 6 2020 .kshrc
drwx------. 2 test test 29 Oct 19 10:16 .ssh
/data/home/test/.ssh:
total 4
drwx------. 2 test test 29 Oct 19 10:16 .
drwx------. 3 test test 88 Oct 19 10:16 ..
-rw-------. 1 test test 829 Oct 19 10:16 authorized_keys
# ls -Rla /home/test/
/home/test/:
total 16
drwx------. 3 test test 88 Oct 19 10:40 .
drwxr-xr-x. 8 root root 106 Oct 19 10:39 ..
-rw-r--r--. 1 test test 18 Aug 30 2019 .bash_logout
-rw-r--r--. 1 test test 141 Aug 30 2019 .bash_profile
-rw-r--r--. 1 test test 312 Aug 30 2019 .bashrc
-rw-r--r--. 1 test test 172 Feb 6 2020 .kshrc
drwx------. 2 test test 29 Oct 19 10:40 .ssh
/home/test/.ssh:
total 4
drwx------. 2 test test 29 Oct 19 10:40 .
drwx------. 3 test test 88 Oct 19 10:40 ..
-rw-------. 1 test test 829 Oct 19 10:40 authorized_keys
I rotate my nginx access log files with logrotate an have the following config:
/var/www/logs/*.log {
daily
missingok
dateext
dateformat _%Y-%m-%d
dateyesterday
rotate 90
compress
delaycompress
compressext
notifempty
create 0640 www-data www-data
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}
When cron runs that script for example at 5am all logs between 0am and 5am in the file will be rotated.
I want a log file for exactly one day from midnight to 11.59pm
Is there an opportunity to configure this?
To rotate the log at 11.59pm configure the /etc/crontab file as follow :
59 23 * * * <path_to_logrotate_command> -f <path_to_logrotate_schedule_file>
E.g. 59 23 * * * /usr/sbin/logrotate -f /home/foo/logrotate/rotate_nginx
Actually, it would be better to just change the schedule of cron.daily, to something like this:
$ grep daily /etc/crontab
59 23 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
Remembering that this will be valid to each script inside /etc/cron.daily:
$ ls /etc/cron.daily -l
total 48
-rwxr-xr-x 1 root root 376 nov 20 2017 apport
-rwxr-xr-x 1 root root 1478 abr 20 2018 apt-compat
-rwxr-xr-x 1 root root 355 dic 29 2017 bsdmainutils
-rwxr-xr-x 1 root root 1176 nov 2 2017 dpkg
-rwxr-xr-x 1 root root 372 ago 21 2017 logrotate
-rwxr-xr-x 1 root root 1065 abr 7 2018 man-db
-rwxr-xr-x 1 root root 539 jun 26 2018 mdadm
-rwxr-xr-x 1 root root 538 mar 1 2018 mlocate
-rwxr-xr-x 1 root root 249 ene 25 2018 passwd
-rwxr-xr-x 1 root root 3477 feb 21 2018 popularity-contest
-rwxr-xr-x 1 root root 246 mar 21 2018 ubuntu-advantage-tools
-rwxr-xr-x 1 root root 214 jun 27 2018 update-notifier-common
But if you need a specific schedule, just for a logrotate rule, the elected answer would be an option.
How do I list matched results in a specified directory?
On my Ubuntu server if I list the contents of a directory it correctly lists it. My working directory is /var/crash.
#pwd
/var/crash
# ls -l
-rw-r--r-- 1 bob bob 121876 Aug 8 2015 results.xml
-rw-rw-r-- 1 bob bob 126 Nov 3 2015 start.txt
-rw-rw-r-- 1 bob bob 43 Jul 28 2015 exit.txt
Let's say I want to list all files that contain 'tar'. In this example there should only be one match i.e. start.txt
# ls -l *tar*
-rw-rw-r-- 1 bob bob 126 Nov 3 2015 start.txt
All's good so far. However if I include the directory (/var/crash) it lists all files.
# ls -l *tar* /var/crash
-rw-r--r-- 1 bob bob 121876 Aug 8 2015 results.xml
-rw-rw-r-- 1 bob bob 126 Nov 3 2015 start.txt
-rw-rw-r-- 1 bob bob 43 Jul 28 2015 exit.txt
I'm guessing my syntax is telling ls to list all matches of tar AND everything in /var/crash. What is the correct syntax to list matches in a specified directory?
You need to specify the pattern together with the directory:
ls -l /var/crash/*tar*
Otherwise, with ls -l *tar* /var/crash you are telling ls to act against two parameters: /var/crash and *tar*. In fact, *tar* will be expanded before ls reaches it, so there might be more parameters for ls.
I am trying to obtain a backup of 'newly' added files to a Fedora system. Files can be copied through a Windows Samba share and appear to retain the original created timestamp. However, because it retains this timestamp I am having issues identifying which files were newly added to the system.
Currently, the only way I can think of doing this is to have a master list snapshot of all the files on the system at a specific time. Then when I perform the backup I compare the previous snapshot with a current snapshot. It would detect files that were removed from the system but it seems excessive and I was thinking there must be an easier way to backup newly added files.
Terry
Try using find. Something like this:
find . -ctime -10
That will give you a list of files and directories, starting from within your current directory, that has had its state changed within the last 10 days.
Example:
My Downloads directory looks like this:
kobus#akira:~/Downloads$ ll
total 2025284
drwxr-xr-x 4 kobus kobus 4096 Nov 4 11:25 ./
drwxr-xr-x 41 kobus kobus 4096 Oct 30 09:26 ../
-rw-rw-r-- 1 kobus kobus 8042383 Oct 28 14:08 apache-maven-3.3.3- bin.tar.gz
drwxrwxr-x 2 kobus kobus 4096 Oct 14 09:55 ELKImages/
-rw-rw-r-- 1 kobus kobus 1469054976 Nov 4 11:25 Fedora-Live-Workstation-x86_64-23-10.iso
-rw------- 1 kobus kobus 351004 Sep 21 14:07 GrokConstructor-master.zip
drwxrwxr-x 11 kobus kobus 4096 Jul 11 2014 jboss-eap-6.3/
-rw-rw-r-- 1 kobus kobus 183399393 Oct 19 16:26 jboss-eap-6.3.0-installer.jar
-rw-rw-r-- 1 kobus kobus 158177216 Oct 19 16:26 jboss-eap-6.3.0.zip
-rw-rw-r-- 1 kobus kobus 71680110 Oct 13 13:51 jre-8u60-linux-x64.tar.gz
-rw-r--r-- 1 kobus kobus 4680 Oct 12 12:34 nginx-release-centos-7-0.el7.ngx.noarch.rpm
-rw-r--r-- 1 kobus kobus 3479765 Oct 12 14:22 ngx_openresty-1.9.3.1.tar.gz
-rw------- 1 kobus kobus 16874455 Sep 15 16:49 Oracle_VM_VirtualBox_Extension_Pack-5.0.4-102546.vbox-extpack
-rw-r--r-- 1 kobus kobus 7505310 Oct 6 10:29 sublime_text_3_build_3083_x64.tar.bz2
-rw------- 1 kobus kobus 41467245 Sep 7 10:37 tagspaces-1.12.0-linux64.tar.gz
-rw-rw-r-- 1 kobus kobus 42658300 Nov 4 10:14 tagspaces-2.0.1-linux64.tar.gz
-rw------- 1 kobus kobus 70046668 Sep 15 16:49 VirtualBox-5.0-5.0.4_102546_el7-1.x86_64.rpm
Here's what the find returns:
kobus#akira:~/Downloads$ find . -ctime -10
.
./tagspaces-2.0.1-linux64.tar.gz
./apache-maven-3.3.3-bin.tar.gz
./Fedora-Live-Workstation-x86_64-23-10.iso
kobus#akira:~/Downloads$
Most unices do not have a concept of file creation time. You can't make ls print it because the information is not recorded. If you need creation time, use a version control system: define creation time as the check-in time.
If your unix variant has a creation time, look at its documentation. For example, on Mac OS X (the only example I know of¹), use ls -tU. Windows also stores a creation time, but it's not always exposed to ports of unix utilities, for example Cygwin ls doesn't have an option to show it. The stat utility can show the creation time, called “birth time” in GNU utilities, so under Cygwin you can show files sorted by birth time with stat -c '%W %n' * | sort -k1n.
Note that the ctime (ls -lc) is not the file creation time, it's the inode change time. The inode change time is updated whenever anything about the file changes (contents or metadata) except that the ctime isn't updated when the file is merely read (even if the atime is updated). In particular, the ctime is always more recent than the mtime (file content modification time) unless the mtime has been explicitly set to a date in the future.
"Newly added files, Fedora" : The below examples will show a list with date and time.
Example, all installed packages : $ rpm -qa --last
Example, the latest 100 packages : $ rpm -qa --last | head -100
Example, create a text file : $ rpm -qa --last | head -100 >> last-100-packages.txt
I've tried to use vim-gitgutter but it doesn't work and I even don't know where to find a root of error.
$ git --version
git version 1.9.3 (Apple Git-50)
$ vim --version | head -1
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Sep 12 2013 14:04:26)
$ ll ~/.vim/autoload/pathogen.vim
-rw-r--r-- 1 coder staff 12K 8 Dec 23:32 /Users/coder/.vim/autoload/pathogen.vim
$ ll ~/.vim/bundle/vim-gitgutter
total 56
-rw-r--r-- 1 coder staff 12K 8 Dec 23:17 README.mkd
drwxr-xr-x 4 coder staff 136B 8 Dec 23:17 autoload
drwxr-xr-x 3 coder staff 102B 8 Dec 23:17 doc
drwxr-xr-x 3 coder staff 102B 8 Dec 23:17 plugin
-rw-r--r-- 1 coder staff 16K 8 Dec 23:17 screenshot.png
drwxr-xr-x 39 coder staff 1,3K 8 Dec 23:17 test
:echo has('signs') returns 1 as it should and I can see the differences by git diff
It turned out that pathogen wasn't activated and it didn't load gitgutter. I fixed it by adding the following line to ~/.vimrc
execute pathogen#infect()