Globbing means matching files by name patterns containing wildcards.

learn more… | top users | synonyms (2)

1
vote
0answers
21 views

Ordering of files opened by program

When I open a set of files, usually just by using a glob character to open all the files in a directory or a subset, typically if not always the default is for the files to be opened by alphabetical ...
6
votes
2answers
367 views

Remove all files with a prefix except the one of the largest size

What is the best way to remove all the files in the current directory with some prefix, except the file with this prefix but having the largest size among all the files with this prefix? (In the ...
22
votes
8answers
41k 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 ...
5
votes
5answers
1k 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 ...
0
votes
4answers
95 views

Is there a “ls” replacement that can handle wildcards?

I just learned that ls cannot handle wildcards (ls '*' does not work) and therefore the shell does it before ls is invoked. So the behaviour of ls may be considered as logically for people working 20 ...
18
votes
5answers
36k 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 ...
0
votes
5answers
103 views

how to iterate through files in directory excluding hidden files

Using: for eachfile in /mnt/thara/* Which iterates through hidden files as well. I don't need hidden files.
28
votes
6answers
43k 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?
-2
votes
6answers
4k views

Wildcards: how do I list files ending in `.txt` only without using the dot character? [closed]

I have a directory with nine files in it. 1 ending in .bat 2 ending in .bak 4 ending in .txt 2 ending in .xtxt My question is, how do i list only the files ending in .txt, but without using the ...
8
votes
8answers
12k views

What's the best way to count the number of files in a directory?

If parsing the output of ls is dangerous because it can break on some funky characters (spaces, \n, ... ), what's the best way to know the number of files in a directory? I usualy rely on find to ...
2
votes
1answer
30 views

Cannot stop bash to expand star (wildcard character) passed to app from shellscript

I have a shell bash script wich should pass the star ["*"] wildcard character to an application without using quotation marks. I am reading since hours and always find to use "set -f" inside the ...
22
votes
2answers
40k 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 ...
5
votes
3answers
987 views

How to view last 5 lines from last created/modified file?

Every day I have to take backup and update the status to support teams at particular time for which I need to check last 5 lines of last created/modified *.aff file in a directory and update them. ...
1
vote
1answer
39 views

How to pdfjam by Filename Numbering?

My files masi1.jpg masi2.jpg masi3-1.jpg masi4.jpg ... masi10.jpg masi11.jpg ... Command pdfjam *.jpg. Output: random. Expected output: as the list. There is no parameters in man pdfjam, only ...
0
votes
1answer
43 views

I accidentally copied part of /* to /some/directory, how should I fix my mistake?

I did something stupid on a remote linux server: my working directory was /some/directory I ran for dir in $(ls | grep "a_pattern"); do mv $d/* ./my_subdirectory; done Now /some/directory/...
5
votes
1answer
10k views

rsync all directories that start with a specific digit

I have directory loaded with thousands of sub directories: /home/tmp/ 1 12 123 1234 2345 234 3456 345 34 ...
4
votes
3answers
3k views

How to match * with hidden files inside a directory

How to match the hidden files inside the given directories for example If I give the below command it's not giving the result of the hidden files, du -b maybehere*/* how to achieve this ...
1
vote
4answers
56 views

How to open or list all files whose names match two patterns in Bash

Suppose that I have a directory with thousands of files; how could I open all files whose names contain the strings "red" and "green"?
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/ ap/...
1
vote
1answer
44 views

tar specific files in several different subdirectories

I have the following folder structure A |-B | |-C | |-1.log | |-2.log |-10.log |-D |-E |-F |-php.log |-H |-php.log I want to collect all the log files and the php file present ...
5
votes
5answers
334 views

How safe it is to output to <dir> simultaneously with rm <dir>/*

Sometimes I need to remove all the contents of a directory and create new files there. Can I do something like this and expect all new files to remain intact: % rm -rf regression/* & ( sleep 10 ; ...
2
votes
2answers
294 views

Tar a list of files which don't all exist

I'm running a command from a script like tar -c -f ar.tar a b c d where b, c, and d may not exist, and may be directories. The solutions that I've come up with are piping the output of ls -d to ...
1
vote
2answers
120 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 \?
9
votes
4answers
2k 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 ...
0
votes
0answers
19 views

getting wrong order of files with ImageMagick and *.png [duplicate]

I am using ImageMagick to concatenate files which I have named 1.png to 50.png. However the files are arranged in the wrong order going 1.png, 11.png, 12.png ... instead of 1.png,2.png ... It must ...
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
28 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
82 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 ...
47
votes
5answers
3k 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 ...
1
vote
1answer
69 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
63 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
299 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
11k 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
36 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
39 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
53 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
54 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
27 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 }') ...
34
votes
1answer
3k 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
65 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
49 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 '...
70
votes
7answers
70k 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
837 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
4k 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
44 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
1k 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
77 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 ...