Tag Info

Hot answers tagged

3

You could use find, provided it's available: $ find "/mac1/2014-08-31-173253/Macintosh HD" -wholename "*/Users/me/*.txt" -or -wholename "*/Users/me/*.csv" This will search /mac1/2014-08-31-173253/Macintosh HD for files containing the pattern */Users/me/*.(txt|csv) in their paths.


2

find . -iname foo.txt -exec ls -t "{}" \+ | head -n 1


2

find -type f -name "*-thumb.png" -exec rm {} \; If you need a prompt to confirm deletion, use -ok in place of -exec as: find -type f -name "*-thumb.png" -ok rm {} \;


2

find is finding your files twice: in the place where they started, and where you moved them to. That means it ends up running: mv -i 3DBGB_run/x.template 3DBGB_run/x.template and produces the error you see. find sees files "live" as it goes - it doesn't build up a list in advance and then run the command for everything in the list. The order that it ...


1

You should avoid search in target directory. So you can add ! -path $TARGET_DIR as for example: find . -name '*.template' ! -path "*3DBGB_run/*" -exec mv -it ./3DBGB_run {} \+


1

find . -iname foo.txt -printf '%CYmd %p%f' | sort -n -t ' ' -k 2 | head -n 1


1

With zsh: setopt extendedglob # best in ~/.zshrc ls -ld -- <126-253>(*.po~[0-9]*) Recursively, including in hidden dirs and only regular files: ls -ld -- **/<126-253>(*.po~[0-9]*)(D.) use zargs if you run into the arg list too long error.


1

Try: find -iname "*.txt" -exec sh -c 'for f do basename -- "$f" .txt;done' sh {} + Your first command failed, because $(...) run in subshell, which treat {} as literal. so basename {} .txt return {}, your find became: find . -iname "*.txt" -exec echo {} \; which print file name matched.


1

This is not work for sed, unless you are a glutton for punishment. At least in a more general case, where the beginning of the block is more then one line (or whee the tags are split across several lines, which is well possible in XML/HTML). If you really must do this with anything else than an XML parser (yes, either fixing the input or cutting out the ...


1

If you want to put aaa section from before bbb just after it: sed -i '/<div class="aaa">/{ :1 /<\/div> <\!-- end aaa -->/!{N;b 1} /<\/div> <\!-- end aaa -->/{N;h} d} /<\/div><\!-- end bbb -->/{n;G}' *html


1

Before you delete directories, you could delete files. ie first run: find . -name "DIR-NAME" -type f -delete Might not work if you have special file types.



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