Globbing means matching files by name patterns containing wildcards.

learn more… | top users | synonyms (2)

6
votes
2answers
363 views

What is the setting in bash for globbing, to control whether * matches dot files

I was surprised recently when I did something like mv ./* ../somedirectory and found that files like .gitignore were not moved. I do most of my work in zsh on OS X, and this surprise bit me in bash ...
6
votes
2answers
203 views

Why two almost idetical grep commands return different output: w/o and with filename

I have 2 almost identical greps: [Alex@localhost tmp]$ grep /bin/bash /etc/passwd root:x:0:0:root:/root:/bin/bash AlexL:x:500:500::/home/AlexL:/bin/bash user1:x:501:501:user1 ...
6
votes
1answer
4k views

What is the .gitignore pattern equivalent of the regex (Big|Small)(State|City)-[0-9]*\.csv

I have a regex I stuck in my .gitignore similar to: (Big|Small)(State|City)-[0-9]*\.csv It didn't work so I tested it against RegexLab.NET. I then found the gitignore man page which led me to ...
6
votes
2answers
914 views

ZSH: Recursive globbing with .directories

I thought the glob pattern: **/(*|.*) would represent every folder and file starting with dot (.) or not, but it skips directories in the current directory that start with .. What is the glob ...
6
votes
2answers
405 views

Remove all Vim undo files in all but one directory

I just realized that I have tons of Vim undo (.un~) files sprinkled around my file system. I'd like to delete all of these files except in one directory—~/.tmp. My first problem is that I can't seem ...
6
votes
3answers
370 views

Remove all but one ( or more ) kind of filetype

I've been trying to find a command to remove all files in a folder but not a kind of filetype. But I seems to not have any luck. What I've tried so far : set extended_glob rm !(*.dmg) # this returns ...
6
votes
2answers
1k views

Multidigit ranges of files in lexicographical order in zsh

I would like to specify a range of files (in lexicographical order) with two integers (e.g. 2 to 57) in zsh by globbing. For example: "pick the files 2 to 57 in lexicographical order under the path ...
6
votes
1answer
320 views

Can I have my shell history record how wildcards expanded?

If I run: $ ls * foo bar buzz $ history | tail -1 ls * You can see that in my shell history it remembers that I ran ls * rather than ls foo bar buzz. Ideally, I'd like to record both in separate ...
6
votes
1answer
161 views

Cannot expand asterisk without proper permission

Can someone explain to me the following? $ ls -ld /temp/sit/build/ dr-xr-s--- 3 asdf qwer 4096 Jan 31 2012 /temp/sit/build/ $ ls -ld /temp/sit/build/* ls: /temp/sit/build/*: Permission denied So ...
5
votes
5answers
4k 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?
5
votes
2answers
1k views

Why doesn't “rm *” work when there are files that begin with a hyphen?

from: http://seclists.org/fulldisclosure/2011/Sep/190 [USER@MACHINE ~] mkdir ejha [USER@MACHINE ~] cd ejha/ [USER@MACHINE ~/ejha] touch ize [USER@MACHINE ~/ejha] touch -- -f -i [USER@MACHINE ...
5
votes
4answers
620 views

Avoiding errors due to unexpanded asterisk

In bash I often use for-loops such as the following for file in *.type; do sommecommand "$file"; done; to perform an operation for all files matching *.type. If no file with this ending is ...
5
votes
5answers
395 views

How to search in specific files matching a pattern

How can I find a word in specific files matching a pattern. e.g. searching for version in CMake* files recursively found in the current directory.
5
votes
4answers
4k views

Find a string only in a specific file inside subdirectories

Let's say I need to find the function GetTypes() in all C# source file (.cs) the directories/subdirectories. I used grep -rn GetTypes *.cs, but I got an error with grep: *.cs: No such file or ...
5
votes
3answers
326 views

“mkdir foo; svn mv * foo”

I often want to do some variant of this idiom: $ mkdir 2010 $ svn mv * 2010 Of course, I get an error because the glob matches 2010 as well: svn: Cannot copy path '2010' into its own child ...
5
votes
3answers
919 views

Create symbolic links to files using wildcards

I want to create symlinks to multiple files: ln -s dev-*.php 's/dev-(.*\.php)/$1/' Results hoped for: site.php links to dev-site.php file.php links to dev-file.php What's the most ...
5
votes
4answers
204 views

is the behaviour of .* to include . and .. defined in LSB or POSIX or some other specification?

as title: is the behaviour of .* to include . and .. defined in LSB or POSIX or some other specification?
5
votes
3answers
393 views

Linux command to return all files that start with TEMP but do not end with double digits

What is the Linux command to return all files that start with TEMP but do not end with double digits? I think it should look something like this: ls -l TEMP*[!0-9][!0-9] but the results of my ...
5
votes
4answers
359 views

Check if a folder has a certain type of file present

How could I check if a file has a file of extension .java? So far I have: for javaFile in *.java ; do { echo "The file $javaFile has : " >> ~/Desktop/externalServers.txt ...
5
votes
2answers
355 views

How does GLOBIGNORE work?

According to bash's manual page: GLOBIGNORE A colon-separated list of patterns defining the set of filenames to be ignored by pathname expansion. If a filename matched by a ...
5
votes
1answer
2k views

The best way to expand glob pattern?

I need to expand a glob pattern (like ../smth*/*, or /etc/cron*/) into a list of files, programmatically. What would be the best way to do it?
5
votes
1answer
107 views

Bash globbing: how to express “something-*.txt except *-foobar.txt” as glob?

On the command line, can I express easily in terms of shell globs that I would like to catch all files something-*.txt, except for something-*-foobar.txt? If I can, how? NB: I know how to achieve the ...
5
votes
2answers
756 views

