Globbing means matching files by name patterns containing wildcards.
3
votes
1answer
366 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
482 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* ...
12
votes
8answers
10k 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
289 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
447 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
4k views
What's the best way to count the number of files in a directory?
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 ...
7
votes
2answers
4k 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 ...
6
votes
3answers
3k 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
196 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 ...
4
votes
2answers
478 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 ...
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 ...
2
votes
4answers
189 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
485 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 ...
3
votes
2answers
482 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
309 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 ...
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 ...
4
votes
4answers
5k 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 ...
10
votes
1answer
376 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?
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 ...
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 ...
3
votes
1answer
191 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
609 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
285 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 ...
3
votes
1answer
269 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 ...
7
votes
1answer
3k 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
1answer
598 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*' ...
3
votes
2answers
230 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
762 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.
...
3
votes
7answers
238 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 ...
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 ...
6
votes
1answer
6k views
Bash: assign ls | grep to a variable and echo it with a string
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
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 ...
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 ...
4
votes
1answer
152 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
103 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
1k 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
225 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
139 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 ...
5
votes
3answers
263 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 ...
5
votes
5answers
2k 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
249 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 ...
2
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 ...
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?
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
3answers
735 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 ...
8
votes
7answers
840 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 .*
5
votes
2answers
500 views
ls, regexp and environment variable
I wanted to declare an environment variable that stocks all the extensions of video files so I can use it when using the shell.
I tried several things but never got it to work:
If in my .bash_profile ...
14
votes
3answers
12k views
How do you move all files (including hidden) in a directory to another?
How do I move all files in a directory (including the hidden ones) to another directory?
For example, if I have a folder "Foo" with the files ".hidden" and "notHidden" inside, how do I move both ...
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 ...
3
votes
1answer
448 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 ...
