the rules of find -cmin 0 and -ctime 0 - find

I was studying the command find, and I saw:
-cmin n
File's status was last changed n minutes ago.
-ctime n
File's status was last changed n*24 hours ago.
but when n is zero, comes the difference, is there a sound explanation for this behavior?
$ date
Thu 23 Jul 2020 02:16:17 PM CST
$
$ touch a
$ find -name a -cmin 0
$ find -name a -cmin 1
./a
$ find -name a -ctime 0
./a
$ find -name a -ctime 1
$
$ date
Thu 23 Jul 2020 02:16:18 PM CST
$

Related

Alias directory minus one file

I'd like to make an alias for a directory that contains many files. If I open the aliased directory, I want to view all files except for one. New files will be added to the directory over time, and I want everything to be aliased except for the one file permanently not-aliased.
Is it possible to set this up without needing to run a script every time a file in the directory changes?
E.g.: myDir contains fileA, fileB, and fileC.
I want myAliasedDir to contain fileA and fileB, but not fileC.
Can you get away with symbolic links?
Assuming your shell is bash:
$ shopt -s extglob
$ mkdir dir1 dir2
$ cd dir1
$ touch file{1..3}
$ ls -l
total 0
-rw-r--r-- 1 jackman jackman 0 Apr 1 12:40 file1
-rw-r--r-- 1 jackman jackman 0 Apr 1 12:40 file2
-rw-r--r-- 1 jackman jackman 0 Apr 1 12:40 file3
$ cd ../dir2
$ for f in ../dir1/!(file2); do ln -s "$f"; done
$ ls -l
total 8
lrwxrwxrwx 1 jackman jackman 13 Apr 1 12:41 file1 -> ../dir1/file1
lrwxrwxrwx 1 jackman jackman 13 Apr 1 12:41 file3 -> ../dir1/file3

I broke the FIND command of Ubuntu, mtime not working as it should

I'm building a script for backup and I'm heavily using the FIND with -mtime.
Yesterday I used find -mtime +1 a lot, to search the file modified more than a day ago.
At the end of the day, the command I used for the whole day stopped working.
user#ubuntu-4:~$ mkdir test
user#ubuntu-4:~$ cd test/
user#ubuntu-4:~/test$ touch -t 201601180830 yesterdayMorning
user#ubuntu-4:~/test$ touch -t 201601181725 yesterdayAfternoon
user#ubuntu-4:~/test$ ll
total 32
drwxrwxr-x 2 user user 4096 Jan 19 09:37 ./
drwx------ 9 user user 12288 Jan 19 09:36 ../
-rw-rw-r-- 1 user user 0 Jan 18 17:25 yesterdayAfternoon
-rw-rw-r-- 1 user user 0 Jan 18 08:30 yesterdayMorning
The result of FIND -mtime n
user#ubuntu-4:~/test$ find -mtime +1
user#ubuntu-4:~/test$ find -mtime -1
.
./yesterdayAfternoon
user#ubuntu-4:~/test$ find -mtime 0
.
./yesterdayAfternoon
user#ubuntu-4:~/test$
I should be able to find the file named yesterdayMorning because at the time I'm writing (09:48 am of 19 january) that file is older than 1 day.
find -mtime -1 (or 0 too) show the correct result because the file's last modification is less than 24 hours.
And yesterday before 05.00 pm I swear it was working!
It's actually not 24 hours ago but more than n days ago. I.e. for -mtime +1 it would have to be modified two days ago.
Use find -mtime +0 to match also yesterday's files.
As stated in the accepted answer -mtime +0 will work for you in this case.
Note:
find using -mtime and -daystart
-mtime n
File's data was last modified n*24 hours ago.
-daystart
Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and
-mtime) from the beginning of today rather than from 24 hours
ago.
This option only affects tests which appear later on the
command line.
date
Tue Jan 19 10:24:43 CET 2016
~/test $ ls -n
total 0
-rw-r--r-- 1 1000 1000 0 Jan 18 10:15 yesterdayMorning10:15.txt
-rw-r--r-- 1 1000 1000 0 Jan 18 10:45 yesterdayMorning10:45.txt
~/test $ find -mtime +0
./yesterdayMorning10:15.txt
~/test $ find -mtime 0
./yesterdayMorning10:45.txt
~/test $ find -daystart -mtime +0
./yesterdayMorning10:15.txt
./yesterdayMorning10:45.txt

date '+%p' AM/PM indicator is wrong case on Fedora 20

This is rather esoteric. But I have a test which tests the string of a formatted timestamp, so it's bugging me.
date's man page indicates that
%p locale's equivalent of either AM or PM; blank if not known
%P like %p, but lower case
However, on Fedora 20:
$ date
Mon 27 Oct 22:44:22 AEDT 2014
$ date '+%p %P'
pm pm
$ TZ=Europe/Madrid date '+%p %P'
pm pm
The %p is not uppercase as it should be.
On Ubuntu 14.04 the behaviour is correct:
$ date
Mon Oct 27 12:20:08 CET 2014
$ date '+%p %P'
PM pm
$ TZ=Australia/Melbourne date '+%p %P'
PM pm
They both have the same version (8.21). Any suggestions on where to look next?
My colleagues managed to track it down to the language setting:
$ LANG=en_AU.UTF-8 date '+%p %P'
AM am
$ LANG=en_GB.UTF-8 date '+%p %P'
am am
Now to figure out where to file a bug report...

Need to remove files with spaces in Debian

I need to find and remove files with spaces in them in a certain folder.
$ ls -l
total 16
-rw-r--r-- 1 smw staff 10 Feb 6 16:10 Foo Bar
-rw-r--r-- 1 smw staff 11 Feb 6 16:10 foobar
$ ls -l *\ *
-rw-r--r-- 1 smw staff 10 Feb 6 16:10 Foo Bar
$ rm -i *\ *
remove Foo Bar? y
$ ls -l
total 16
-rw-r--r-- 1 smw staff 11 Feb 6 16:10 foobar
You'll have to deal with bash's niceties when dealing with spaces...
First, you need to iterate over the files, in a way that gives you the files properly regardless of spaces. Check out this question. I'd favor this:
find ... | while read line ; do command "$line" ; done
And then it's a matter of using something like sed to change $line into whatever you need (such as the same thing without spaces) right where command "$line" is.
This is how I removed a file with a space
pi#raspberrypi ~/Music $ ls -l
-rw-r--r-- 1 pi pi 0 Feb 25 16:05 Sleep Away.mp3
pi#raspberrypi ~/Music $ rm Sleep\ Away.mp3
use the "\" forward slash to escape any spaces

How to delete a NULL file from Solaris Unix?

I have a NULL file in a directory:
-rw-r--r-- 1 blah1 blah2 83532 Nov 5 09:34 <can't see, but null here>
How do I remove this? This is very annoying as it interferes with svn status.
Thanks for any help.
Delete interactively, saying no to all of the non-null files.
/bin/rm -i *
You can remove using the iNode value (using the -i option on ls command)
# ls -li
total 16
30475938 -rw-r--r-- 1 root root 7 mar 19 10:29 -h
# find . -inum 30475938 -print
./-h
# find . -inum 30475938 -exec rm {} \;
# ls -li
total 0
In my blog, you have some examples -in Spanish- how to remove files with reserved characters.
http://sparcki.blogspot.com.es/2010/03/como-eliminar-archivos-utilizando-su.html
Urko,