0
votes
1answer
74 views

Copying files with multiple extensions

I would like to copy files with multiple extensions to a single destination directory. For example, I can use the following command to copy all .txt files in the working directory to a directory ...
5
votes
3answers
136 views

Bash script error with strings with paths that have spaces and wildcards

I am having trouble getting the basics of Bash scripting down. Here's what I have so far: #!/bin/bash FILES="/home/john/my directory/*.txt" for f in "${FILES}" do echo "${f}" done All I want to ...
2
votes
1answer
97 views

Bash: Syntax Error on @()

I have the following function in my .bashrc file: extract() { local c e i (($#)) || return for i; do c='' e=1 if [[ ! -r $i ]]; then echo "$0: file ...
12
votes
3answers
2k views

Why does [a-z] asterisk match numbers?

I have 3 directories at current path. $ls a_0db_data a_clean_0db_data a_clean_data $ls a_*_data a_0db_data: a_clean_0db_data: a_clean_data: $ls a_[a-z]*_data a_clean_0db_data: a_clean_data: I ...
2
votes
1answer
50 views

How to use " rm !(*keyword) in bash 4.1.2?

I got bash 4.1.2 on remote centos machine. When using my favorite rm !(*keyword) I got bash: !: event not found I tried to upgrade its bash, but seems the edition remains after upgrade. The ...
1
vote
1answer
49 views

Expand shell variable without globbing

I want to check whether an input string refers to a file name - not a wildcard string like *.txt. This doesn't work: if [ -f "$1" ]; Because $1 gets expanded to *.txt, which gets expanded to, say ...
2
votes
2answers
69 views

Is a ? treated in a special way in parameter expansion?

I'm attempting to parse to output from git status --porcelain -b for use in my prompt but I'm coming across strange behaviour when performing parameter expansion. This snippet should demonstrate the ...
3
votes
4answers
260 views

Make many subdirectories at once

Suppose I have a directory /, and it contains many directories /mydir, /hisdir, /herdir, and each of those need to have a similar structure. For each directory in /, there needs to be a directory doc ...
2
votes
2answers
161 views

Bash copy all files that don't match the given extensions

When I import pictures from my camera in Shotwell, it also imports the video clips. This is somewhat annoying, as I would like to store my videos in another folder. I've tried to write a bash command ...
3
votes
2answers
76 views

Move every file that is not a directory

I have a directory that I am trying to clean out that contains both files and subdirectories. What I am trying to do is simple: move all the files into another directory, but leave all the ...
2
votes
3answers
253 views

Count files in a directory by extension

For the purpose of testing, I'd like count how many images files are inside a directory, separating each image file type by file extension (jpg="yes". This because later it will be useful for another ...
1
vote
1answer
42 views

processing multiple extensions

I have done a script to convert recursive .jpg files to another size: echo $re mkdir "$re"_tmp for a in *.jpg ; do convert "$a" -resize $re "$re""_tmp/${a%.*} ["$re"].jpg" ; done I'd like integrate ...
4
votes
5answers
422 views

Bash pattern to match all files but directories

In bash, how do I specify a pattern that matches everything but subdirectories in current directory. Given that the pattern */ matches all the subdirectories, I tried (with extglob turned on): $ echo ...
3
votes
1answer
493 views

find files without extension

Let say I have: foo.txt bar baz.ooo If I use ls -1 !(*.*) then I'll get only bar on the output. Great, now I wish to have same results with find - some find -regex that will do the job. NOTE: ...
-6
votes
2answers
443 views

Shell script to compile C files

I used to have a shell script that would compile all of the FILE.c files in a directory to FILE.out I lost it and am trying to remake it and have the following which I know is very similar but can't ...
3
votes
2answers
132 views

Error when calling mv with wildcards

#! /bin/bash error_text=$(tail -n +1 /path/dir/folder/exc/a/update/Abd/ER/* | \ grep 'Warning\|Loaded\|Event') echo $error_text nc 10.10.99.45 25 << EOF ehlo mail.abc.pvt mail from: ...
6
votes
2answers
691 views

Copying one file to multiple directories

I have a file that I want to copy to another 60 directories. The best way I can think of doing this is by making a bash script that has instructions to every folder like this: cp script.sh ...
5
votes
2answers
111 views

ls command: how to ignore case without globbing

I use the shopt -s nocaseglob command to ignore case, but it seems like it doesn't work if I use a string without glob. Just a question out of curiosity, is it possible to ignore case without ...
4
votes
2answers
470 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
93 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: ...
16
votes
7answers
3k 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
75 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 ...
40
votes
2answers
3k 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?
4
votes
2answers
594 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
59 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
324 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
2k 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.
2
votes
2answers
265 views

Bash's declare -p HISTIGNORE brings bash to a halt! Why?

Executing the following code in GNU bash, Version 4.2.45(1)-release (x86_64-redhat-linux-gnu), Fedora 19 ... shopt -s extglob export ...
3
votes
1answer
46 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 ...
6
votes
2answers
494 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
1k 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
3k 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
62 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
281 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 ...
4
votes
2answers
189 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) ...
5
votes
2answers
654 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
130 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. ...
3
votes
4answers
2k 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
3k 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 ...
4
votes
1answer
4k 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: ...
2
votes
1answer
164 views

Curly Brace glob order?

If I have two files (in a folder with similarly numbered files) such as foo.18 foo.19 And I want to use a glob on them, do I do it like so: cp -r /folder1/*.{19,20} /folder2/ or like so? cp -r ...
1
vote
1answer
493 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 ...
3
votes
2answers
1k 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 ...
6
votes
3answers
11k 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 ...
6
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?
3
votes
2answers
371 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, ...
2
votes
3answers
601 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
284 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
103 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: ...