How to put the specific files from a directory in an array in bash?

Suppose I have a directory under which there are 3 files named: file1.txt,file2.txt and file3.txt. Now how can I fill an array with those file names(I just know that all the files have certain ...
5
votes
3answers
473 views

Get a list of 3 letter commands on Mac OS X

How can I either create or find a list of 3-letter unix commands on Mac OS X? I'd like to create a new program/command for a project. I'd like to make it a 3-letter name, but I don't want to conflict ...
5
votes
3answers
889 views

Glob with Numerical Order

I have this list of pdf files in a directory: c0.pdf c12.pdf c15.pdf c18.pdf c20.pdf c4.pdf c7.pdf c10.pdf c13.pdf c16.pdf c19.pdf c2.pdf c5.pdf c8.pdf c11.pdf c14.pdf c17.pdf c1.pdf ...
5
votes
2answers
93 views

ls command: how to ignore case without globbing

I use the shopt -s nocaseglob command to ignore case, but it seems like it doesn't work if I use a string without glob. Just a question out of curiosity, is it possible to ignore case without ...
5
votes
2answers
538 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 ...
5
votes
2answers
520 views

How can I make bash not match `.` and `..` with `.*`

When I try to match all dot files in a directory with .* it seems to have a nasty side-effect: besides matching all (real) files and directories, it matches . and ... bash-3.2$ mv test/.* dest/ mv: ...
5
votes
2answers
1k views

Remove unknown unicode character from textfiles - sed, other bash/shell methods

I need to search and replace all occurences of an unknown character in some files having the same name. Opening such files with vi, I read <91> code for that character. Opening them with nano, I ...
5
votes
1answer
5k views

Listing with `ls` and regular expression

How can I list files with a filename ending with last character and with .txt extension ? I have tried ls *+([[:digit:]]).txt but this is true for abc12.txt and abc2.txt. But I need to get only ...
5
votes
1answer
112 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 ...
5
votes
2answers
156 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 ...
5
votes
3answers
524 views

Bash globbing of multi-part argument

Below are some examples of a find command I'm trying to run. I'm looking for different ways that I might be able to use globbing to generate (as an example) a find command with predicates joined ...
5
votes
2answers
611 views

ls, regexp and environment variable

I wanted to declare an environment variable that stocks all the extensions of video files so I can use it when using the shell. I tried several things but never got it to work: If in my .bash_profile ...
5
votes
2answers
158 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
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 ...
4
votes
5answers
316 views

Bash pattern to match all files but directories

In bash, how do I specify a pattern that matches everything but subdirectories in current directory. Given that the pattern */ matches all the subdirectories, I tried (with extglob turned on): $ echo ...
4
votes
3answers
2k views

Using OR patterns in shell wildcards

Contents of my dir are $ ls -lrt total 0 -rw-r--r-- 1 user1 admin 19 Oct 8 12:31 night.txt -rw-r--r-- 1 user1 admin 19 Oct 8 12:31 noon.txt -rw-r--r-- 1 user1 admin 38 Oct 8 12:31 day.txt I ...
4
votes
4answers
546 views

How to exclude some files not matching certain extensions with grep?

I want to output all lines containing the word OK recursively from a directory. But there are a few extensions which I need to exclude from the result: *~ *.map *.js except *.debug.js I tried: ...
4
votes
1answer
888 views

Why is my find not recursive?

I am running the following command, but it is not performed recursively: find . -name *.java I know there are java files further down in the current directory but it is performing the find on the ...
4
votes
2answers
4k views

How can I search a wild card name in all subfolders?

How can I search a wild card name in all subfolders? What would be the equivalent of DOS command: dir *pattern* /s in *nix?
4
votes
3answers
2k views

Why does tar --exclude=“.*” create an empty archive?

Everything I read says that to exclude .svn and .htaccess and other hidden files when creating a tar archive, use the --exclude=".*" pattern. When I try, I get an empty archive. When I leave out the ...
4
votes
2answers
216 views

Why 2 linux machine behave differently with command of the same syntax?

I am using 2 machine , which is both Red Hat Enterprise Linux AS release 3 (Taroon Update 2) ( I check it in /etc/*-release ). I checked they are using the same default shell by ps -p $$, which is ...
4
votes
2answers
761 views

mv on a glob pattern does not work without sudo

I am using MySQL database on Ubuntu machine. My MySQL data directory is /var/lib/mysql/ , since I have a database named "db_test" , so, I have a directory named db_test/ under /var/lib/mysql/ . And ...
4
votes
3answers
5k views

checking an argument to a bash script is a string of all digits

The Bash FAQ says If you're validating a simple "string of digits", you can do it with a glob: # Bash if [[ $foo = *[!0-9]* ]]; then echo "'$foo' has a non-digit somewhere in it" else echo ...
4
votes
2answers
502 views

Get the complement of the result of an ls command

Let's say I have a directory with multiple files, all of which are either binary files (files with no declared extensions) and source files (.c extension). I do this: $ ls and get: README.md ...
4
votes
3answers
300 views

How to pipe to multiple places with vertical bar?

I have a folder full of files with a .dot extension like this: a.dot b.dot c.dot I want to go through all the files in this folder and run a command on them such as this: dot -Tpdf a.dot -o a.pdf ...
4
votes
2answers
271 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 ...
4
votes
1answer
720 views

How do I filter a glob in zsh

Basically I can use a glob in zsh to a list. Often, it turns out, I would like to filter that list, grep'ishly I'm wondering though, if I need to do that. Does zsh have a method to filter a list? ...
4
votes
4answers
521 views

Find files without a number

I am trying to write a simple script that will iterate through all drives except sda. Right now I have this for i in $(find /dev/ -name "sd*" ! -name "sda*") do echo $i done However this ...