Tag Info

New answers tagged

3

I don't think that's true. The shell is the one interpreting the command line arguments and passing them to the corresponding commands as it (the shell) is parsing them. So your C program, when it finally get's executed will only see the arguments 1, 2, and 3. The pipe and everything after is the responsibility of the shell, and will not get passed in as ...


1

With GNU find (i.e. under non-embedded Linux or Cygwin), you can use -regex to combine all these -path wildcards into a single regex. find . -regextype posix-extended \ -type d -regex '\./(\..*|Music|Documents)' -prune -o \ -type f -regex '.*(\.(bck|bak|backup)|~)' -print0 | xargs -0 --no-run-if-empty trash-put With FreeBSD or OSX, use -E ...


1

As far as I know, there is no option to tell find to read patterns from a file. An easy workaround is to save the patterns I want to exclude in a file and pass that file as input for a reverse grep. As an example, I have created the following files and directories: $ tree -a . ├── a ├── .aa ├── .aa.bak ├── a.bck ├── b ├── .dir1 │   └── bb1.bak ├── dir2 │ ...


0

This seems to be more a shell question than a find question. With a file containing ( -name dir1 -o -name dir2 ) -prune (no "\"!) you can simply do this: find ... $(< /path/to/file) Without changing the find call itself (to eval find or by changing $IFS) this works with paths without whitespace only, though. If you want to keep the file simpler you ...


6

Since you're working in bash, use an array. excludes=() excludes+=('--exclude=/path/*') … tar -czf backup.tgz "${excludes[@]}" If you have an optional entry in some variable, add it in a conditional. if [[ -n $exclude_or_empty ]]; then excludes+=("$exclude_or_empty"); fi


6

tar -czf backup.tgz "$exclude1" "$exclude2" ${exclude3+"$exclude3"} 2>&1 ${exclude3+"$exclude3"} expands to nothing, if $exclude3 is unset, and to "$exclude3", if it is set. (and similarly for the other variables that are potentially unset.) Note that there is a difference between an unset variable and a variable that is set to the empty string, ...



Top 50 recent answers are included