Globbing means matching files by name patterns containing wildcards.
2
votes
2answers
94 views
Zipping files two by two
I have a directory that has 800 files like this:
file1.png
file1@2x.png
file2.png
file2@2x.png
file3.png
file3@2x.png
... etc
I need to create zip files like this
file1.zip (containing ...
2
votes
2answers
201 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 ...
2
votes
2answers
99 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
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
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`
2
votes
1answer
163 views
unzip two different kind of file extensions
Note here, .zip and .jar is just an example, my file extensions are different. Suppose I have a directory which can contain number of zip files
a.zip b.zip c.zip
AND/OR
z.jar x.jar y.jar
along ...
2
votes
2answers
253 views
zsh: excluding files from a pattern
Say I have the following files:
|-- bar
`-- foo
|-- type_A_1
|-- type_A_2
|-- type_B_1
|-- type_B_2
|-- type_B_xx
|-- type_B_xx
`-- something_else
I thought the ...
2
votes
3answers
2k views
How can I loop through lines of a file and find files matching each line?
In a BASH shell, I would like to take the lines of a file (eg pattern.txt) and find the files on my system whose names contain the patterns in each line of my file. So, I have the following for loop
...
2
votes
6answers
74 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 ...
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 ...
2
votes
6answers
226 views
Copy/Move whole folder but with certain extentions
I have a backup copy of my site located in /tmp/backup and want to copy it to /home/mysite/public_html
But my aim is to copy only the .php files (with nested folders) and replace.
If I don't have ...
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
...
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
...
2
votes
2answers
207 views
Untar directory from large tarball
How do I untar a directory that I don't know the path to? I only know the directory name.
I know how to untar a single file with a wildcard: tar -xf somefile.tar.gz --wildcards --no-anchored ...
2
votes
1answer
333 views
Bash globbing hidden files
I'm trying the following globs in a bash shell:
$ ls -d .*
. .. .a .ab
$ ls .a*
.a .ab
$ ls .[!.]*
.a .ab
$ ls .[!.]?*
.ab
Shouldn't the last expression mean "a dot followed by exactly one ...
2
votes
4answers
190 views
Access the last file (alphabetically) in a directory
I'm trying to open a file with vim from the command line, the file is in a directory filled with automatically generated files that are prepended with a time stamp. Since I don't know the time stamps ...
2
votes
1answer
498 views
shopt -s nocaseglob is not working on Ubuntu
Case insensitive file name globbing is not working in bash on Ubuntu 11.04 64bit. The shell options specified in .bashrc are as follows:
shopt -s nocaseglob
shopt -s nocasematch
shopt also shows ...
2
votes
2answers
224 views
How do I output a count of all files with “tty” in the filename in the Linux directory that holds files on system devices
I am having trouble knowing how to output a count of all files with “tty” in the filename in the Linux directory that holds files on system devices.
2
votes
3answers
266 views
loop to paste specific files in different directories
I some directories that contain a similarly named file eg (*Sample_name*.base.coverage.txt). And I would like to paste all of the *base.coverage.txt files together. I have something written, but its ...
2
votes
3answers
91 views
Selecting latest files and grouping by name
I have a directory containing files of the following name structure.
<device>.<yyyy-mm-dd-hh-mm-ss>
I am working on a script that will retain the the last X copies of these ...
1
vote
2answers
3k views
Delete files in a directory that match a regexp, using a Mac terminal
How do I delete files in a directory that match a given regexp, or a similar solution, using a Mac terminal?
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 ...
1
vote
1answer
484 views
Difficulty making a regular expression to find at least 2 occurrences of a character in a file
I have a file containing random codes. Each code has ten characters in it, and I am trying to grep codes in the file that have at least 2 occurrences of a character. I am doing this:
grep DD* ...
1
vote
3answers
1k views
Selecting files that start with $LETTER, or a letter later than $LETTER in the alphabet
Suppose a directory contains the following files:
afile1
afile2
bfile
cfile
ffile
ffile2
qfile
zfile
I am looking for an easy way of selecting all the files which start with $LETTER, or start with ...
1
vote
5answers
918 views
ls: Do not show directories that match same pattern in wildcard searches, only files
Supposing I have something like the following, a typical business PC situation:
drwxr-xr-x 1 whatever whoever 3 Oct 3 16:40 invoices2009
drwxr-xr-x 1 whatever whoever 4 Oct 3 16:40 ...
1
vote
2answers
57 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, ...
1
vote
3answers
137 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
3answers
2k views
List only regular files (but not directories) in current directory
I can use ls -ld */ to list all the directory entries in the current directory. Is there a similarly easy way to just list all the regular files in the current directory? I know I can use find
find . ...
1
vote
1answer
178 views
Extended file globbing not working with cat inside bash script
When, in my terminal, I type
cat ~/my/+(a|b)/doc
It reads ok from both ~/my/a/doc and ~/my/b/doc, but when I put that command in a bash script:
#!/bin/bash
cat ~/my/'+(a|b)'/doc
I get the error:
...
1
vote
2answers
320 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 ...
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.
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 ...
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 ...
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 ...
1
vote
3answers
468 views
How can we rename a file with semi-colon as part of the filename?
I tried to rename all file with extension "XLS;1" to "XLS" but it just didn't work.
I tried the following in cygwin in windows xp and they don't work:
mv *.XLS;1 *.XLS
mv *.XLS\;1 *.XLS
mv ...
1
vote
2answers
145 views
Generate a list of files from a file containing a series of globbing patterns
I am looking for a way to build a list of files by parsing a file that contains a sequence of zsh globbing patterns.
The final goal is to pass this list of files to hg add in mercurial. For those ...
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 ...
1
vote
3answers
123 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 ...
1
vote
1answer
90 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
83 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
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
...
1
vote
1answer
193 views
restricting pushes to selected Mercurial repositories using `ssh` forced commands and `hg-ssh`
The context of this question is the hg-ssh script. It is helpful but not critical to know something about Mercurial. This script sets up a forced command using public keys so the given public key ...
1
vote
2answers
141 views
Listing all my files modified more than X days ago, in long format
How can I list in long format all files (located in a directory) which belong to me (rights) and were modified more than 7 days ago?
1
vote
1answer
115 views
imagemagick globbing multiple extensions
I have a folder containing photos coming from different cameras.
I use Imagemagick to convert to resized and renamed photos in another folder.
Something like this:
convert "*.jpg" \
-resize 640 ...
1
vote
1answer
63 views
List all the matched files starting from an index
In zsh, there is the [m,n] glob qualifier which works as follows:
[beg[,end]]
specifies which of the matched filenames should be included in the
returned list. The syntax is the same as for ...
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 ...
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:
...
0
votes
2answers
2k 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.
0
votes
2answers
72 views
HTTP Downloader that supports directory index? So that I could use globbing?
Is there an http downloader that supports globbing?
i.e. I would like to fetch the latest update of a package, abc-XXX.rpm, but the XXX (version number) is unknown to me. Is it possible to do a ...
0
votes
4answers
184 views
Bash Globbing Variable Substitution? [duplicate]
Possible Duplicate:
Batch renaming files
I want to rename files using their existing name as a base for the new one.
So if I can ls these files with
ls blue*+(.png)
I'd want to rename ...