Globbing means matching files by name patterns containing wildcards.
4
votes
3answers
240 views
How to pipe to multiple places with vertical bar?
I have a folder full of files with a .dot extension like this:
a.dot
b.dot
c.dot
I want to go through all the files in this folder and run a command on them such as this:
dot -Tpdf a.dot -o a.pdf
...
4
votes
2answers
209 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 ...
4
votes
2answers
500 views
ZSH: Recursive globbing with .directories
I thought the glob pattern:
**/(*|.*)
would represent every folder and file starting with dot (.) or not, but it skips directories in the current directory that start with ..
What is the glob ...
4
votes
4answers
298 views
Find files without a number
I am trying to write a simple script that will iterate through all drives except sda. Right now I have this
for i in $(find /dev/ -name "sd*" ! -name "sda*")
do
echo $i
done
However this ...
4
votes
4answers
789 views
file $(ls /usr/bin/* | grep zip) command gives me errors. What's wrong?
I'm a total noob when it comes to unix/linux commands and I decided to read a book.
I've reached a chapter where they try to explain how to pass the output of commands as expansions to the shell.
...
4
votes
1answer
158 views
How/why does this globbing expression work?
In one of my bash scripts I needed to obtain the last part of a colon delimited string. For example I needed to grab the numeric 289283 value from the following value:
OK: DriveC-ReadBytesPerSec: ...
4
votes
8answers
213 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 ...
4
votes
4answers
6k views
How do I recursively delete directories with wildcard?
I am working through SSH on a WD My Book World Edition. Basically I would like to start at a particular directory level, and recursively remove all sub-directories matching .Apple* - how would I go ...
4
votes
2answers
508 views
How can I search for a file with fixed name length using ls?
In a directory, I have files like
lazer_100506
lazer_100707
lazer_091211
lazer_110103
lazer_100406_temp
lazer_100622#delete
etc
How can I get a listing of only the first four files?
$ ls ...
4
votes
1answer
128 views
What is the tool that allows me to specify arbitrary directories using **
I once saw a colleague uses a tool which allows to use ** to represent any directories. For example: if a file called myfile.java sits deep inside:
src/main/com/mycompany/product/store/myfile.java
...
4
votes
2answers
53 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
...
4
votes
3answers
339 views
Delete matching file from every subfolder of current dir
I used this one to copy file in every dir:
find -type d -maxdepth 1 -print0 | xargs -0 -n1 cp .htaccess
Now i need to do reverse one and delete file with matching name from every sub directory of ...
4
votes
3answers
87 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 ...
4
votes
3answers
328 views
How can I list all *.doc files in a Zip archive, including files in subdirectories?
I have Zip files, that might look like this:
$ zipinfo -1 zip.zip
doc.doc
dotx.dotx
xls.xls
ppt.ppt
txt.txt
c.c
subdir/subdir2/doc.doc
subdir/xls.xls
subdir/ppt.ppt
subdir/c.c
subdir/txt.txt
...
3
votes
4answers
182 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
3answers
370 views
Using OR patterns in shell wildcards
Contents of my dir are
$ ls -lrt
total 0
-rw-r--r-- 1 user1 admin 19 Oct 8 12:31 night.txt
-rw-r--r-- 1 user1 admin 19 Oct 8 12:31 noon.txt
-rw-r--r-- 1 user1 admin 38 Oct 8 12:31 day.txt
I ...
3
votes
5answers
406 views
How do I extract all .htaccess files from a tarball?
I want to extract all .htaccess files from a tarball, how can I do so? I see only one mention of "include" in the manual page of tar which is not related with an option for including only certain ...
3
votes
2answers
435 views
How can I search a wild card name in all subfolders?
How can I search a wild card name in all subfolders? What would be the equivalent of DOS command: dir *pattern* /s in *nix?
3
votes
3answers
248 views
Fastest way to open all files in a directory with multiple file extensions on commandline
If I want to open all mp4 files in a directory, I can simply do something like totem *.mp4. But how can I open all mp4 and all flv files in that directory with one command. I.e. I want to do something ...
3
votes
7answers
239 views
“which” with a little “grep”-like solution?
# which mkdir
/bin/mkdir
# which mkdi
#
How can I get the path of the e.g.: "mkdir"'s binary without knowing the name of the binary file? (command). So that which "mkdi" would output the ...
3
votes
4answers
74 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 ...
3
votes
1answer
226 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
...
3
votes
3answers
1k views
checking an argument to a bash script is a string of all digits
The Bash FAQ says
If you're validating a simple "string of digits", you can do it with a glob:
# Bash
if [[ $foo = *[!0-9]* ]]; then
echo "'$foo' has a non-digit somewhere in it"
else
echo ...
3
votes
3answers
163 views
is the behaviour of .* to include . and .. defined in LSB or POSIX or some other specification?
as title: is the behaviour of .* to include . and .. defined in LSB or POSIX or some other specification?
3
votes
5answers
177 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 ...
3
votes
2answers
143 views
returning strings corresponding to shell glob matching
Suppose I have a subdirectory called sub. Then I want to operate on all files in that directory with the extension "txt". I want something like
for f in sub/*.txt
do
enscript -b "" -o {$f ...
3
votes
2answers
76 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 ...
3
votes
3answers
257 views
Get a list of 3 letter commands on Mac OS X
How can I either create or find a list of 3-letter unix commands on Mac OS X?
I'd like to create a new program/command for a project. I'd like to make it a 3-letter name, but I don't want to conflict ...
3
votes
1answer
376 views
How do I filter a glob in zsh
Basically I can use a glob in zsh to a list. Often, it turns out, I would like to filter that list, grep'ishly I'm wondering though, if I need to do that.
Does zsh have a method to filter a list? ...
3
votes
2answers
58 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 ...
3
votes
1answer
69 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 ...
3
votes
1answer
469 views
scp, globbing, and different shells
The other day at work I tried doing
scp remotehost:~/*.txt .
and I received an error about the *, *.txt file not found sorry, not at work and I forget the exact error
on my workstation I run zsh ...
3
votes
2answers
234 views
How can I make bash not match `.` and `..` with `.*`
When I try to match all dot files in a directory with .* it seems to have a nasty side-effect: besides matching all (real) files and directories, it matches . and ...
bash-3.2$ mv test/.* dest/
mv: ...
3
votes
2answers
155 views
Finding program name by wildcard pattern
I am trying to write a script that will attempt to find if a certain program is installed. Lets say that the program is called, myprog. The problem is that the program can be named in different ...
3
votes
2answers
542 views
Multidigit ranges of files in lexicographical order in zsh
I would like to specify a range of files (in lexicographical order) with two integers (e.g. 2 to 57) in zsh by globbing.
For example: "pick the files 2 to 57 in lexicographical order under the path ...
3
votes
2answers
2k views
How to use 7z to archive all the files and directories (including hidden ones) in a directory?
Because of specifics of my archiving needs I am not comfortable with solid tar.gz archives and use 7z instead.
I use the following command to do this:
7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m ...
3
votes
2answers
232 views
Splitting a large directory tree by file type
I have a large data directory (20-30Gb) on my Ubuntu 10.10 desktop machine that consists of many raw data files, processed data files, and assorted scripts, tables, figures etc. generated from the ...
3
votes
4answers
92 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:
...
3
votes
1answer
145 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 ...
3
votes
1answer
193 views
Copy files in different subdirectories that excludes a string
I'm trying to copy all files of a type in a given directory and subdirectories but excluding files of a different type.
find /var/ftp/pub/bs -iname "*foo*.foo" -exec cp {} /var/ftp/pub/bs1 \;
...
3
votes
1answer
279 views
ZSH: Globbing the first N files under a path in lexicographic order
I was wondering if there is a way to specify the first N files under a given a directory in zsh.
I am interested in solutions for recursive enumeration (i.e. any file recursively below a path is ...
3
votes
1answer
529 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 ...
3
votes
4answers
2k views
How to exclude numeric directories with rsync?
I know rsync has an --exclude option which I use quite frequently. But how can I specify that it should exclude all "numeric" directories?
In the directory listing below I would like to only have it ...
3
votes
3answers
1k views
Get the number of files that match a pattern in a directory and delete the oldest one
I'd like to do the following:
Get the number of files in a given directory that match a given pattern, for example:
ExtractBackup_{date}.tar.gz
If that number is 2 or higher, delete the oldest file ...
3
votes
2answers
281 views
How to enable tab completion of wildcards in bash?
How can I enable tab completion in bash for a statement such as vim db/migrate/*crea? Essentially I am looking for tab completion to match the regular expression and present the options.
How would ...
3
votes
3answers
305 views
Configure bash globbing
After coming from cygwin, I'm quite confused about the bash (version 4.1.5) globbing on my Ubuntu 10.4. I'd love one of the following two possibilities:
ignore . and .., match everything else
ignore ...
3
votes
1answer
615 views
rsync pattern copy: dotfiles
I followed the advice given in the question
Rsync filter: copying one pattern only to setup a command line I need to backup only the dotfiles .inF*
Yet with the command:
rsync -av --include='.inF*' ...
2
votes
6answers
2k views
Show only hidden files (dot files) in ls alias
I'm using the command
ls -a | grep '^\.'
for showing only the hidden files.
I added the line
alias hidden='ls -a | grep '^\.'' # show only hidden files
to .bash_aliases file
but this does not ...
2
votes
5answers
215 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?
2
votes
2answers
170 views
What exactly did mv /tmp/folder/* /* do to my filesystem?
It's hard to search for special characters on google, which is why I'm posting this here.
I recently ran (as root) a mv /tmp/folder/* /* when I meant to run mv /tmp/folder/* ./ Big mistake!
Things ...

