Tag Info

Hot answers tagged

4

The most straight forward way I can see to do this is with GNU find, bash and the sponge utility from moreutils: find dir/with/files -name '*.txt' ! -name '*.DontTouch.txt' -print0 | while IFS= read -rd '' file; do echo 'cat path/to/theCommonComment.txt "$file" | sponge "$file"' done As it stands this will just print the cat/sponge commands ...


2

find has a little bit of sophistication to deal with this case: If the expression contains no actions other than -prune, -print is performed on all files for which the expression is true. So explicitly print just the parts you want: find -type d \( -iname old -prune -o -iname backup -prune -o -iname .git -print \) avoids searching the old and backup ...


2

You could exclude the directories by specifying -path: find . -type d \( -iname .git ! -path "*/old/*" ! -path "*/backup/*" \) Note that -not in GNU find is the same as ! but is not POSIX compliant. Quoting from man find: ! expr True if expr is false. This character will also usually need protection from interpretation by the shell. ...


2

You need the -prune option of find, it's really pretty tricky. It requires to use -path instead of -name too. I think you want to use this: find . -type d \( -path '*/old' -prune -o -iname '.git' -print \) The effect of the -not is implemented by matching old "old", and the donig nothing or (using option -o) matching ".git" and printing the name or ...


2

Use find with an absolut path. find /path/ -size +20M It will print the whole path. If you do not know the working directory then use command substitution for pwd like this: find "`pwd`" -size +20M #or like this: find "$(pwd)" -size +20M To get your working directory


1

On GNU/anything, to insert _after_ the first line: find -name '*.txt' ! -name '*thispattern*' ! -name '*thatpattern*' \ -exec sed -si '1r TheLicense.txt' '{}' + to insert a file before, simplest is somewhat slower and a little bit kludgier: find -name '*.txt' ! -name '*thispattern*' ! -name '*thatpattern*' \ -exec sed -si '1{h;s,.*,cat ...


1

I would create a file as dummy with the contents that you want to be replaced. So dummy file would look like below. <?php /** * * Copyright (C) MyCompany, Ltd. - All Rights Reserved * Unauthorized copying of this file, via any medium is strictly prohibited * Proprietary and Confidential * * */ After that, I would execute the below ...


1

find -type d -iname .git -not -iname old This matches directories which are called .git and not called old. Since a directory which is called .git cannot be called old, the -not -iname old part can be removed without changing the meaning of the command. -not says “don't match”, but not “don't recurse into”. There's a different way to say “don't recurse ...



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