Tagged Questions

Globbing means matching files by name patterns containing wildcards.

learn more… | top users | synonyms (2)

6
votes
1answer
4k views

What is the .gitignore pattern equivalent of the regex (Big|Small)(State|City)-[0-9]*\.csv

I have a regex I stuck in my .gitignore similar to: (Big|Small)(State|City)-[0-9]*\.csv It didn't work so I tested it against RegexLab.NET. I then found the gitignore man page which led me to ...
7
votes
1answer
513 views

Why is bash extended-globbing variable substitution acting at the byte level?

I thought that bash variable substitution and globbing worked at character resolution, so I was rather surprised to see it acting at the byte level. Everything in my locale is en_AU.UTF-8 When ...
4
votes
1answer
775 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? ...
1
vote
1answer
1k 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* ...
21
votes
9answers
30k 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 ...
5
votes
3answers
580 views

Bash globbing of multi-part argument

Below are some examples of a find command I'm trying to run. I'm looking for different ways that I might be able to use globbing to generate (as an example) a find command with predicates joined ...
11
votes
4answers
1k views

How do I choose specific files in a different directory using bash?

I want to list (or delete, or do some other operation) on certain files in a directory, like this: $ ls /opt/somedir/ aa bb cc aa.txt bb.txt cc.txt $ ls /opt/somedir/(aa|bb|cc) ## pseudo-bash ...
7
votes
6answers
7k views

What's the best way to count the number of files in a directory? [duplicate]

If parsing the output of ls is dangerous because it can break on some funky characters (spaces, \n, ... ), what's the best way to know the number of files in a directory? I usualy rely on find to ...
30
votes
2answers
18k 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 ...
7
votes
4answers
8k views

How do I reverse a for loop?

How do I properly do a for loop in reverse order? for f in /var/logs/foo*.log; do bar "$f" done I need a solution that doesn't break for funky characters in the file names.
-2
votes
1answer
267 views

Why does this script show all files in the directory and not just PDF files?

I wrote the script below to find the number of PDF files in a given directory. However, it instead shows all the files in the directory: #!bin/bash message="." message1="*.pdf" ls -al $message ...
6
votes
2answers
1k 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 ...
8
votes
4answers
1k views

How to silently get an empty string from a glob pattern with no matches

Say I have a folder with three files: foo1 foo2 bar 1. If I run list_of_files=$(print foo*) echo $list_of_files I get: foo1 foo2 2. If I run list_of_files=$(print bar*) echo $list_of_files ...
1
vote
2answers
225 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 ...
2
votes
4answers
901 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 ...
4
votes
2answers
822 views

mv on a glob pattern does not work without sudo

I am using MySQL database on Ubuntu machine. My MySQL data directory is /var/lib/mysql/ , since I have a database named "db_test" , so, I have a directory named db_test/ under /var/lib/mysql/ . And ...
6
votes
2answers
2k 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 ...
4
votes
3answers
842 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
2answers
5k 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 ...
10
votes
4answers
15k 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 ...
15
votes
1answer
504 views

How do ${0##*/} and ${0%/*} work?

I'm quite confused about the following regular expressions I found in a shell script: ${0##*/} ${0%/*} How do they work?
4
votes
4answers
5k 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 ...
11
votes
6answers
7k 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 ...
3
votes
1answer
289 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 \; ...
5
votes
2answers
1k views

Why doesn't “rm *” work when there are files that begin with a hyphen?

from: http://seclists.org/fulldisclosure/2011/Sep/190 [USER@MACHINE ~] mkdir ejha [USER@MACHINE ~] cd ejha/ [USER@MACHINE ~/ejha] touch ize [USER@MACHINE ~/ejha] touch -- -f -i [USER@MACHINE ...
4
votes
4answers
555 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
1answer
463 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 ...
9
votes
1answer
8k views

How to download specific files from some url path with wget

If I don't want to have to download the files found in a specific url path manually, what options do I have? Using wildcards fail: $ wget 'http://www.shinken-monitoring.org/pub/debian/*deb' Warning: ...
3
votes
2answers
1k 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*' ...
7
votes
2answers
985 views

How does a shell (bash, for example) expand wildcard patterns?

Assume that a directory has 100 files starting with the letter 'a'. If I do a grep <some string> a* from the terminal, how will the shell handle this? Will it expand the regular expression, ...
3
votes
2answers
377 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 ...
4
votes
4answers
1k 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
8answers
268 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 /bin/mkdir ...
3
votes
1answer
846 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 ...
9
votes
1answer
19k views

How can I assign the result of a command to a shell variable?

I want to assign the result of an expression to a variable and concatenate it with a string, then echo it. Here's what I've got: #!/bin/bash cd ~/Desktop; thefile= ls -t -U | grep -m 1 "Screen Shot"; ...
1
vote
1answer
291 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 ...
3
votes
3answers
3k 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 ...
4
votes
1answer
193 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: ...
0
votes
0answers
108 views

How to use find command with wildcard when current directory contains a match? [duplicate]

Possible Duplicate: find not recursive when file at top I'm having some confusion with the find command. If I type: find . -name *.xml or find ./ -name *.xml I receive a list of all ...
5
votes
4answers
5k views

Find a string only in a specific file inside subdirectories

Let's say I need to find the function GetTypes() in all C# source file (.cs) the directories/subdirectories. I used grep -rn GetTypes *.cs, but I got an error with grep: *.cs: No such file or ...
2
votes
6answers
329 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 ...
3
votes
2answers
180 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 ...
6
votes
3answers
345 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 ...
6
votes
5answers
4k views

How to copy all html files from a directory tree to a single directory?

I want to copy all the .html files in myDir and its subdirectories to ~/otherDir. Here's what I tried (it doesn't work): $ find myDir -name *.html -print | xargs -0 cp ~/otherDir usage: cp [-R [-H | ...
6
votes
1answer
328 views

Can I have my shell history record how wildcards expanded?

If I run: $ ls * foo bar buzz $ history | tail -1 ls * You can see that in my shell history it remembers that I ran ls * rather than ls foo bar buzz. Ideally, I'd like to record both in separate ...
4
votes
3answers
6k 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 ...
1
vote
2answers
197 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?
2
votes
3answers
3k 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
3answers
1k views

untar a directory of *.tgz files using a wildcard

I've got a directory that looks like $ ls Broad_hapmap3_r2_Affy6_cels_excluded.tgz DINGO.tgz GIGAS.tgz index.html IONIC.tgz passing_cels_sample_map.txt ...
11
votes
8answers
3k views

How do I delete everything in a directory?

I'm sorry for asking such a basic question: How do I delete everything in a directory, including hidden files and directories? Right now, I use the following: rm -rf * rm -rf .*