Globbing means matching files by name patterns containing wildcards.

learn more… | top users | synonyms (2)

0
votes
2answers
86 views

find: meaning of the \? sign as a value of the name parameter

What is the meaning of the ? sign in the following command? find /foo/path -name \?
6
votes
4answers
411 views

How can I use '*' to capture everything with exceptions

For example, I have files named A_1.txt A_t_1.txt A_ts_1.txt A_tsa_1.txt in a directory ~/admin/packages/. I am building a for loop to by globbing to A_1.txt for f in ~/admin/packages/*_1.txt ...
0
votes
2answers
21 views

Listing numbered files using wildcard sequence with predefined range

I have a folder of numbered data files. I am trying to incrementally extract a predefined range of files. The range of files that I am looking for is predefined in two variables, ns and ne, which ...
1
vote
1answer
79 views

pattern matching without echo

Why are the outputs different? touch a aa bb ccc echo * a aa bb ccc // I understood, * means matches zero or more * aa bb ccc // I'm confused. echo ? a //OK ? a aa bb ccc // confused ...
40
votes
5answers
2k views

Why is the wild card character * so different between commands zip and rm?

I put together a script to do some file operations for me. I am using the wild card operator * to apply functions to all files of a type, but there is one thing I don't get. I can unzip all files in a ...
20
votes
8answers
39k 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 ...
1
vote
1answer
61 views

Why grep on remote system says file or directory not available

I'm trying to run a grep command on remote system to give me the result for May 22. But reply comes /bin/grep: /var/log/Clients_Logs/127.0.0.1/*: No such file or directory But when I specifically ...
2
votes
3answers
54 views

Use a wildcard in directory path

I'm trying to write a bash script where part of a directory is a long, unknown string. I know the first part of the directory name. How do I combine the known string and the wildcard in the path? As ...
20
votes
1answer
1k views

Why is nullglob not default?

In most shells nullglob isn't the default. That means, for example, if you run this command ls * in an empty directory, it will expand the *-glob to a literal ' * ', instead to an empty list of ...
4
votes
3answers
288 views

Remove files by regular expression

I want to keep files whose names match [0-9A-Z]{1,2}_\d{4}_\w+?\.dat, for example, A1_2001_pm23aD.dat, K_1998_12.dat, and remove the rest. However, the ls and rm commands do not support such regexes. ...
7
votes
5answers
10k views

How to rotate all images in a directory with imagemagick?

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 ...
2
votes
3answers
35 views

echo all *.tex filenames in a specific directory

I have a directory structure like this: ├── lebenslauf │   ├── lebenslauf.out │   └── lebenslauf.tex ├── thirdPage │   ├── auto │   │   ├── test.el │   │   └── thirdPage.el │   ├── missfont.log │   ...
0
votes
1answer
35 views

globbing and wildcards

Are wildcards ever supposed to be expanded for a program that is not the first in the pipeline? Every example uses wildcard for the first program in the pipelilne. For example, the following does ...
1
vote
2answers
31 views

gunzip multiple files

I have a directory where there are multiple folders, each of folder contains a .gz file. How can I unzip all of them at once? My data looks like this List of folders A B C D In every of them ...
3
votes
6answers
9k views

Find files by the length of filename

I want to find all files by length of the file names. For example if I want to find files of length 1, such as a.go, b.go. I put: grep '.\{1\}' file But this does not work. What command can I use ...
1
vote
2answers
52 views

expand wildcards “inside a command” instead of in the shell

(This is a simplest working example of something in a much messier context.) I have a directory d with files 1.txt 2.txt 3.txt 4.wav. My current directory is somewhere else. ls d reports 1.txt 2.txt ...
1
vote
1answer
24 views

Bash capturing asterisk inside a file [duplicate]

I have a text file which contains an asterisk as the first character in every line, when I try to process the file in a script like this: while read line; do out=$(echo $line | awk '{ print $3 }') ...
33
votes
1answer
2k views

Why does my regular expression work in X but not in Y?

I wrote a regular expression which works well in a certain program (grep, sed, awk, perl, python, ruby, ksh, bash, zsh, find, emacs, vi, vim, gedit, …). But when I use it in a different program (or on ...
2
votes
1answer
64 views

How to delete files with ~?

I have removed all my python code from the home directory, but when I do ls I get: a11.py~ class1.pdf foobar.txt~ n1 pic.py~ When I do ls like this: ls *.py I get: ls: cannot access *.py: No ...
1
vote
1answer
48 views

Globbing error due to whitespace

My directory variable POSTMAP="/work/Documents/Projects/untitled\ folder/untitled\ folder/*/*_tsta.bam" My for statement: for file0 in ${POSTMAP}; do ... It seems that the whitespace in ...
69
votes
7answers
69k views

