Tag Info

New answers tagged

0

You specified -or, that needs to be -o, as other have corrected. You also need parentheses I think (correction on my original post). I'd recommend using %T@ for the format specifier (seconds since 1970) which is cleaner to sort; then you can convert it using date --date="@`find . \\( -iname "*.mp3" -o -iname "*.jpg" \\) -printf '%T@\n' | sort -rn | head ...


2

Also see the following: find . -type f -mtime -1 \( -name '*.mp3' -o -name '*.jpg' \) -printf '%AY-%Am-%Ad %P \n'


5

Something like this should work: find . \( -iname "*.mp3" -o -iname "*.jpg" \) -printf '%TY%Tm%Td %TT %p\n' | sort -r This should find the files that (case-insensitively) find files ending with mp3 or jpg, print out the modification time, then sort it in reverse order. It seems to show both file-types when you run it effectively as two commands: ( find ...


4

With zsh: setopt extendedglob zmodload zsh/stat zstat -F %F +mtime -- **/(#i)*.(mp3|jpg)(Om[1]) Note that it's based on last modification time, the creation time (whatever that means) is generally not readily available on Linux. It doesn't consider hidden files. I you want them, add the D globbing qualifier above.


2

Depending on what you want exactly to do, and the structure of your files, other possibilites may be available, such as : ls -1tq /dir/*/readme.txt | head -n 1 Returns the full name of the most recent readme.txt found in any subdirectory (not recursive) of /dir/ The usage of * as part of the path (not just as part of a filename) often being underknown, I ...


1

For more portability, you can use perl: $ perl -MList::Util=reduce -le ' BEGIN { $dir = "." } opendir DIR,$dir; print shift @{(reduce {$a->[1] > $b->[1] ? $a : $b} map {[$_,(stat($_))[9]]} grep { -d and !/^..?$/ } readdir DIR)} ' .Skype Change $dir to whatever directory you want ...


3

You don't need any elaborate pipelines for this. Moreover, you don't need to find anything - you already know where each file is, you just don't know which of them is newest. This is easily handled. To demo, here's my little test: mkdir ./dir1 ./dir2 ./dir3 for d in 1 2 3 do touch ./dir$d/samefile sleep 1 done That creates the test set. Now, which ...


0

Short answer: look into man find and the 'time' options. This will locate the file(s), then use the -printf option to display the path of the file(s), which then can be used for cd <path> One way to use find and extract DIR of the last accessed file (within the last 24h) in current dir and its sub directories lastAccDir="$(find 2>/dev/null . -type ...


1

To complement @JRFerguson's answer. To obtain a reference file whose modification time is 30 minutes in the past, you can do portably (precision of one second): TZ=ZZZ0 touch -t "$(TZ=ZZZ0:30 date +%Y%m%d%H%M.%S)" /some/ref/file And then do: find . -newer /some/ref/file That only works for intervals of 50 hours: TZ=ZZZ-24:59:59 touch -t ...


0

You can use perl instead: #! /usr/bin/perl use strict; use warnings; use File::Find (); use File::stat; use vars qw(*name); *name = *File::Find::name; my $now = time; File::Find::find({wanted => \&wanted}, '.'); sub wanted { print "$name\n" if stat($_)->mtime > ($now - 30*60) and $name ne "."; } Except OSX or ...


2

AIX's find lacks the nice GNU features. You can work around this easily. Create two "reference" files with timestamps that mark the boundaries of interest: touch -amt 201407251200 myref1 touch -amt 201407251230 myref2 Now do: find . -type f \( -newer myref1 -a ! -newer myref2 \) -exec ls -ld {} + This references a file's mtime or modification time. ...


1

You should use -cmin. From man page of find, -cmin n File’s status was last changed n minutes ago. -ctime n File’s status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpreta- tion of file status change times.


2

your drive /dev/sdb1 is mounted in media_2e040 directory now so all the properties of media_2e049 are sdb1 properties. if you change them with touch you have changed sdb1 properties.


1

From the GNU manpage -t sort by modification time, newest first -c with -lt: sort by, and show, ctime (time of last modification of file status information) with -l: show ctime and sort by name otherwise: sort by ctime, newest first When -c is used with -lt, it will show and sort by file ctimes (instead of modification ...


5

-t lists the file's modification time, which is the last time the file's content was modified (unless the modification time was explicitly set afterwards). -c lists the file's inode change time, which is the last time the file's metadata was changed (ownership, permissions, etc.) or the file was moved. Most unix systems do not track the creation date of a ...


0

If you're sure that your file names won't contain newlines or unprintable characters, then this is one of the rare cases where is makes sense to parse the output of ls. cd /app/path1/path2 latest_file=$(LC_ALL=C ls -cr | head -n 1) mv "$latest_file" /app/path1/path2/path3 or if you want to avoid a directory change in the main shell process: ...


1

Unix doesn't have a create date, so when you update these files in your .zip you're updating them based on their modification date, which according to the zip man page is normal behavior. excerpt The new File Sync option (-FS) is also considered a new mode, though it is similar to update. This mode synchronizes the archive with the files on the OS, only ...


1

Your issue is due to the fact that you've taken control of the formatting of the output generated by find, splitting on newlines now, \n. In order to get xargs to process your output when using -0 the output needs to be separated by null characters, \0. Here's an easy way to fix it though: $ find . -type f -printf "%C@ %p\n" | sort | tail -n 2 | \ cut ...


1

Either avoid -0 option with xargs, or use -print0. A snippet from the man page for xargs In these situations it is better to use the -0 option, which prevents such problems. When using this option you will need to ensure that the program which produces the input for xargs also uses a null character as a separator. If ...


0

Linux doesn't have an easily accessible file creation timestamp (but see Stéphane's comment below). Running stat on a file I've just created shows a Access, Modify and Change timestamp - but no creation. I'm guessing that maybe the CIFS share you viewed a few months ago was not created by a Linux system? Maybe it was a Windows system shared by CIFS?


6

You may want to check this: ls -l --time=atime atime — updated when file is read mtime — updated when the file changes. ctime — updated when the file or owner or permissions changes. Have fun! :)


3

You need to use GNU stat command. Example: stat my_file.txt will give you what you are looking for.


5

Try: ls -lu If you want sorted result by access time: ls -ltu From man ls: -u with -lt: sort by, and show, access time with -l: show access time and sort by name otherwise: sort by access time If you want to get full date time, use --full-time: $ ls -ltu --full-time Or use GNU stat: $ stat -c "%x" -- test.txt 2014-06-30 ...



Top 50 recent answers are included