Tag Info

Hot answers tagged

7

I am a little confused by wording of the question. If what you want to do is delete everything in the ./Library/Caches directory apart from a single folder called Snapshots, there is no need to use find. In bash, shell globs are the simplest way: shopt -s extglob # probably already enabled echo Library/Caches/!(Snapshots) If this prints all the ...


6

find . -name TheFileName -type f -exec sh -c 'for i do echo SomeText > "$i"; done' sh {} +


6

find . -depth -print0 | perl -0lne ' if ("$_/" =~ m{/Caches(/.*)}s && $1 !~ m{/Snapshots/}) {rmdir $_ or unlink $_}' If your find doesn't support -print0, you can replace it with -exec printf '%s\0' {} +. The idea is to print the list of files NUL-terminated (as 0 is the only byte that can't occur in a file path) and use perl's -n with -0 ...


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


5

If you statement is true “there are no .B files without .A files.”, then get a list of .B files and remove the extension. find $directory-to-search -name "*.B" | sed -r -e "s~(.*)\.B~\1~g"


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


4

Ugly and fragile, but it should get the job done: find /data/DIV5/SASC/e042_ctcl/input/*/Clean_data/*/*/*.fq.gz -type f -print0 | \ xargs -0 -n 1 \ sh -c 'mkdir -p "$PWD/`dirname $0`"; ln -s "$0" "$PWD/`dirname $0`"' Inspired by chaos' answer, I came up with this alternative which also trims unneeded directories: find ...


4

Because you don't use option -type f, find will return all folders and files. In second command, if a folder is found, command ls -lh will list its content, causing more result than first command. $ find . -maxdepth 1 -mtime -10 | wc -l 63 $ find . -maxdepth 1 -mtime -10 -exec ls -lh {} \; | wc -l 313 You should use: find . -maxdepth 1 -type f -mtime -10 ...


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


3

access times are a feature of the filesystem. individual programs cannot prevent this. it has to be disabled on the filesystem. you can disable access time updates for the files: chattr -R +A /my/directory or mount the filesystem using noatime to disable access time updates for the entire filesystem. note that with both options above access times ...


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" \) ...


3

I do not believe the jar command accepts multiple .jar files by way of arguments so AFAIK a single jar invocation addressing all .jar files is out of the question. One option to speed things up by avoiding one find exec invocation for each .jar file is the follows find . -name '*.jar' -exec sh -c \ 'for f; do jar -tf "$f" | grep --label="$f" "spring"; ...


3

If none of the filenames contain any newlines, you can do: find D -type f \( -name '*.A' -o -name '*.B' \) | sed 's/\.[^.]*$//' | sort | uniq -d >paired_files This should work in the more general case where there are .B files without .A files. To handle any filename using recent GNU tools: find D -type f \( -name '*.A' -o -name '*.B' \) -print0 ...


2

I am with the impression that you are looking for a tool like GNU Stow. GNU Stow is a symlink farm manager which takes distinct packages of software and/or data located in separate directories on the filesystem, and makes them appear to be installed in the same place. For example, /usr/local/bin could contain symlinks to files within ...


2

I whould generate the commands with awk and then pipe them into bash: find /data/DIV5/SASC/e042_ctcl/input/*/Clean_data/*/*/*.fq.gz -type f | \ awk '{printf "mkdir -p `dirname %s`\nln -s %s ./%s \n", substr($0, 27), $0, substr($0, 27)}' This generates a list of the commands, I would first control them and then finally pipe it to bash. The complete command ...


2

I'm not a find sorcerer so I don't want to say that you can't do it with find, but I do know it can be done with a couple lines of bash. Given that I understand your directory structure correctly: #!/bin/bash for i in Library/Caches/*; do if [[ -d "$i" ]]; then [[ "$i" =~ "Snapshots" ]] || echo "rm-ing $i" # change to rm -rf "$i" to use ...


2

The below command would look for the jar files that have substring spring in it. find /some/dir -type f -name "*spring*.jar" Now, your original command looks through the content, which isn't what the text around it or the examples say. find . -name "*.jar" -exec jar tf '{}' \| grep -H "spring" \; Please find this chat description where Gilles ...


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


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


2

I suspect you mean that you want the filename as included in the uuencode output: begin 644 path/to/the/file.pdf.Z %=&5S=`H` ` end not to include the path/to/the. For that, you want the second argument passed to uuencode to be the basename. For that you'd need to do it like: find "$dir" -ctime -1 -type f -name "abc*pdf*" -exec sh -c ' for file do ...


2

Your find cmd also finds the current directory ".". The rights of this directory will then be set to 600 and therefore you'll lose the rights to touch the files within this directory. So cd .., chmod 700 said directory and then run your reverting find, which now excludes the current directory, like this: find . \! -path . \! -iname '*.sh' -print0 | xargs ...


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


2

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


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


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

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


1

You can use tee for this: If your shell properly matches the **/TheFileName, and the issue is simply getting the content in each file: echo SomeText | tee **/TheFileName >/dev/null If the issue is that **/TheFileName isn't matching properly, you can use find: echo SomeText | find . -name TheFileName -exec tee {} + >/dev/null If your find doesn't ...


1

Zsh has a convenient function zmv. First, load it (you can do this from your .zshrc, or on the command line for a one-session use): autoload -U zmv alias zcp='zmv -C' alias zln='zmv -L' To recreate a forest of symbolic links is as easy as this: zln -s '/data/DIV5/SASC/e042_ctcl/(input/*/Clean_data/*/*/*.fq.gz)' '$1' If you want to traverse Clean_data ...



Only top voted, non community-wiki answers of a minimum length are eligible