How do you move all files (including hidden) from one directory to another?

How do I move all files in a directory (including the hidden ones) to another directory? For example, if I have a folder "Foo" with the files ".hidden" and "notHidden" inside, how do I move both ...
7
votes
4answers
813 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 ...
7
votes
1answer
1k views

Why does `grep fil*` fail?

I found echo file|grep fil* fails, but echo abcd|grep abc* succeeds. I don't understand it, can someone explain? Thanks
1
vote
4answers
3k views

How do I suppress error messages from cp?

I am currently looking ways to suppress error command in Linux, in particular, the command cp. I do: root@ubuntu:~$ cp /srv/ftp/201*/wha*/*.jj ~/. cp: cannot stat `/srv/ftp/201*/wha*/*.jj': No ...
2
votes
1answer
32 views

alias ? not working in zsh

I was lead to believe that there were no differences between aliases in zsh and bash, however that appears to not be the case. I had an alias that would help me familiarize myself with the command ...
4
votes
3answers
996 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 ...
3
votes
2answers
75 views

Why does ls .* show different files than ls ./.*?

Blank file .ignoramus in current directory exists. bojan@localhost:~$ echo $GLOBIGNORE .ignoramus bojan@localhost:~$ ls .* | grep ignor bojan@localhost:~$ ls ./.* | grep ignor ./.ignoramus tools ...
7
votes
2answers
3k views

zsh: excluding files from a pattern

Say I have the following files: |-- bar `-- foo |-- type_A_1 |-- type_A_2 |-- type_B_1 |-- type_B_2 |-- type_B_xx |-- type_B_xx `-- something_else I thought the ...
2
votes
1answer
2k views

rsync specific directories

Below are the directories of my directory structure. I only want to run rsync on the content under the archive directory of any subdirectory and exclude everything else: ./ ap/ ap/aploader/ ...
3
votes
1answer
125 views

Is it dangerous to always have extglob on?

If I turn extglob on to do things like shopt -s extglob rm !(*.html|*.txt) # remove everything except html and txt files Is it unwise to keep extglob on after this? Are there any caveats of having ...
5
votes
1answer
58 views

Bash script single-quotes parameter with globbing value

I'm trying to write a code search script, with configurable directories and files that are excluded. The main part of this script is the following line: out=$(grep -TInr$C$W --color=always \ ...
1
vote
6answers
60 views

Is there any reason to double-check the `find -type -f` results with `-f` bash operator?

In this blog I found a bash script ("Snippets" section) which contains following structure to source individual files from .bash_profile: if [ -d ~/.bash_profile.d ]; then for file in $( find ...
3
votes
2answers
47 views

Iterating over glob patterns, not the files in them

I would like to perform the same aggregation operations on each of several bunches of files where each bunch is matched by one glob pattern. What I would not like to do is pipe each file name into the ...
0
votes
1answer
35 views

linux - setting order in which files are read or output with utilities (sorting)

I'm having issues with programs reading files in the wrong order, and also outputting in an undesirable order with utilities such as ls. I've tried some of the LC_COLLATE options, but none of them ...
0
votes
3answers
57 views

why “ls *bash*” doesn't show the .bashrc file [duplicate]

I cd to my home directory and typed ls *bash* expecting it will show a list of files contains "bash". However it is not. While, typing ls .bash* works. According to the documentation, * ...
4
votes
1answer
57 views

What is the sort order when using conditional operators?

I wrote a bash script that processes a list of filenames (using glob expansion, as in for f in *) and then outputs a subset of this list to a file. Subsequently I read the content of this file into an ...
28
votes
5answers
42k views

rm -rf all files and all hidden files without . & .. 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: ...
24
votes
3answers
1k views

What is the difference between [[ $a == z* ]] and [ $a == z* ]?

Is there is any difference between these two. [[ $a == z* ]] and [ $a == z* ] Can I have an example where they would have different outputs? Furthermore, how does the working of [[ ]] differs ...
0
votes
1answer
13 views

How can I mix variables and wildcards in fish?

I have a value stored in a variable that I want to use as part of a wildcard, like this: set extension (somecommand) cp *$extension ~/filezone But the * prevents the variable from being ...
4
votes
3answers
4k views

Get the number of files that match a pattern in a directory and delete the oldest one

I'd like to do the following: Get the number of files in a given directory that match a given pattern, for example: ExtractBackup_{date}.tar.gz If that number is 2 or higher, delete the oldest file ...
12
votes
4answers
11k views

Bash script error with strings with paths that have spaces and wildcards

I am having trouble getting the basics of Bash scripting down. Here's what I have so far: #!/bin/bash FILES="/home/john/my directory/*.txt" for f in "${FILES}" do echo "${f}" done All I want to ...
8
votes
2answers
1k views

Why did mv delete a file with mv id_rsa *.old? [duplicate]

I wanted to backup my ~/.ssh/id_rsa to id_rsa.old, and it looks like it got deleted! How is this possible? :) root@localhost:~/.ssh# ls -l total 16 -rw------- 1 root root 3326 Mar 12 11:22 id_rsa ...
1
vote
3answers
338 views

Why can't unrar expand this expression?

I had three RAR files in the same directory: file1.rar, file2.rar and file3.rar. I wanted to extract them with one command using expansion, bearing in mind that asterisks have to be escaped in ...
4
votes
1answer
44 views

Deduplicating Bash Brace Expansions

Brace expansions can produce multiple instances of file names if there is an overlap in the matches. A simple example: mkdir testdir; cd testdir touch abcd for f in *{b,c}*; do something_to "$f"; ...
-1
votes
1answer
38 views

wildcard usage for a directory displaying filenames in linux?

so one of the questions i have been working on is to display the contents of a directory files by using its wildcards do display specific contents, in this case aim using ls and the portion that I got ...
28
votes
6answers
42k views

How to copy some, but not all files?

So, you can use the * as a wild card for all files when using cp within context of a directory. Is there a way to copy all files except x file?
0
votes
0answers
20 views

What does echo *? [duplicate]

Recently I was writing a bash-script and added a line: $ echo * and got an output of file names and directory names. What is the context of this list (just out of curiosity)?
40
votes
8answers
89k views

List only regular files (but not directories) in current directory

I can use ls -ld */ to list all the directory entries in the current directory. Is there a similarly easy way to just list all the regular files in the current directory? I know I can use find find . ...
25
votes
7answers
35k views

How to match case insensitive patterns with ls?

I would like to list all files matching a certain pattern while ignoring the case. For example, I run the following commands: ls *abc* I need to see all the file that have "abc" as a part of the ...
0
votes
1answer
28 views

Why doesn't `tar --exclude` take multiple options?

Looking at the man-page for tar it's stated that --exclude=PATTERN will " exclude files, given as a PATTERN ". I'm not sure if PATTERN is explained in more detail somewhere else, but why does the ...