4
votes
2answers
50 views

Script to loop through folders with numeric names

I am working on a bash script to compress the images in my Wordpress folders. The wordpress folder structure is as follows: > wp-content/uploads/2014/01/filename.jpg > ...
2
votes
1answer
52 views

Specifying full range of printable ASCII characters in a glob pattern

I want to use a globbing pattern to match only printable (including space) ASCII characters 0x20 through to 0x7e. This is being used inside a super super.tab database. I've arrived at the pattern: ...
15
votes
6answers
501 views

How do I copy multiple files by wildcard?

I have a folder with a number of files in it ABC.* (there are roughly 100 such files). I want to duplicate them all to new files with names starting with DEF.* So, I want ABC.Page1 ABC.Page2 ...
3
votes
1answer
33 views

grepping with “shopt -s globstar extglob”

I have shopt -s globstar extglob in my ./bashrc. I'm searching for files that refer to string Foo in the following command: grep -Fwn Foo /**/src/**/*.@(h|cpp) Now I want to except all refers from ...
36
votes
2answers
2k views

Why does rm *(1)* remove all files in a directory?

I expected that: $ rm *(1)* would remove all files containing (1) in the name. I was wrong. It removed all files in the directory. Why?
2
votes
1answer
53 views

bash globstar matching

I have this directory structure: ~/tmp/globstar ɀ find dir -type f dir/file.ext dir/subdir1/file.ext dir/subdir2/file.ext and, with the globstar option enabled in Bash, I can say: ~/tmp/globstar ...
2
votes
1answer
34 views

Can I use variables inside {} expansion without `eval`?

Can I use variables inside {} expansion without appealing to eval? If so, how? This doesn't work: $ touch 1.foo 1.bar $ ls 1.{foo,bar} 1.bar 1.foo $ extensions=foo,bar $ ls 1.{$extensions} ls: ...
2
votes
2answers
82 views

delete directory with special character in filename

I have these tricky directories that I can't figure out how to delete. If I run ls -ld * I get… drwxrwxr-x 7 user1 taskfmri 2048 Jan 22 15:26 857263 drwxrwx--- 4 user2 ...
11
votes
2answers
1k views

What is the difference between “du -sh *” and “du -sh ./*”?

The title says it all. What's the difference between those 2 commands? NOTE: I'm more interested in the * and ./* part.
3
votes
1answer
40 views

**/ not working with a mounted volume

I'm trying to recursively extract a set of .jpgs from a mounted volume using SMB1, to a folder on my computer. Here's what I've got: cp -a **/97*.jpg /Users/.../All_Covers This works as long as my ...
5
votes
2answers
120 views

How does GLOBIGNORE work?

According to bash's manual page: GLOBIGNORE A colon-separated list of patterns defining the set of filenames to be ignored by pathname expansion. If a filename matched by a ...
3
votes
4answers
206 views

Searching a pattern in file names with number

I have a large number of files in a folder each with the date as the filename. For example 20130101 20130102 20130103 . . . 20130131 similarly for other months 20130201 to 20130230, the pattern is ...
3
votes
2answers
515 views

Bash globbing and argument passing

I have the following simplified bash script #!/bin/bash files=("$@") if [ "X$files" = "X" ]; then files=$HOME/print/*.pdf; fi for file in "${files[@]}"; do ls "$file"; done If I pass ...
3
votes
1answer
48 views

How to cd open / autocomplete a folder that ends in a specific phrase

I have a folder with subfolders named like this: 1122334 important things 1122335 less important things 1122336 notes 1122337 pictures of kittens etc The numbers at the beginning are date codes. ...
1
vote
2answers
229 views

In a Bash if condition, how to check whether any files matching a simple wildcard expression exist?

Stupidly, I had been using a condition like this as part of a script: if [ $(ls FOO* 2> /dev/null) ] # if files named "FOO*" were downloaded then echo "Files found" # ... process and ...
5
votes
2answers
347 views

Copy all dotfiles except for `.git` and `..`

I am aware of using .[!.]* to refer to all dotfiles in a directory with the exception of .., but how might one refer to all dotfiles except for .. and .git? I have tried several variations on ...
2
votes
2answers
123 views

Discrepancy between the two expansions

If you input the command ls * and echo *, you will notice the remarkable discrepancy between the results. The former recursively includes while the latter totally excludes files in subdirectories. ...
2
votes
4answers
730 views

How do I select files in a bash script that do not have an extension?

Let's say I have files xinitrc, alphabetsoup, ieat.pie in the current directory. Need a bash script to select only xinitrc and alphabetsoup.
2
votes
4answers
568 views

Shell script to check for the presence of one or more files with a specific extension?

I want to write a script to find a file with specific extension.this much i have done: #!/bin/bash file="/home/Savio/Dsktop/check/*.csv" file1="/home/Savio/check/*.txt" if [[ -f "$file" && -f ...
1
vote
1answer
727 views

delete files matching pattern

I need to recursively remove all files in all subdirs where the filename contains a number followed by an 'x' followed by a number, at least two times. Example: I'd want to remove these files: ...
1
vote
1answer
167 views

Bash command that uses wildcard in place of folder to copy folder contents of multiple files into one directory?

I have a directory ~/dir that contains a bunch of random folders like: ~/dir/av 801 and ~/dir/lm 320. I want to copy the contents of every inner folder (ie: av 801) into a different directory. The ...
1
vote
2answers
321 views

How do I run a command on multiple files

This is pretty basic, I have a folder with several subfolders of JS files and i want to run Google's Clojure compiler on all of the files in those folders. The command to process a single file is as ...
4
votes
3answers
4k views

Test if there are files matching a pattern in bash

I am trying to write an if statement in bash to test whether there are any files matching a certain pattern. If there is a text file in a directory it should run a given script. My code currently if ...
3
votes
5answers
2k 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?
3
votes
2answers
219 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 ...
27
votes
7answers
3k 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
3answers
380 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 ...
4
votes
3answers
211 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
92 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: ...
8
votes
5answers
336 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
667 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
308 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
1answer
95 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
1answer
336 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 ...
2
votes
2answers
361 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
123 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
103 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
185 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
342 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 ...
4
votes
3answers
477 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 ...
2
votes
2answers
67 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
788 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 ...
2
votes
2answers
147 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 ...
7
votes
7answers
3k views

How do I create a directory in all subdirectories?

Suppose I have a directory structure like this: $ [~/practice] ls a/ b/ c/ d/ Now I want to create a directory tmp1 in all sub directories of practice and I do this: $ [~/practice] mkdir */tmp1 ...
0
votes
4answers
385 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 ...
15
votes
3answers
663 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 ...
2
votes
2answers
117 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 ...
4
votes
4answers
469 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 ...
2
votes
1answer
307 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
570 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 ...