Globbing means matching files by name patterns containing wildcards.

learn more… | top users | synonyms (2)

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 ?
33
votes
1answer
3k views

Does 'rm .*' ever delete the parent directory?

The expression .* is expanded by bash to include the current and parent directories: $ ls -la total 2600 drwxrwxrwx 2 terdon terdon 2162688 Sep 10 16:22 . drwxr-xr-x 142 terdon terdon 491520 Sep ...
0
votes
2answers
35 views

How to exclude the files with all the 4-digit numbers without the first five numbers by wild card in tree command

I want to exclude list the following number 0005 0006 ... 9998 9999 I try the following code, but failed And I use tree -I '*.[0-9][0-9][0-9][5-9]' But It creates line with 0014 0024... I ...
0
votes
2answers
44 views

Why doesn't this find command work? Regex & Find variants for .mp3 .wav and .m4a files

2015.10.25 Move on and Be Blessed.wav dummy.m4a 2015.11.17 BS Full.wav.mp3 2015.11.17 BS MOL.wav.mp3 find . -name '*.mp3' -o -name '*.wav' -o -name ...
12
votes
1answer
5k 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?
0
votes
2answers
94 views

tar “--exclude-from” double star wildcard

I wrote a backup script on my Debian 8 system which uses tar command with "--exclude-from" to exclude some files/dir. This works great, but today I would like to exclude some files sharing the same ...
2
votes
4answers
55 views

Does directory match array variable

