Globbing means matching files by name patterns containing wildcards.

learn more… | top users | synonyms (2)

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 ...
7
votes
3answers
780 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 ...
2
votes
1answer
28 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
941 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
70 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 ...
7
votes
5answers
10k 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 ...
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
121 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
51 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
55 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
46 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 ...
20
votes
7answers
38k 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 ...
68
votes
8answers
67k 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 ...
0
votes
1answer
34 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
49 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
52 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
40k 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
12 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
10k 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
309 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
42 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
33 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 ...
25
votes
6answers
40k 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)?
38
votes
8answers
85k 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
34k 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 ...
4
votes
2answers
85 views

confusing about double quoting

I learned when I use command, double quoting treat all things as character except $, `, \ . But, when use command like find -type f -name "*.jpg" *.jpg is inside double quotes. Then, it means we want ...
3
votes
1answer
26 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 ...
3
votes
4answers
207 views

How to escape shell metacharacters automatically with `find` command?

I've got a bunch of XML files under a directory tree which I would like to move to corresponding folders with the same name within that same directory tree. Here is sample structure (in shell): ...
3
votes
2answers
3k views

How does logrotate treat globbing?

If I have a logrotate config file like this, # matches multiple ones /var/log/project/*.log { ... prerotate ... endscript ... } So how does the glob work here? If I have 3 log ...
5
votes
2answers
69 views

How to store a path built with wildcards and containing with spaces into a variable

Here's the situation (I'm on a Mac, OS X El Capitan): # This works: $ cd /Applications/Adobe\ Illustrator*/Cool\ Extras.localized/en_US/Templates/; # These do not work: $ ...
5
votes
4answers
382 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 ...
10
votes
2answers
1k 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 ...
1
vote
1answer
47 views

Can I use Zsh's built-in wildcard matching to replace the use of `find` here?

This is a follow-up to another question I posted I use a script to automatically rename files according to a particular order: #!/usr/bin/env zsh pages=($(sed -n '/page_order/,/^$/ p' _config.yml | ...
1
vote
1answer
35 views

zsh glob pattern to match all files except one, does not work, despite EXTENDED_GLOB being set [duplicate]

I have a directory containing several files: $ ls tdir xx yy zz I'm looking for a zsh glob pattern, which expands to all (non-dot)-files except xx. This is what I tried: $ set -o EXTENDED_GLOB $ ...
0
votes
1answer
46 views

Listing files with a certain extension

I'm suppose to write a command that would list all files that end in .tx with an optional t at the end. So far all I got is listing the files that end in .tx which is: ls *.tx Now my problem is ...
0
votes
2answers
88 views

For loop cannot distinguish * syntax

set -x for f in ~/1/2/*/*_1.txt; do subdir="${f%/*}" pushd "$subdir" &>/dev/null file="${f##*/}" expTool INPUT1= "${f##*/}" INPUT2= "${f%_1.txt}_2.txt OUTPUT1= "${f%_1.txt}_3.txt" OUTPUT2= ...
2
votes
2answers
24 views

exclude target redirection file from being processed in for loop

This will cause LIST to grow very large (even a couple of GB in a short time etc): $ for i in *; do echo $i; cut -d ' ' -f1 $i ; done > LIST For example, after 10 seconds: $ wc -l LIST ...
32
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
2answers
82 views

How to copy image files whose names don't end with their resolution size?

I have a folder with images in it and it is organized by year and month folders (ie. /2015/08/image.jpg). Whenever an image is added, it is also copied and resized like so: image-1024x768.jpg ...
3
votes
1answer
27 views

Rsync unable to remove remote file not exist in local

Consider my local folder /tmp/foo/ /tmp/foo/1.txt /tmp/foo/2.txt /tmp/foo/3.txt and my remote folder /tmp/foo/ /tmp/foo/1.txt /tmp/foo/2.txt /tmp/foo/4.txt and in my local side, I run the ...
1
vote
1answer
45 views

How to prevent bash from transforming arguments?

I am trying to use an argument of the script to find other files. The problem is that when i give the script the argument x.* in the command line, it is transformed into x.sh. Any ideas how i can get ...
16
votes
5answers
34k views

How do I recursively delete directories with wildcard?

I am working through SSH on a WD My Book World Edition. Basically I would like to start at a particular directory level, and recursively remove all sub-directories matching .Apple*. How would I go ...
3
votes
4answers
25k views

Unix Command to return all files that end with single digit and TXT extension

Which command returns all files that end with a single digit and have the TXT extension ?