Tag Info

New answers tagged

0

With out GNU/BSD find TZ=ZZZ0 touch -t "$(TZ=ZZZ0:30 date +%Y%m%d%H%M.%S)" /reference/file and then find . -newer /reference/file solution given by Stéphane Chazelas


1

Recreating the directory seems a pretty clean way to do it. find /data1 -name MyTargetDir -type d -exec rm -rv {} \; -exec mkdir {} \; You could instead use a subshell in the exec to run a rm -rf * (or similar) from within the directory. But that just seems more trouble than the above. You have the side effect of cleaning up the directory size if that ...


0

No doubt there are nicer ways of doing it, but this should work: for MyTargetDir in `find /data1 -name MyTargetDir -type d -depth` do if [ $MyTargetDir != "" ]; then rm -rfvi $MyTargetDir/* fi done The if statement is required in case you never find the directory that you are looking for in which case the rm command would destroy your root file ...


-1

Or you could try this command without the r option in rm. so it don't will be able to remove directories.


0

rm -rf MyTargetDir && mkdir MyTargetDir It should do what you are trying to do.


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.


1

Argument of -name parameter in find command works exactly as wildcard characters in file/directory names in command line. * is any string and ? is any character.


8

The pattern given to -name has to match the entire base filename. The behaviour of the -name pattern is defined as: The primary shall evaluate as true if the basename of the current pathname matches pattern This means it's true when the whole of the basename matches the pattern you gave. You can think of a pattern as being basically like a shell glob: ...


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.


0

For closure, this is the start of the script I am going to use. It needs more work to make it robust and do logging but you should get the general idea. #!/bin/sh # This script should be executed from a crontab that executes every 5 or 10 minutes # the find below looks for all log files that do NOT have the sticky bit set. # You can see the sticky bit ...


0

Try to use inotifywait for that: inotifywait -e close_write /home/tomcat/openam/openam/log/CURRENT_OPENED_LOG_FILE


3

The argument to -regex has to match the whole path that is found. A command like find . finds paths like ./dir/subdir/somefile, while a command like find ~/dir finds paths like /home/adam/dir/subdir/somefile. So your regexp has to match the /home/adam part at the beginning. The command find -E . -type f -regex '^\..*[^~]' finds files whose name doesn't ...


1

You can use mtime to do so: find . -mmin 30 #exactly 30 minutes old


3

On Linux, there is no track of the creation time of a file. You can only access: the last modification time of the content (a creation counts as a modification of course), mtime, the last access time, atime, the last modification time of the meta-data, ctime. If you want to look for files with a test based on these times, find (man find) can help you. ...


0

You can use $ find ~/ -type f -name "MYFILE" The best way to search for file or folder is : updatedb (for updating system file index). locate Myfile


8

Use the -perm test to find in combination with -not: find -type d -not -perm 775 -o -type f -not -perm 664 -perm 775 matches all files with permissions exactly equal to 775. -perm 664 does the same for 664. -not negates the test that follows, so it matches exactly the opposite of what it would have: in this case, all those files that don't have the ...


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: ...


3

you could use: find . -type f ! -name "*.*" the ! negates the following expression, here a filename that contains a '.' you can also use the -maxdepth option to reduce the search depth.


0

There is no really good way to tell from a system perspective which is the last created directory, as as been pointed out ctime and mtime are not reliable indicators. You could procedurally do this, by creating a file called .create-time when you create your directory and then never modify or change the permission on this file and use the file as your guide ...


1

In Linux, you can't get the created date of file. ctime is not created date. It changes when your file is updated content or metadata. In Mac OSX, you can use option -U: ls -tU So you can try: cd $(ls -tU parent/cv* | head -n 1)


0

There are many ways to find the latest file/directory, depending on which tools you have at your disposal and how portable you want to be.


1

You can try to use find -D tree . [expr..] to understand what find does with your original command. You must understand that the -type f and also the -exec ls .. expressions are and'ed to the rest of the expressions with higher precedence than the ors. So your original command will get parsed into something like this: (-type f AND -name *.c) OR -name *.h OR ...


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 ...


2

With GNU find, you can use -regex option: find . -type f -regex '.*\.\(c\|h\|cpp\)' -exec ls {} \;


2

Try adding the expressions into parentheses as stated in the man page: find . -type f \( -name '*.c' -or -name '*.h' -or -name '*.cpp' \) -exec ls {} \; should work.


2

Like this: find . -name '*.bor' -exec zip '{}.zip' '{}' ';'


1

If I understand you right, you want to have the attachments have filename like Sum123.pdf instead of homecdeSum123.pdf. I assume the latter name is produced by your mail program that removes the slashes in the path name when saving. I think you should use a different way to call uuencode, removing the path name on the second parameter: find /home/cde ...


2

Try this oneliner find /home/cde -ctime -1 -name "Sum*pdf*" | uuencode files.txt | mailx -s "subject" abc@gmail.com


0

Though this command may be safe in most cases, it is a bad habit to use * where the command can accept options, because a filename starting with a dash (created by mistake or by a malicious person who could have exploited another bug) could be interpreted as an option. As someone said, the * is pointless here, but what you need to remember is that, ...


-1

find will print all files and folders in the directory tree. xargs runs the command supplied - rmdir for each element find returns. rmdir will not remove folders that aren't empty, and will not remove files either - you can try it. mkdir a folder, touch a few files inside it and then run rmdir on the folder. rmdir will complain with something like this: ...


5

The man page for rmdir says:- Remove the DIRECTORY(ies), if they are empty. If you want to remove all empty directories then it will be safe. The question you need to ask is:- Do you want to remove all empty directories? Some applications need a directory even if it's empty. For example, journald can be configured so that it only logs to persistent ...


0

According to your strace output, and I have no idea about the reason, the open() function prefix filenames with /proc/ : open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 4 fcntl64(4, F_SETFD, FD_CLOEXEC) = 0 getdents64(4, /* 21 entries */, 32768) = 664 getgid32() = 0 stat64("/proc/index.php", 0xbfc53bd0) = -1 ENOENT (No such file or directory) ...