I'd like to check to see if a directory contains an array of file extensions. I'm on Ubuntu using Bash. Something like : files=$(ls $1/*) extensions=$( txt pdf doc docx) if [[ -e $files[@] ...
0
votes
1answer
37 views

What's the equivalent wildcard operator in Zsh to Bash's *

I have just started using Zsh and I have noticed that the asterisk (*) wildcard operator does not seem to work in it. For example, running cd ~/Doc* does not change me into the ~/Documents directory ...
1
vote
1answer
55 views

find command match issue [duplicate]

I'm having some trouble while searching files with find command and the way it handles the search. Let's say I'm currently in the directory /tmp and the directory contains the files: ...
1
vote
1answer
36 views

globbing and $# [closed]

Suppose my shell script gets 3 arguments: ./myscript dir1 material dir2 I need $# to report the count of items globbed with dir1/* and not the count of my script's original 3 arguments. Do you ...
3
votes
1answer
317 views

Odd alias “find . -name '*\!{*}*' -ls” in Unix Power Tools

From Unix Power Tools 3rd Edition page 175: Article 9.27 shows a way to match directories in the middle of a path. Here's a simpler "find file" alias that can come in very handy: alias ff ...
5
votes
4answers
6k 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: ...
0
votes
1answer
32 views

Head and Tail of a directory, set by the user

I have this script that will show the user the head or tail of the files that are inside a set directory (currently that is set as '~/bin/new/*'). This script works but i would like to allow the user ...
38
votes
7answers
7k views

why does ls -d also list files, and where is it documented?

when specifying ls --directory a* it should list only directories starting with a* BUT it lists files AND directories starting with a Questions: where might I find some documentation on this, ...
2
votes
2answers
145 views

Role switch of special characters in bash

On what basis does the role of asterisk keep changing? CASE 1: var1=abcd-1234-defg echo ${var1#*-*} # RESULT: 1234-defg CASE 2: stringZ=abcABC123ABCabc echo `expr match "$stringZ" ...
0
votes
1answer
161 views

scp with sshpass - remote directory and file with wildcards

I have a list with 950 MongoDB VMs I wish to collect all mongodb.log. The path to log file is depending on database name. for i in $(cat /tmp/mongonodes.txt) ; do sshpass -p34dDgdWger@rg4fll434ef ...
2
votes
3answers
407 views

Why rm exclude using ! doesn't work in zsh?

I have 10 files in current directory: 10test 1test 2test 3test 4test 5test 6test 7test 8test 9test I want to remove all file except 2test and 3test, but I run command rm !(2test|3test) doesn't ...
10
votes
2answers
4k views

Exclude one pattern from glob match

I have several files with the same base filename. I'd like to remove all but one foo.org #keep foo.tex #delete foo.fls #delete foo.bib #delete etc If I didn't need to keep one, I know I could use ...
0
votes
0answers
117 views

rsync “no such file or directory” when using wildcard

I am trying to use rsync to copy the contents of a folder to another folder. This is the command I am using for this. rsync -v -r $folder64/Pictures/* $folder65/Pictures/ And here is the error ...
2
votes
1answer
78 views

bash regex: asterisk gives ambiguous search results with grep

I am using a simple text file to test the * meta-character through grep. The text file is as below: 1 11 111 1111 11111 111111 d da daa daaa b bc bcc bccc Now when I search digit 1 using grep ...
0
votes
2answers
21 views

file globbing in bash not being picked up by php -l

I am trying to run php's lint function on all files in a directory, and it's proving to be harder than I expected. (I know there are non-php files here; I'm not concerned about that right now.) Here's ...
30
votes
10answers
61k 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 ...
3
votes
5answers
593 views

Copy Sequential Files

I have 12 files named dmp_000, dmp_001, etc, all the way to dmp_011. I would like to copy all of them to rdmp_000, rdmp_001, and so on, sequentially so the numbered files coincide. There must be an ...
3
votes
4answers
105 views

Why does the wildcard * not work when changing directories?

For example I'm in my directory: /home/myname and then I want to CD into a different directory. /home/pulsar/... Since I need to go pretty deep into the other directory, how can I go about this ...
2
votes
1answer
41 views

How to reuse file pattern in .gitignore in bash/zsh?

Here is the content of the .gitignore cron.yaml build target webview *.pyc *.sublime-workspace .idea *.rej .coverage app/tools/temp_*.py app/tools/*/temp_*.py I am currently iteraring files in a ...
-1
votes
4answers
4k views

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

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 ...
3
votes
4answers
192 views

Match-zero-or-more operator in shell globbing

I'm stuck in a quite trivial problem here: how can I make the * symbol in bash mean zero or more, like it does in tools such as sed? For example, ak* should match any file whose name consists ...
1
vote
2answers
62 views

Internal expansion with the find command and wildcard character [duplicate]

I'm still learning the command line and I am having some trouble fully understanding the use of the wildcard within the find command. I'm working in the directory user/temp and use the find command ...
2
votes
3answers
52 views

Recursively delete files with 'WIDTHxLENGTH' in the name in a directory

I have a directory that has subdirectories, and I want to delete images named like thumbnail-name_WIDTHxLENGTH.{jpg,png}, where WIDTH and LENGTH are both decimal integers, like box-image-150x150.jpg ...
55
votes
7answers
20k views

The result of ls * , ls ** and ls ***

I know using the command ls will list all the directories. But what does the ls * command do ? I used it and it just lists the directories. Is the star in front of ls means how deep it can list the ...
3
votes
5answers
522 views

Look if a folder has some files with certain extensions

Suppose I have a file structure: $ cd /home/Desktop $ ls -d */ Abc/ Qwe/ Zxc/ Rty/ $ Now I want to iterate through every directory and see if they have any ".pdf" files. Could some one please ...
0
votes
2answers
40 views

Find a file that doesn't include specific characters

I want to find a specific file that doesn't start with a,k,G or Q and in which the third letter in the name is not a digit. I have tried many links, but found nothing regarding to this composite ...
1
vote
1answer
44 views

Having trouble with img2pdf and spaces in filenames

I am trying to convert a bunch of jpeg files to a pdf file. When I type the filenames with the quotes all is fine: $ img2pdf "./Page 001.jpg" "./Page 002.jpg" -o book.pdf When I go for the ...
1
vote
3answers
85 views

What is the bash equivalent of the where cmdlet?

The where cmdlet is something I use in PS quite often- its very convenient. If I want to get all files with a name starting with "test" I would do this: ls | ?{$_.name -like 'test*'} What is an ...
4
votes
5answers
12k views

Count files in a directory by extension

For the purpose of testing, I'd like count how many images files are inside a directory, separating each image file type by file extension (jpg="yes". This because later it will be useful for another ...
4
votes
5answers
1k views

Is it possible to reference the most recently modified file in a command line argument?

I frequently download PDF files with heinous numeric file names from my browser. These automatically go into ~/Downloads. Ideally I would like to just be able to open these files with: evince "the ...
3
votes
3answers
110 views

Why are square brackets preventing shell expansion?

'4800483343' is a directory, and 'file1' & 'file2' are two files in it. Why is the following happening? $ ls 4800483343 file1 file2 $ md5sum 4800483343/* 36468e77d55ee160477dc9772a99be4b ...
1
vote
1answer
42 views

Handle wildcards matching no file in bash

I am trying to read files from a directory into an array but even when the file doesn't exist, it is saved into the array. I want to exclude the file name if it doesn't exist. a=(/tmp/nofileexists) ...
8
votes
6answers
485 views

Force newlines with cat wildcard printing

I want to use cat with wildcards in bash in order to print multiple small files (every file is one sentence) to standard output. However, the separate file contents are not separated by a newline, ...
3
votes
1answer
111 views

Ignore globs that don't match anything

I want to select all files in a directory that end with any of the following extensions: txt, java, xml, csv Right now I'm doing like this: echo *.{txt,java,xml,csv} The problem is, if the ...
3
votes
2answers
442 views

Regex file name with multiple digits

Say I have the following file: test_file-1234-master.tar.gz I have tried to un tar using the following commands tar -xf test_file-[0-9]+-master.tar.gz tar -xf test_file-[:digit]-master.tar.gz ...
5
votes
3answers
347 views

Use shell's “*” glob, but exclude one file and don't match directories?

I've got a makefile rule that builds a zip/tarbar for distribution. In the recipe, it does some "value added" things, like ensure CR/LF's are correct, and ensures execute bits are correct before ...
0
votes
1answer
60 views

Why is the redirection of loop output dependent on the filename?

I have two files: a.csv and b.csv: echo $'a_header\na1' > a.csv echo $'b_header\nb1' > b.csv Now I want to remove the first line from each, and concatenate them. for file in `ls *.csv`; do ...
2
votes
3answers
251 views

tar unix not changing directory

I am executing a tar command to compress files which are present in another directory. I executed following command: tar -czf /backupmnt/abc.tar.gz -C /backupmnt/statusService/ * I want to create ...
1
vote
4answers
599 views

How to list filenames that contain spaces and special characters without using find

I am writing a script that requires me to provide a list of files in my directory, whose filenames contain spaces,*,?,$,%,etc. How can I do this, I have seen multiple posts but couldn't find anything ...
22
votes
5answers
7k views

What does `mv ./*` without specifying destination do?

I accidentally forgot to specify destination before hitting the Return key. Where does mv ./* without specifying destination move the files and directories under current directory to?
1
vote
4answers
380 views

Bash: move files of specific pattern

I write a script that iterates over a set of zip files, extracts them and moves only files that match a specific filename pattern to another folder. The script: #!/bin/bash ...
4
votes
3answers
76 views

Move unique files from a folder with duplicates files

Well to put it simply, I have duplicate files in a folder, with this form: file.ext file(1).ext file(2).ext file(3).ext otherfile.ext otherfile(1).ext otherfile(2).ext ... I want to move only ...