Tag Info

New answers tagged

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


1

-type f will only find files, not directories. -maxdepth 0 will only ever find the directory you're searching in (.). You'll have to find the files you actually want to pass to rm. The standard way to do this is to exclude directories and all their contents like this (untested!): find . -mindepth 1 \( -name '*log*' -o -name 'crash-reports' -o -name ...


0

In addition to @Gnouc answer , you can also add ls -la to get more details. You should have sudo privileges to do that . $ find / -xdev -type f -size +100M -exec ls -la {} \; | sort -nk 5


1

Try: find / -xdev -type f -size +100M It lists all files that has size bigger than 100M. If you want to know about directory, you can try ncdu. If you aren't running Linux, you may need to use -size +204800 or -size +104857600c, as the M suffix to mean megabytes isn't in POSIX. find / -xdev -type f -size +102400000c


-1

Instead of piping the output to grep, why not just use awk to only match the 'i' in the first field of the output? lsattr -Ra 2>/dev/null /|awk '$1 ~ /i/ && $1 !~ /^\// {print}' In fact, I run this daily via cron to scan the /etc directory on hundreds of servers and send the output to syslog. I can then generate a daily report via Splunk: ...


2

There are several syntax problems, one of which is fatal and another which is likely to bite you at some point. By the way, you can use + instead of ; to end the -exec directive; this way gzip will be executed in batches, which is slightly faster. If the value of LOGS_DIR is /somewhere/with/logs, then the following command is executed on the remote host: ...


0

You forgot to add an ';': ssh -q $CUR_HOST "cd $LOGS_DIR; echo cd $LOGS_DIR; find . -name *.log -mmin +1440 -exec gzip {} \;; exit" Because of the missing ;, find interprets exit as a path.


2

An alternative to l0b0's fine answer (shorter, but potentially slightly less efficient): Assuming a (recent) GNU sed: find pool -print0 | sed -znE 's|.*/mypackage-([[:alnum:].]+-[0-9]{1,2})-x86_64\.pkg\.tar\.xz$|\1|p'| tr '\0' '\n' Note the expensive part of find is the walking down the tree which it will have to do anyway whether you have -regex or ...


3

If you use find pool -regextype posix-extended \ -regex ".*/mypackage-([a-zA-Z0-9.]+-[0-9]{1,2})-x86_64\.pkg\.tar\.xz" \ -printf '%f\n' | grep -Eo '[a-zA-Z0-9.]+-[0-9]{1,2}' (assuming GNU grep as well), it should work for any path. The regex doesn't allow for any newlines, so there's no way to make it match for example a directory containing a ...


3

Question 1: What's happening? Your -o is splitting your arguments. The -exec only runs if the stuff on the same side of the -o is successful (the -path "*amblock/stats.*BRIK"). If you want -exec to run on both conditions, you need to wrap them in parenthesis: find ${TRIADS_DIR}/*.dc.results \( -path "*amblock/stats.*HEAD" -o -path "*amblock/stats.*BRIK" \) ...


1

That should be what you search: find /home/user/logfilesError/ -maxdepth 1 -type f -name "gBatch_*" -daystart -mtime -1 \ -exec grep -H "ERROR" {} \; | sed -e 's/.*\/gBatch_/gBatch_/g' -e 's/:[^E]*/: /g' | tr '\n' ', ' Example ouput: gBatch_2070.log:ERROR **.batch.BatchStart = Batchverarbeitung beeendet, gBatch_2077.log - ERROR **.batch.BatchStart = ...


1

find /home/user/logfilesError/ -maxdepth 1 -type f -name "gBatch_*"\ -daystart -mtime -1 -exec grep -rl "ERROR" "{}" + | xargs -l basename\ > /tmp/files_found if [ $? -eq 0 ]; then tday="$(date +'%d.%m.%Y')" while read line do error=`grep "ERROR" /home/user/logfilesError/$line` error=`echo $error | sed 's/^.*ERROR/ERROR/' | ...



Top 50 recent answers are included