Tagged Questions

Globbing means matching files by name patterns containing wildcards.

learn more… | top users | synonyms (2)

7
votes
5answers
6k 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?
4
votes
2answers
511 views

Sort files by modification time

I've seen many questions and answers here using a construction along the lines of list_dir=`ls -t /path/to/dir/` for i in $list_dir; do or ls -t | while read i; do Now, I know that you shouldn't ...
15
votes
4answers
10k views

rm -rf all files and all hidden files w/o . & .. 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: ...
2
votes
3answers
2k views

ffmpeg -pattern_type glob — not loading files in correct order

I have a dilemma.. I've had a script for a while now that downloads pictures from a webcam every few minutes. The naming convention just does new_image((len(files(dir))+1) + '.jpg') and that's all ...
5
votes
2answers
203 views

Passing glob expressions to functions/scripts

The following script is supposed to concatenate multiple csv files in a path specified in the first argument into a single csv file specified in the second argument #!/bin/zsh set -x set -v ...
3
votes
2answers
402 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 ...
30
votes
7answers
4k 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, ...
3
votes
4answers
188 views

Expansion with numbers in human readable format

So, I want to play some MP3s in a console player that takes file names as inputs. I have the following files, as given by ls -1 * where * get expanded by my shell (zsh): 1 - Main title.mp3 10 - End ...
2
votes
3answers
641 views

Very strange behavior with grep and IFS

I'm having trouble using grep, the returned results are "n-empty", I mean without the 'n' character... This is the script sample : OLDIFS=$IFS IFS="\\n" i=$(grep -ril $1 *) echo $i IFS=$OLDIFS ...
2
votes
2answers
89 views

“or” in shell glob

I want to ls the files containing the substring "s1r", "s2r", "s3r" or "s19r" in their filenames. I'm almost there! Botched attempts: ls *s[123][9?]r* The above gives me only files including the ...
5
votes
2answers
188 views

Modifying zsh globbing patterns to use with cp

I'm trying to write a script to copy files recursively from a particular folder except files A.extn, B/*.extn and C/* where B and C are directories and extn is just some generic extension. This is ...
4
votes
3answers
298 views

Why should 'Character Classes' be preferred over 'Character Ranges' In Shell (Bash)?

The Linux Command Line (Book - page count 47) says: ... you have to be very careful with them [character ranges] because they will not produce the expected results unless properly configured. For ...
0
votes
2answers
106 views

Supress expansion of * in echo

I am working on a script which dynamically executes some queries on daily basis. These queries are coming from a table in the database. Here is the sample output of the query table: ...
3
votes
2answers
1k views

Excluding a directory name in a zsh recursive glob

I'm running zsh on Linux under setopt extended_glob ksh_glob glob_dots. I'm looking for something easy to type on the command line, with no portability requirements. I'm looking at a source code tree, ...
2
votes
6answers
2k views

How to make tar globbing work with the 'change directory' option

I have the followin directory structure: base/ files/ archives/ scripts/ I want a script to run from scripts/, compress files that match results.*.log in files/ into a gzipped tar archive ...
0
votes
3answers
634 views

How to find files ending with ~ and pyc? [duplicate]

I want to find all files (in current and all subdirectory) which end in'~' or 'pyc'. To do so I have tried the following find pattern: find . -name '*{~,pyc}' find . -name '{*~,*.pyc}' but neither ...
9
votes
5answers
608 views

Can I select only one result from a bash glob?

I'm trying to write a script for work to automate some reporting on an output. The Log files are (currently, it's being 'standardise' in the future) stored in this sort of path structure: ...
4
votes
4answers
2k views

How to remove files which do not end with “.c”?

I have a directory which contains all the C programs. I have also compiled them at the creation time so as to check my code. There are a lot of programs nearly 100 of them. So I want a BASH script ...
3
votes
1answer
615 views

Shell wildcards and dot files

I am a beginner terminal user trying to understand wildcards. I think I pretty much have a good grasp on it, but I have a couple of questions: Why do the following two codes work as expected: ls -d ...
1
vote
3answers
630 views

What does a question mark in a filename matching pattern mean?

What does the question mark in this command mean? find . –type d –name "?d*" –print I tried to to run it without it but didn't notice any change.
2
votes
3answers
115 views

Filter a list of strings using math

I have a directory with files listed like so: abc201303130110.txt abc201303140511.txt abc201303150112.txt As you can see, the filename contains a datetime stamp. I want to return all files with the ...
2
votes
2answers
679 views

Working of rm/ls with [0-9]

