Globbing means matching files by name patterns containing wildcards.
27
votes
5answers
2k 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 ...
4
votes
1answer
600 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?
21
votes
7answers
2k 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, ...
12
votes
8answers
10k 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 ...
2
votes
3answers
78 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
...
3
votes
4answers
62 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 ...
4
votes
3answers
76 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
71 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:
...
2
votes
6answers
73 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 ...
1
vote
2answers
54 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, ...
3
votes
4answers
145 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 ...
8
votes
5answers
232 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:
...
0
votes
3answers
48 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 ...
3
votes
1answer
118 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
138 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
78 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 ...
0
votes
1answer
64 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 ...
2
votes
2answers
87 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 ...
5
votes
3answers
204 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
68 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 ...
4
votes
4answers
238 views
Avoiding errors due to unexpanded asterisk
In bash I often use for-loops such as the following
for file in *.type; do
sommecommand "$file";
done;
to perform an operation for all files matching *.type. If no file with this ending is ...
1
vote
1answer
75 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 ...
6
votes
1answer
122 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 ...
2
votes
2answers
56 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 ...
7
votes
2answers
4k views
How to use wildcards (*) when copying with scp?
Why can't I copy with scp when I'm using "*" characters in the path?
scp SERVERNAME:/DIR/* .
What configs do SCP need to allow "*" in the path?
UPDATE: the problem is not on server side, pscp is ...
4
votes
8answers
150 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
209 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
...
1
vote
2answers
71 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 ...
5
votes
2answers
119 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
3answers
121 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
123 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
88 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.
...
1
vote
1answer
93 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 ...
5
votes
1answer
66 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 ...
4
votes
3answers
134 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 ...
1
vote
3answers
136 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 ...
1
vote
1answer
82 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
...
3
votes
2answers
184 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
164 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 ...
5
votes
3answers
263 views
“mkdir foo; svn mv * foo”
I often want to do some variant of this idiom:
$ mkdir 2010
$ svn mv * 2010
Of course, I get an error because the glob matches 2010 as well:
svn: Cannot copy path '2010' into its own child ...
2
votes
4answers
83 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 ...
2
votes
2answers
41 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
...
10
votes
5answers
357 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
...
1
vote
1answer
89 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
...
-2
votes
1answer
74 views
How to print contents of two files using wildcards in puTTY? [closed]
How do I print out the contents of two files using wildcards in puTTY?
3
votes
1answer
60 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
98 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
2answers
199 views
Using wildcards to match a directory in bash
Lets say the folder structure is like so:
/home/
--user1/asdf
--user2/asdf1234
--user3/asdf325234
--cool/asdf
How could I change to asdf1234 without specifying the user? For example:
cd ...
1
vote
2answers
154 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 ...
2
votes
2answers
84 views
What is an equivalent of rm `find lib/ -name *.swp` without find?
As in the title, I would like to remove all files in the lib directory with .swp in the end.
How can I do this without find in:
rm `find lib/ -name *.swp`


