Globbing means matching files by name patterns containing wildcards.

learn more… | top users | synonyms (2)

4
votes
5answers
929 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 ...
20
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 ...
3
votes
3answers
86 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
40 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
401 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
106 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
266 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
277 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
57 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
220 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
273 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
6k 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
248 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
61 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 ...
1
vote
2answers
56 views

Cannot run command inside bash variable including square brackets with nullglob

Assuming I want to run commnand stored inside the variable with nullglob turned on. For example: shopt -s nullglob a="echo [foo]bar" ${a} This gives me an empty output due to the nullglob option of ...
17
votes
2answers
5k views

Delete all files starting with a question mark

I have a folder in which I have around 4k files. Some of these files start with a a ? or ! character. I need to delete them but can't find an expression that would do so: rm -f ./?* just deletes ...
63
votes
3answers
230k views

Zip all files in directory?

Is there a way to zip all files in a given directory with the zip command? I've heard of using *.*, but I want it to work for extensionless files, too.
24
votes
1answer
612 views

Why does a unquoted wildcard work remotely with scp?

I'm typing this in Bash: scp user@remote:~/dir/*.xml . and it works, getting all the files that make the wildcard on the remote server. But why does this work? I thought that Bash expands wildcard ...
28
votes
6answers
3k 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 ...
5
votes
5answers
8k 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 ...
1
vote
2answers
69 views

List files in hierarchy of directory

I need to list files in hierarchy of directory. For that I wrote script like foreach file ( * ) ls ${file}/*/*/*/*/*.root > ${file}.txt end But for this I have to know that in the directory ...
2
votes
3answers
140 views

List transient files by numerical value having number greater than a given constantly varying filename

I've a directory having constantly changing filenames (by numerical value) listed as: -rw-rw----. 1 root root 10493952 May 7 10:39 A0000000.LOG -rw-rw----. 1 root root 10493952 May 7 08:38 ...
3
votes
2answers
1k views

tar command - skip symlinks

I use the tar command as, tar -cvf protTests.tar protTests/* to tar all files inside the folder, protTests. But this is including the symbolic links inside the folder, which is not a desired one. ...
0
votes
0answers
54 views

how to exclude specific subfolder when creating zip file via command line linux

I do want to exclude subfolder like uploads/2015/OtherSubfolderName through command line. I have tried with below command, its working fine. zip -r zipfile.zip public_html -x *uploads* but can we ...
1
vote
1answer
866 views

Check if multiple files exist in directory

How to find multiple files present in a directory in ksh (on AIX) I am trying below one: if [ $# -lt 1 ];then echo "Please enter the path" exit fi path=$1 if [ [ ! f $path/cc*.csv ] ...
0
votes
1answer
217 views

find delete shows “No such file or directory”

I just run a command to "find and delete files & folder older than 100 days" on a folder, and got the following: $ find . * -mtime +100 -delete find: May_01_2015: No such file or directory find: ...
1
vote
3answers
141 views

Copy filenames, and add path prefix, in a directory, recursively

I have a working directory: /home/myusername/projectdir The working directory contains files and sub-directories. The depth of sub-directories is not known. I want to put all the *.log files into the ...
0
votes
4answers
89 views

How can I test for the .RAW file extension?

I'm trying to set up an sh script that will run every 30 minutes. During each run, I want to check a directory for the presence of at least one .RAW file. Upon finding that file extension, I will have ...
0
votes
3answers
125 views

regex in `/bin/sh` shell

I would like to remove all files ending with a given set of extensions in a particular directory in a /bin/sh shell. With a /bin/bash I can do it with regex like this : rm path/(*.pdf|*.png) but ...
2
votes
2answers
235 views

Cygwin using wildcard to trim all images

Unortunately, I am forced to use windows. So, I installed Cygwin to use some Linux commands. The following command works fine. It replaces an image with its trimmed version. "C:\Program ...
3
votes
2answers
191 views

Is there a reason to use multiple question marks instead of an asterisk in filename expansion?

If I have a number of directories, named, for example 10001 through 10025 is there any reason to use ls 1*/foo vs. ls 100??/foo? I have a lot more than 25 of them, so I mostly curious if there's any ...
3
votes
6answers
7k 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 ...
5
votes
4answers
2k views

How can I search for a file with fixed name length using ls?

