Tag Info

New answers tagged

1

If you don't mind seeing the output slightly out of order (if you do, you can sort it): grep -r --exclude={*~,*.map,*.js} "OK" /some/dir **/*.debug.js This requires that your shell supports ** for recursive globbing: zsh does out of the box, bash does after you run shopt -s globstar, ksh93 does after you run set -o globstar. Without ** support in the ...


3

With zsh you can do: grep OK some/dir/**/^(*~|*.map|(^*debug).js) Provided of course the argument list isn't too long, in which case you can always do: printf '%s\0' some/dir/**/^(*~|*.map|(^*debug).js) | xargs -0 grep ok


7

I'd use find to locate the files and pipe the result through xargs: $ find . -type f \! -name "*~" \ \! -name "*.map" \ \! \( -name "*.js" -and \! -name "*.debug.js" \) \ -print0 | xargs -0 grep "OK" This searches for every file not matching "*~", "*.map" or "*.js but not *.debug.js". Using find you can easily ...


5

I would just pass that through a second grep to remove them: grep -r --exclude={\*~,\*.map} "OK" bar/ | grep -vP '(?<!debug)\.js' The -v reverses the match, printing lines that don't match the pattern and the -P enables Perl Compatible Regular Expressions which let us use negative lookbehinds. This particular regex, will match .js that is not ...


2

I think I would've done this using find but just to help answer your scripting questions I've modified your example slightly. #!/bin/bash for d in *; do # First level i.e. 2014, 2013 folders. regx='^[0-9]+$' # Regular Expression to check for numerics. echo "dir: $d" if [[ $d =~ $regx ]]; then # Check if folder name is ...


4

You can use bash extended globbing for this: shopt -s extglob DIR_UPLOADS=/home/html/wp-content/uploads/ cd ${DIR_UPLOADS} for dir in $PWD/+([0-9])/+([0-9]); do cd "$dir" && for file in *; do echo 'Compress Image' done done From the man page: +(pattern-list) Matches one or more occurrences of the given patterns So putting a ...


0

I suggest you the following bash script : #!/bin/bash FIRST=1 unset TARFILE unset FILESET find . -name '????_??_??_*.txt' | sort | while read fn do CURTARFILE=`echo $(basename $fn)|awk -F_ '{print $1"_"$2"_"$3".tar.gz"}'` if [ "$CURTARFILE" == "$TARFILE"] ; then FILESET=$FILESET" \"$fn\"" FIRST=0 continue fi [ ...


2

This is very simple: tar -cvzf 2014_04_01.tar.gz 2014_04_01_??.txt Update To do this for multiple dates (GNU find): find . -maxdepth 1 -name '????_??_??_??.txt' | cut -d_ -f 1-3 | sort -u | while read date; do tar -cvzf "$date".tar.gz "$date"_??.txt done


2

The glob pattern or regular expression [ -~] matches all printable characters in the C locale: this matches all characters from 32 (space) to 126 (tilde). In a locale other than C (more precisely, if LC_COLLATE is not C), if the application is locale-aware, this may match other characters. Another way to write this pattern is [[:print:]]. However, this ...


14

The problem is, you didn't quote your -name parameter. Do this instead: find . -name '*.java' Explanation Without the quotes, the shell interprets *.java as a glob pattern and expands it to any file names matching the glob before passing it to find. This way, if you had, say, foo.java in the current directory, find's actual command line would be: find . ...


2

tar will do this for you really fast. TEST First I created 2 directories and 10 files: % mkdir test1 test2 ; cd test1 % for n in `seq 1 10` ; do touch ABC.file$n ; done % ls > ABC.file1 ABC.file2 ABC.file4 ABC.file6 ABC.file8 > ABC.file10 ABC.file3 ABC.file5 ABC.file7 ABC.file9 Then I copied them: % tar -cf - ./* |\ tar -C../test2 ...


1

In zsh, put the following lines in your .zshrc: autoload -U zmv alias zmv='noglob zmv' alias zcp='zmv -C' alias zln='zmv -L' Then, on the command line, you can run zcp 'ABC(.*)' 'DEF$1' or simply zcp -W ABC.* DEF.* In another shell, as long as you have zsh installed: zsh -c 'autoload zmv; noglob zmv -CW ABC.* DEF.*'


2

If you don't mind using a less standard tool, I recommend using mmv (mass move) which was written for this very kind of tasks. Using mcp (mass copy), which is part of the suite, you could simply do mcp "ABC.*" "DEF.#1" It's not exactly easy to find download packages. The current Debian package (which Arch also uses in AUR) to compile at home can be found ...


0

You could do this: for i in ABC.*; do cp {ABC,DEF}."${i#*.}"; done


4

To do this efficiently with a large number of files, it is better to avoid a starting a different cp process for each one. One way would be to copy then rename them using prename (rename is symlinked to this by default on Debian based distros). Using this and the Linux mktemp: tmp=$(mktemp -d --tmpdir=.) cp ABC.* "$tmp" prename "s:$tmp/ABC:DEF:" "$tmp/"* ...


15

How about something like this in bash: for file in ABC.*; do cp "$file" "${file/ABC/DEF}";done you can test it by putting echo in front of the cp command: for file in ABC.*; do echo cp "$file" "${file/ABC/DEF}";done


4

To match repeating extensions, with zsh: rm -- *.*.*(e{'[[ $REPLY:t =~ "(\..*)\1$" ]]'}) Recursively: rm -- **/*.*.*(e{'[[ $REPLY:t =~ "(\..*)\1$" ]]'}) That would match a.php.php and b.x.x and c.x.y.x.y (and .php.php). With ksh93: rm -- *@(.*)\1 Recursively: set -o globstar rm -- **/*@(.*)\1 With GNU find, recursively: find . -regex ...


1

Try this at the root of your directory where you want to delete the files: find . -name "*.php.php*" -exec rm '{}' \;


4

rm -- *.php.php this will delete all files that have more than one php extension for all sub directories you need find /scripts/tmp -name "*.php.php" -exec rm {} + /scripts/tmp is the directory under which my files and subdirectories existed



Top 50 recent answers are included