I am learning the shell commands and came across the short tags eg.[0-9],[[:digit:]] etc.. As a proof of concept i tried deleting all the files with the rm command(i know its not a good practise but i ...
0
votes
1answer
287 views

Working of the [0-9] [duplicate]

I am learning the shell commands and came across the short tags eg.[0-9],[[:digit:]] etc.. As a proof of concept i tried deleting all the files with the rm command(i know its not a good practise but i ...
6
votes
3answers
6k 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 ...
1
vote
1answer
106 views

starting vim with command substitution

I am working on a project on two different machines - one running Mac OSX 10.8.3, and one running Red Hat Enterprise Linux. On my Mac, I can do this: vim $(ls -R */*.@(h|cpp) */*/*.@(h|cpp)) and ...
3
votes
2answers
1k 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 ...
8
votes
1answer
891 views

Wildcards inside quotes

This will be an easy one, but in my memories, when shell scripting, using double quotes would allow expanding globbing and variables. But in the following code: #!/bin/sh echo *.sh echo "*.sh" echo ...
1
vote
1answer
242 views

How to prevent double escaping?

I'm trying to put a bunch of images together into a pdf. I ran gm convert *.jpg out.pdf and it worked, but the images were not in the right order. I found that ls -v orders them correctly so then I ...
2
votes
2answers
210 views

Select greatest numbered filename

Simple requirement but can't find anything online which can achieve it. I have a list of dated files as below... filename_20120101.dat filename_20120102.dat filename_20120103.dat I ...
5
votes
8answers
2k views

Run a command on all subfolders

If you have a series of subfolders (like from a to z) and want to run a command on each one of them (like rm *.pdf or ls *.pdf), how do you do that? The "manual" approach would be cd a, rm *.pdf, or ...
3
votes
1answer
624 views

for loop in bash function

I recently wrote the following bash function: makeaudiobook () { count=1 almbumartist=$2 for f in $1; do preprocess $f > $f-preprocessed text2wave $f-preprocessed -o $f.wav ...
6
votes
2answers
480 views

Remove all Vim undo files in all but one directory

I just realized that I have tons of Vim undo (.un~) files sprinkled around my file system. I'd like to delete all of these files except in one directory—~/.tmp. My first problem is that I can't seem ...
1
vote
2answers
129 views

How to get “current glob” in zsh

I want to do something like: $ convert [a,b,c,d,e].png -resize 50% <current_match>_half.png How can I do this? Is there some variable that stores the current match? I couldn't find anything in ...
1
vote
3answers
472 views

Reading a directory in shell script

I want to read a numbered directory which is under a path, into a variable in shell script. The paths are something like this: .../releases/R1/... .../releases/R2/... .../releases/R3/... Each time ...
2
votes
2answers
776 views

Bash Wildcard Partial Match Directory

I have this bash script which is trying to find a directory that partially changes on peoples systems. cd "$HOMEDIR/AppData/Local/GitHub/PortableGit"*"/bin" Yet this does not seem to work - it ...
1
vote
1answer
141 views

Copy files excluding x,y,z causing error in shell script

I'm not well versed in shell scripting but I imagine this to be a painfully easy fix but its eluding me. I need to copy the contents of a directory excluding a number of files. I have a command that ...
1
vote
1answer
2k views

How can I zip the contents of current directory minus all hidden files?

How can I zip up the contents (excluding hidden files and folders) of the folder I am currently in? zip -r extension.xpi . -x "*/.*" This is what I have so far, but I am still getting hidden files. ...
5
votes
1answer
114 views

Bash globbing: how to express “something-*.txt except *-foobar.txt” as glob?

On the command line, can I express easily in terms of shell globs that I would like to catch all files something-*.txt, except for something-*-foobar.txt? If I can, how? NB: I know how to achieve the ...
1
vote
1answer
278 views

Why does printf ignore the IFS when printing out the result of my script?

This is a follow up to a question posted on SO. I've written a script called except which should print all filenames / directories except the ones given like so. $ ls a b c d $ rm $(except b d) $ ls ...
1
vote
3answers
640 views

Shell script Variable Structure

How can I create a variable with a file name format like : FileName pattern: SnapshotIR__somenumber.csv I tried something like : TODAY=$(date +"%m%d%Y") SNAPSHOT = $(SnapshotIR$TODAY*.csv) I ...
5
votes
3answers
1k views

Create symbolic links to files using wildcards

I want to create symlinks to multiple files: ln -s dev-*.php 's/dev-(.*\.php)/$1/' Results hoped for: site.php links to dev-site.php file.php links to dev-file.php What's the most ...
4
votes
2answers
542 views

Get the complement of the result of an ls command

Let's say I have a directory with multiple files, all of which are either binary files (files with no declared extensions) and source files (.c extension). I do this: $ ls and get: README.md ...
3
votes
5answers
230 views

Regex match in CLI

Is there something like a logical for the cli? I want to achieve this mv -t newfolder *.(png|jpg) so that alls jpg and png files are moved into newfolder. I know it could be done with mv -t ...
2
votes
2answers
91 views

Select a range of logs from daily log archives

I have a folder containing daily logs, named as : system-2013-01-01.log system-2013-01-02.log system-2013-01-03.log system-2013-01-04.log system-2013-01-05.log system-2013-01-06.log ...
3
votes
1answer
4k 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 ...
10
votes
5answers
2k views

Pattern matching on path names in bash

I want to act on a list of subdirectories in a directory. Consider: for x in x86-headers/*/C/populate.sh; do echo $x; done This gives x86-headers/elf/C/populate.sh x86-headers/gl/C/populate.sh ...
3
votes
1answer
156 views

Passing all files of specific filetype in current and subdirectories

I have constructed an elaborate 500+ character command with many arguments and switches to autosign multiple PDF documents. I'm using JSignPDF and I'd like to use it's batch mode including the ...
2
votes
2answers
164 views

Bash variables and types

I'm making a script that validate an IP address. I do this: read pool checkIp() { local ip=$1 local stat=1 if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then ...
2
votes
5answers
318 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 ...
1
vote
2answers
503 views

aptitude remove pkg_name* not working like apt-get

I have uninstalled (aptitude purge) the qt-sdk package but there is still a lot of qt4* and libqt* packages on my system. Is there a way to remove all these packages with aptitude remove/purge ...