0

The use of uuencode is not standard and won't give you attachments. If you want to send a mail with multiple attachments, the easiest solution may be to use Mutt with mutt -s subject -a file1 file2 ... filen -- address < message


0

Here, use this :). #!/bin/bash RECIP="abc@example.com" SRCDIR="yourdirectory" TMPDIR="tmp" [ ! -d "$TMPDIR" ] && mkdir -p "$TMPDIR" attargs="" for file in `find "$SRCDIR" -ctime -2 -type f -name "Sum*pdf*"`; do echo "$file" #DEBUG filename=`basename $file` uuencode "$file" "$filename" > "$TMPDIR/${filename}" attargs="${attargs} ...


0

POSIX has this to say about dates in an ls -long listing: The <date and time> field shall contain the appropriate date and timestamp of when the file was last modified. In the POSIX locale, the field shall be the equivalent of the output of the following date command: date "+%b %e %H:%M" ...if the file has been modified in the last six ...


0

I found this tip that shows how to use uuencode to append multiple attachments to a single file, and then attach this single file to the email. The article is titled: Email Multiple File Attachments From Solairs / AIX / HP-UX / UNIX / Linux Command Line. Example $ uuencode r1.tar.gz r1.tar.gz > /tmp/out.mail $ uuencode r2.tar.gz r3.tar.gz >> ...


5

The ; has to be its own separate argument to find: find /home/shredtest/ -depth -exec /home/test.sh "{}" \; (note space between {} and \;). After -exec: All following arguments to find are taken to be arguments to the command until an argument consisting of `;' is encountered. (from man find). That is, the argument has to consist entirely of ; to ...


2

I assume that your file names don't contain newlines. find /home/setefgge/public_html -type f -ctime -1 -exec ls -nls {} + | sort -k 10 Using + instead of ; to terminate the -exec action makes it faster by batching the invocations of ls. You can sort by piping through the sort command; tell it to start sorting at the 10th field (the first 9 are the ...


0

Why not pipe the result of find through sort and then execute ls for each of the lines? find . -type f -ctime -1 | sort | while IFS= read -r filename; do ls -ls "$filename"; done


4

Once you hit a directory that's not executable, find tries to go into it, but it can't because, well, it's not executable. You need to tell it not to try by using -prune. And put that condition first, so it's not short-circuited. find . '(' '(' -not -executable ')' -and -type d -and -prune ')' -or \ '(' -not -readable ')' -or \ '(' -not ...


-1

ls -l $(find /home/setefgge/public_html -type f -ctime -1 | sort)


0

find /path/folder -type d -ctime +7 | xargs rm -rf ctime +7 only consider the ones with modification time older than 7 days


0

What you want is not possible IMHO with a single find run unless you know that all the directories to be skipped are in the first directory level. first step In the first run delete all the files (or rather: non-directories): find . \( -type d \ \( -name '*log*' -o -name 'world*' -o -name 'crash-reports' -o -name 'banned-ips*' \) \ -prune \) -o \( ...



Top 50 recent answers are included