In a directory, I have files like lazer_100506 lazer_100707 lazer_091211 lazer_110103 lazer_100406_temp lazer_100622#delete etc How can I get a listing of only the first four files? $ ls ...
-1
votes
1answer
39 views

Assign regular expression as character for a variable

I am wondering is there is a way to assign a regular expression as a character in a string to a variable and not have the regular expression change my variable. For example: in my directory I am ...
16
votes
2answers
29k 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 ...
1
vote
2answers
49 views

zsh - complex filename matching [closed]

I have trouble passing a list of file names to a program when utilizing globbing operators. Essentially the problem is that I have files with multi-stage suffixes and I want to match only the master ...
2
votes
3answers
466 views

!(*.sh) works on the command line but not in a script

When I use the code below in a terminal on Ubuntu, it works fine: rm !(*.sh) -rf But if I place the same line code in a shell script (clean.sh) and run shell script from terminal, it throws error ...
4
votes
3answers
534 views

Force Bash 4 'globstar' option to ignore symlinks

Bash 4 has a fantastic option called 'globstar' that emulates (i.e. was stolen from) zsh's ** syntax for globbing across multiple directories. However, it's somewhat crippled (for my usage, at least) ...
4
votes
2answers
506 views

Disable glob qualifiers in zsh

Is there a way to disable glob qualifiers with zsh? It seems like a useful feature, but it gets in the way of normal parentheses. I use ag to search files, and ag mymethod(param) causes zsh to ...
0
votes
0answers
41 views

What does the double star/asterisk wildcard expand to? [duplicate]

For example, Where are your test specs located? (./test/specs/**/*.js) Will that descend in all subdirectories under ./test/specs/, recursively? What authoritative source discusses this ...
1
vote
2answers
75 views

Piping contents of multiple files between programs while keeping contents separate

I would like to read in a number of files and pipe their output to subsequent programs while still maintaining them as individual pipelines of data. program1 *.txt | program2 | program3 folder I ...
2
votes
1answer
115 views

Unable to get back to bash prompt after strange command

I was messing about with different wildcards and ran the following command: ls testdir/!(*/) after which I was completely unable to get back to the bash prompt. None of ^C, ^D, or even ^Z worked: ...
2
votes
3answers
204 views

Copy only directories with .mp3 files with rsync

I'm trying to copy only folders with .mp3 files in them to another device. And only the .mp3s in them. The structure looks like this: Band/Year - Album/*.flac Band/Year - Album/*.txt Band/Year - ...
1
vote
1answer
164 views

du reports directory size as much bigger than the sum of its contents

Running du -shc * in the top directory gives 110G for a particular folder, whereas running the same command inside that folder gives a total size of 11G. How is that possible? Platform Details: OS: ...
1
vote
1answer
88 views

Copy array of multiple files with globbed extensions, in bash 3.2

I've found bits and pieces of each of the things I want to do across the Web, but nothing exactly fits my use case. I'm trying to write a script that copies multiple specific files to a directory on ...
2
votes
3answers
231 views

reverse cat files order

I need to do log analysis and I am facing problem that cat access.log* display latest log file first. I tried to sort logs which takes a lot of time because I have logs from couple of years back. And ...
1
vote
1answer
114 views

Listing directories and understanding ls

On ls man page, I saw this -d, --directory list directory entries instead of contents, and do not dereference symbolic links on my current folder: drwxr-xr-x 2 oracle oinstall 4.0K Jul ...
6
votes
2answers
719 views

How can I make bash not match `.` and `..` with `.*`

When I try to match all dot files in a directory with .* it seems to have a nasty side-effect: besides matching all (real) files and directories, it matches . and ... bash-3.2$ mv test/.* dest/ mv: ...
3
votes
7answers
256 views

for loop in bash lists dot and double dot folders [duplicate]

for f in ~/common/.*; do echo $f done The entries listed are, /home/sk/common/. #undesired /home/sk/common/.. #undesired /home/sk/common/.aliasrc And i am putting a ugly ...
2
votes
5answers
186 views

Testing if files start with certain letters and contain no special character except for period at end next to file extension in a shell script

I have a shell script that runs a for loop to execute a command on multiple text files in a folder. I want to test if these files' names start with a specific set of letters (NA for instance), and ...