Globbing means matching files by name patterns containing wildcards.

learn more… | top users | synonyms (2)

5
votes
3answers
244 views

How to check if a glob has an expansion? [duplicate]

Is there a good clean conventional way to do this? For example, if there are any ".gz" files in a certain directory, I want to unzip them. But if there aren't, I don't want to see any error. If I ...
3
votes
2answers
81 views

Remove all files, except for two

I would like to delete everything in one folder, with the exception of two files: exec.js .git I found this: rm !(exec.js|.git) Which works in the CL, but when I try to store in a sh file, and ...
31
votes
10answers
66k views

Converting multiple image files from JPEG to PDF format

I want to convert some files from jpeg to pdf. I am using following command. $ convert image1.jpg image1.pdf But I have 100 images. How should I convert all of them to corresponding pdfs? I ...
20
votes
6answers
31k 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?
28
votes
7answers
4k views

Why does [A-Z] match lowercase letters in bash?

In all shells I am aware of, rm [A-Z]* removes all files that start with an uppercase letter, but with bash this removes all files that start with a letter. As this problem exists on Linux and ...
1
vote
0answers
25 views

Completion with wildcards in directory names in bash

I can do: $ cd sources/ar #[TAB] here would complete word 'ar' to 'art' I can do $ cd */art #[enter] here would bring me to sources/art I can do $ cd */art #[TAB] that would expand */art to ...
12
votes
1answer
121 views

[[ and case equivalency in bash

Does if [[ "$1" = pattern ]]; then hook fi always behave the same as case "$1" in pattern) hook;; esac or are there any gotchas?
7
votes
3answers
2k views

Is it possible to change the order of a glob?

I am trying to show all instances of a particular message from the syslog in chronological order by doing something like the following: grep squiggle /var/log/messages* Unfortunately the glob ...
2
votes
2answers
55 views

shopt -s extglob not working as expected

I am trying to recursively change file permissions in a wordpress installation affecting everything below the public_html document root folder, excluding certain folders. I have set extglob on with ...
1
vote
4answers
96 views

/bin/ls: Argument list too long

I am a biology person and running a program named autodock. I have some files from ZINC library in .mol2 format. As per requirement I need to split this files with the csplit command and I received ...
3
votes
1answer
39 views

how to set globstar for noninteractive shells

I would like to execute commands noninteractively on a remote server that use the ** globstar option. However, globstar is not set by default on the remote, and bash doesn't source any files in ...
19
votes
3answers
40k views

How do I remove all sub-directories from within a directory?

This question is kind of a phase II to the first question I posted at here I have a directory that contains a bunch of sub-directories, .zip files, and other random files not contained within a sub-...
3
votes
2answers
56 views

How to Run a command on all subfolders

If you have a series of sub folders (like from a to z) and want to run a command on each one of them (like dsmmigrate * & ) how do you do that? The manual approach would be, cd a dsmmigrate * &...
0
votes
2answers
75 views

Wildcard not working in quotes

The script is supposed to loop over subdirectories and match all the filenames (FLA.*Image.*file.jpg and FLA.*Image.jpg) in subdirectories and process it. It also create output folder inside the ...
5
votes
3answers
292 views

for loop glob mishaps

I am trying to set up a script that will loop over a set of directories, and do one thing when it finds .jpg files, and another when it finds .nef files. The problem is, if a directory does not have ....
23
votes
8answers
42k views

Test if there are files matching a pattern in order to execute a script

I am trying to write an if statement 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 [ -f /*...
1
vote
1answer
71 views

Why is find not listing matching files when preceded by an asterisk(*)? [duplicate]

On Ubuntu 14.04, 64 bit, I have set /lib/modules/4.2.0-27-generic/kernel/drivers to be my current directory. I intend to search all files having net present as a sub-string. If I search with a regex ...
0
votes
0answers
31 views

Unrar specific files using wildcards

I want to extract only a specific file type using unrar. With unzip command I can extract all archives with a specific extension. unzip "$FileName" *[.txt,.TXT] How can I do the same with unrar? ...
1
vote
0answers
23 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
403 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 ...
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
101 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
37k 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
110 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.
29
votes
6answers
45k 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
5k 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
34 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
42k 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
1k 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
46 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
46 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
11k 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
61 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
50 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
338 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
323 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
124 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
20 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
416 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
31 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
84 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 ...
48
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
83 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
78 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 ...
22
votes
1answer
2k 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
315 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. ...