7
votes
Accepted
Zsh: Copy or Move symlinks to regular files, but not symlinks to directories (or vice versa)
Use the - qualifier for the following qualifiers to apply after symlink resolution, combined with @ (before the -!) to test for symlinks.
cp -- *(@-.) /symlinks/to/regular/files/
cp -- *(@-/) /...
6
votes
BASH - Find file with regex - Non-recursively delete number-only filenames in directory
No need for regexps,
LC_ALL=C find . ! -name '*[!0-9]*' -type f -delete
Non-recursively (and that applies for all find commands below), add -maxdepth 1 if supported, or change to:
LC_ALL=C find . ! -...
3
votes
Find and delete files from unix directory of multiple patterns
I find it puzzling that you need to find them and delete them. It would seem sufficient to simply delete them. The rm command does "the finding" for you:
rm -- *_bkp *_backup *_bak.csv
If ...
3
votes
Find and delete files from unix directory of multiple patterns
I would use find for this:
$ find . -iname '*_backup' -o -iname '*_bkp' -o -iname '*_bak.csv'
./A001.txt_bkp
./A003_bak.csv
./A002.csv_backup
Here the . parameter means "from the current ...
3
votes
Find and delete files from unix directory of multiple patterns
With bash modern shell:
printf 'rm %s\n' *@(bkp|backup|bak)*
Replace printf 'rm %s\n' with rm, when happy with the output.
This use extglob capability.
Extended globs: shopt -s extglob allow you to ...
3
votes
gnu grep multiple filters in one regex
The command you can use is:
cut -f1 -d: .pgpass | grep -E '^FISP.*(CDS|TAP).*PGS401'
The will search for (regex) ^FISP.*CDS.*PGS401 or ^FISP.*TAP.*PGS401
Here is the result of execution, based on the ...
1
vote
gnu grep multiple filters in one regex
I'd try using \ to flip the "special" state* of your ()|s. You can do it like this:
grep '^FISP\(CDS\|TAP\)PGS401'
"special" state: prefacing a character with \ flips it from &...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
wildcards × 1222bash × 456
shell × 311
shell-script × 132
zsh × 128
files × 98
find × 96
ls × 87
regular-expression × 70
command-line × 66
grep × 64
quoting × 64
filenames × 63
linux × 42
rm × 34
directory × 30
rsync × 26
cp × 24
awk × 23
tar × 23
pattern-matching × 23
sed × 22
scripting × 19
rename × 19
recursive × 19