Globbing means matching files by name patterns containing wildcards.

learn more… | top users | synonyms (2)

1
vote
2answers
490 views

Way to write new filename on wildcard input?

I have some experience with Inix terminals from science internships I've been part of, mainly using a few utilities like grep, awk, and sed but there is one thing I've been trying to figure out for a ...
3
votes
2answers
550 views

How to copy multiple files but keep their extensions the same?

I am looping through a number of files, and $file represents the current file. How can I make copies or renames and keep the extension the same for this current file? e.g. if $file = x.jpg How to ...
0
votes
4answers
946 views

How to rotate all images in a directory with imagemagic?

I want to rotate all the images in a directory that match a pattern. So far I have: for file in `ls /tmp/p/DSC*.JPG`; do convert $file -rotate 90 file+'_rotated'.JPG done but that gives no ...
0
votes
1answer
56 views

Does wildcarding significantly hurt BIND Performance?

I have enabled RPZ on my BIND 9.9.4 DNS server and I wanted to be able to wildcard some records in my RPZ zone, but I am afraid of the performance hit this might cause. Does anyone out there have some ...
2
votes
1answer
165 views

Why is `find -name *.jks` not returning some files? [duplicate]

find . -name *.jks -print 2>/dev/null returns files of extension jks that do not have underscores as part of their name. Much to my surprise, I have just discovered that * does NOT substitute ...
5
votes
2answers
597 views

Copy all dotfiles except for `.git` and `..`

I am aware of using .[!.]* to refer to all dotfiles in a directory with the exception of .., but how might one refer to all dotfiles except for .. and .git? I have tried several variations on ...
28
votes
1answer
1k views

Does 'rm .*' ever delete the parent directory?

The expression .* is expanded by bash to include the current and parent directories: $ ls -la total 2600 drwxrwxrwx 2 terdon terdon 2162688 Sep 10 16:22 . drwxr-xr-x 142 terdon terdon 491520 Sep ...
2
votes
2answers
125 views

Discrepancy between the two expansions

If you input the command ls * and echo *, you will notice the remarkable discrepancy between the results. The former recursively includes while the latter totally excludes files in subdirectories. ...
3
votes
4answers
1k views

cp hidden files with glob patterns

Situation : $ mkdir foo && touch foo/.test $ cp foo/* . zsh: no matches found: test/* (or bash : cp: cannot stat ‘test/*’: No such file or directory) I have a directory full of hidden ...
5
votes
1answer
114 views

“globbing” (*) comes from “global command”… Huh?

According to legend, in the early days what we now call "globbing" (i.e. using expressions like e.g. *.c, ./*.p?) was supported by one certain program /etc/glob, whose name in turn derived from ...
3
votes
4answers
2k views

How do I select files in a bash script that do not have an extension?

Let's say I have files xinitrc, alphabetsoup, ieat.pie in the current directory. Need a bash script to select only xinitrc and alphabetsoup.
2
votes
4answers
3k views

Shell script to check for the presence of one or more files with a specific extension?

I want to write a script to find a file with specific extension.this much i have done: #!/bin/bash file="/home/Savio/Dsktop/check/*.csv" file1="/home/Savio/check/*.txt" if [[ -f "$file" && -f ...
3
votes
1answer
116 views

watch command to delete files in a directory every N secs

I thought of using watch command to delete files in a directory every N seconds with the command running in background. This is what I was planning to use: nohup watch -n1200 rm -rf ...
8
votes
5answers
3k views

cp with a single argument containing wildcards [duplicate]

If I have the following 2 files and 1 folder: someuser@computer:~/Desktop/test$ ls -l total 340 -rw-r--r-- 1 someuser someuser 45082 ago 5 09:56 file1.pdf -rw-r--r-- 1 someuser someuser 291836 ago ...
4
votes
1answer
3k views

delete files matching pattern

I need to recursively remove all files in all subdirs where the filename contains a number followed by an 'x' followed by a number, at least two times. Example: I'd want to remove these files: ...
15
votes
5answers
2k views

What does `mv ./*` without specifying destination do?

I accidentally forgot to specify destination before hitting the Return key. Where does mv ./* without specifying destination move the files and directories under current directory to?
3
votes
1answer
2k views

Using regex in ls and mv

I have a directory structure like this ├── UK │   ├── BuyBand_go_UK.png │   ├── BuyBand_go_UK.svg │   ├── BuyBand_K.png │   ├── BuyBand_K.svg │   ├── BuyBago_UK.png │   ├── BuyBago_UK.svg │   ├── ...
1
vote
1answer
217 views

The result of echo * and echo .*

Thereotically, the result of command echo * should be "Any file in the current directory". Should it include the dotfile? Similarly, Should the result of ls * include the dotfile?
2
votes
1answer
153 views

Curly Brace glob order?

If I have two files (in a folder with similarly numbered files) such as foo.18 foo.19 And I want to use a glob on them, do I do it like so: cp -r /folder1/*.{19,20} /folder2/ or like so? cp -r ...
14
votes
1answer
2k views

Delete all files starting with a question mark

I have a folder in which I have around 4k files. Some of these files start with a a ? or ! character. I need to delete them but can't find an expression that would do so: rm -f ./?* just deletes ...
9
votes
2answers
346 views

What is the difference between “*.pl” and *.pl in grep? Why does quoting change the result?

What is the difference between: grep "string" . -r --include *.pl and grep "string" . -r --include "*.pl" The latter includes files in subdirectoried while the former not. Why?
1
vote
1answer
441 views

Bash command that uses wildcard in place of folder to copy folder contents of multiple files into one directory?

I have a directory ~/dir that contains a bunch of random folders like: ~/dir/av 801 and ~/dir/lm 320. I want to copy the contents of every inner folder (ie: av 801) into a different directory. The ...
2
votes
2answers
962 views

How do I run a command on multiple files

This is pretty basic, I have a folder with several subfolders of JS files and i want to run Google's Clojure compiler on all of the files in those folders. The command to process a single file is as ...
3
votes
1answer
131 views

How to use parameter substitution in glob pattern (zsh)

I want to process a bunch of files ending in some suffixes, so I wrote the following zsh script but it did not work. EXT=(.jpg .png .gif) EXT=${(j.|.)EXT} # EXT becomes '.jpg|.png|.gif' for f in ...
1
vote
1answer
238 views

I quite like mercurial .hgignore-style globbing. Is there a Linux shell that supports it?

I quite like mercurial .hgignore-style pattern globbing. Globs are rooted at the current directory; a glob such as *.c will only match files in the current directory ending with .c. The ...
3
votes
3answers
335 views

What exactly did mv /tmp/folder/* /* do to my filesystem?

It's hard to search for special characters on google, which is why I'm posting this here. I recently ran (as root) a mv /tmp/folder/* /* when I meant to run mv /tmp/folder/* ./ Big mistake! Things ...
6
votes
3answers
9k views

Test if there are files matching a pattern in bash

I am trying to write an if statement in bash to test whether there are any files matching a certain pattern. If there is a text file in a directory it should run a given script. My code currently if ...
6
votes
5answers
5k views

In linux, how to delete all files EXCEPT the pattern *.txt?

I know how to delete all txt file under current directory by rm *.txt. Does anyone know how to delete all files in current directory EXCEPT txt file?
4
votes
2answers
312 views

Sort files by modification time

I've seen many questions and answers here using a construction along the lines of list_dir=`ls -t /path/to/dir/` for i in $list_dir; do or ls -t | while read i; do Now, I know that you shouldn't ...
14
votes
4answers
7k views

rm -rf all files and all hidden files w/o . & .. error?

rm -rf /some/path/* deletes all non-hidden files in that dir (and subdirs). rm -rf /some/path/.* deletes all hidden files in that dir (but not subdirs) and also gives the following error/warning: ...
2
votes
3answers
1k views

ffmpeg -pattern_type glob — not loading files in correct order

I have a dilemma.. I've had a script for a while now that downloads pictures from a webcam every few minutes. The naming convention just does new_image((len(files(dir))+1) + '.jpg') and that's all ...
5
votes
2answers
164 views

Passing glob expressions to functions/scripts

The following script is supposed to concatenate multiple csv files in a path specified in the first argument into a single csv file specified in the second argument #!/bin/zsh set -x set -v ...
3
votes
2answers
333 views

How do I let bash autocomplete wildcards?

If I have directory containing the files foo.bar.a.cat foo.bar.a.hat and I type ls f+TAB the bash shell autocompletes to ls foo.bar.a.. If I type ls *bar*+ TAB I would like it to autocomplete to ...
30
votes
7answers
3k views

why does ls -d also list files, and where is it documented?

when specifying ls --directory a* it should list only directories starting with a* BUT it lists files AND directories starting with a Questions: where might I find some documentation on this, ...
3
votes
4answers
171 views

Expansion with numbers in human readable format

So, I want to play some MP3s in a console player that takes file names as inputs. I have the following files, as given by ls -1 * where * get expanded by my shell (zsh): 1 - Main title.mp3 10 - End ...
2
votes
3answers
547 views

Very strange behavior with grep and IFS

I'm having trouble using grep, the returned results are "n-empty", I mean without the 'n' character... This is the script sample : OLDIFS=$IFS IFS="\\n" i=$(grep -ril $1 *) echo $i IFS=$OLDIFS ...
2
votes
2answers
81 views

“or” in shell glob

I want to ls the files containing the substring "s1r", "s2r", "s3r" or "s19r" in their filenames. I'm almost there! Botched attempts: ls *s[123][9?]r* The above gives me only files including the ...
5
votes
2answers
165 views

Modifying zsh globbing patterns to use with cp

I'm trying to write a script to copy files recursively from a particular folder except files A.extn, B/*.extn and C/* where B and C are directories and extn is just some generic extension. This is ...
4
votes
3answers
271 views

Why should 'Character Classes' be preferred over 'Character Ranges' In Shell (Bash)?

The Linux Command Line (Book - page count 47) says: ... you have to be very careful with them [character ranges] because they will not produce the expected results unless properly configured. For ...
0
votes
2answers
100 views

Supress expansion of * in echo

I am working on a script which dynamically executes some queries on daily basis. These queries are coming from a table in the database. Here is the sample output of the query table: ...
2
votes
2answers
1k views

Excluding a directory name in a zsh recursive glob

I'm running zsh on Linux under setopt extended_glob ksh_glob glob_dots. I'm looking for something easy to type on the command line, with no portability requirements. I'm looking at a source code tree, ...
2
votes
6answers
1k views

How to make tar globbing work with the 'change directory' option

I have the followin directory structure: base/ files/ archives/ scripts/ I want a script to run from scripts/, compress files that match results.*.log in files/ into a gzipped tar archive ...
0
votes
3answers
488 views

How to find files ending with ~ and pyc? [duplicate]

I want to find all files (in current and all subdirectory) which end in'~' or 'pyc'. To do so I have tried the following find pattern: find . -name '*{~,pyc}' find . -name '{*~,*.pyc}' but neither ...
9
votes
5answers
520 views

Can I select only one result from a bash glob?

I'm trying to write a script for work to automate some reporting on an output. The Log files are (currently, it's being 'standardise' in the future) stored in this sort of path structure: ...
4
votes
4answers
1k views

How to remove files which do not end with “.c”?

I have a directory which contains all the C programs. I have also compiled them at the creation time so as to check my code. There are a lot of programs nearly 100 of them. So I want a BASH script ...
3
votes
1answer
516 views

Shell wildcards and dot files

I am a beginner terminal user trying to understand wildcards. I think I pretty much have a good grasp on it, but I have a couple of questions: Why do the following two codes work as expected: ls -d ...
1
vote
3answers
543 views

What does a question mark in a filename matching pattern mean?

What does the question mark in this command mean? find . –type d –name "?d*" –print I tried to to run it without it but didn't notice any change.
2
votes
3answers
114 views

Filter a list of strings using math

I have a directory with files listed like so: abc201303130110.txt abc201303140511.txt abc201303150112.txt As you can see, the filename contains a datetime stamp. I want to return all files with the ...
2
votes
2answers
563 views

Working of rm/ls with [0-9]

I am learning the shell commands and came across the short tags eg.[0-9],[[:digit:]] etc.. As a proof of concept i tried deleting all the files with the rm command(i know its not a good practise but i ...
0
votes
1answer
260 views

Working of the [0-9] [duplicate]

I am learning the shell commands and came across the short tags eg.[0-9],[[:digit:]] etc.. As a proof of concept i tried deleting all the files with the rm command(i know its not a good practise but i ...