Globbing means matching files by name patterns containing wildcards.

learn more… | top users | synonyms (2)

4
votes
1answer
24 views

“[--0]” globbing pattern in man pages

I am a Linux/Unix newbie. I was reading about "Glob" and "Globbing Pathnames", and I found this strange (to me) part in man pages: "[--0]" matches the three characters '-', '.', '0', since '/' ...
4
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 ...
1
vote
1answer
51 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 ...
0
votes
3answers
47 views

Number of files in a directory starting with specific text

How to get count of files in a directory starting with specific text like dataxxx.csv
4
votes
2answers
42 views

Unzip source arguments

To copy a bunch of zip files from one location to another: $ cp *.zip destination/ To unzip a bunch of zip files to a directory: $ unzip \*.zip -d destination/ man unzip says: The backslash ...
-1
votes
2answers
136 views

delete files having a certain pattern in their names

I want to delete all files that have two numbers and a dot in beginning of their names for example: 01. abc 02. xyz
1
vote
3answers
335 views

List files that do not begin with a specific prefix

I need to list only the files in a directory that do NOT begin with qc_dl, qc_dt or qd_df, but that also DO end in .sas. I can list the files that do not begin with "qc_dl" as such: ls -I "qc_dl*" ...
2
votes
2answers
76 views

order for listing files

If I have a list of files under a directory ullman-000.pbm ullman-001.pbm ... ullman-098.pbm ullman-099.pbm ullman-1000.pbm ullman-1001.pbm ullman-1002.pbm ullman-1003.pbm ullman-1004.pbm ...
37
votes
6answers
6k views

The result of ls * , ls ** and ls ***

I know using the command ls will list all the directories. But what does the ls * command do ? I used it and it just lists the directories. Is the star in front of ls means how deep it can list the ...
2
votes
4answers
72 views

Find files that end with number

Im trying to make some backup script as the log files get bigger and bigger. What i have is coping the current file, (for example secure file in /var/log/) and remove the content from that file. But ...
2
votes
1answer
38 views

Find Command: File Path vs -name Argument

I'm currently building a script to handle some files in a directory. In the first example, I use the find command and pass a directory in as the argument. In the second I instead use the -name switch ...
0
votes
1answer
26 views

Shell glob expansion after loop variable substitution

How can the following be changed example so that it does glob expansion after loop variable substitution? for i in a b c do echo $i/*.txt done UPDATE: This normally does work, however set -f ...
0
votes
1answer
29 views

defining rename command scope; replace word; replace entire file name; wildcards

Im looking to use the rename command to edit file names. More specifically, Im trying to isolate specific pieces to change, or in some cases, the whole name. For example: Lets say I have three ...
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 ...
2
votes
2answers
59 views

Bash extended globbing

I'm unable to show JUST ONE file from the output of ls using bash extended globbing. From info bash If the `extglob' shell option is enabled using the `shopt' builtin, several extended pattern ...
2
votes
2answers
43 views

Tar a list of files which don't all exist

I'm running a command from a script like tar -c -f ar.tar a b c d where b, c, and d may not exist, and may be directories. The solutions that I've come up with are piping the output of ls -d to ...
3
votes
4answers
204 views

what is the difference between `find .` and /home/user/* as an input to for command

What is the difference between find . and /home/user/* as an input to for command.? For example: for var in $(find .) do echo "$var" done or for var in /home/user/* do echo "$var" done In the ...
5
votes
3answers
286 views

How to view last 5 lines from last created/modified file?

Every day I have to take backup and update the status to support teams at particular time for which I need to check last 5 lines of last created/modified *.aff file in a directory and update them. ...
2
votes
2answers
92 views

How to show only total file size of particular extension by `du` command

I have a hundreds of pdf files and html files in a directory. And I want to know total size of pdf files. By command du -ch /var/foo I can see total file size but I only need last line, the total ...
0
votes
2answers
39 views

can I use logical operators to remove all files that matches with one and/or other pattern in a single line?

I want to remove .txt or .csv files in a single line. What I have in my directory tachomi$ ls file1.csv file1.sql file1.txt file2.csv file2.sql file2.txt I only want .sql files so I want to ...
0
votes
4answers
273 views

keep the last file of every month and delete the rest

I have files like below. I want to keep SEP 30, OCT 30....files and delete the rest. Can you please help me with any script? -rw-r--r-- 1 nbswmcm advboprd 13463761 Sep 2 01:19 ...
5
votes
5answers
112 views

How can I programatically tell if a filename matches a shell glob pattern?

I would like to tell if a string $string would be matched by a glob pattern $pattern. $string may or may not be the name of an existing file. How can I do this? Assume the following formats for my ...
1
vote
3answers
394 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 ...
2
votes
1answer
19 views

How can I use `find` with `-pattern` and also restrict depth?

This is as far as I've gotten: find . -path \*/pages/*/index.css Which will find: ./lib/pages/home/index.css ./lib/pages/home/lib/header/index.css What I really want is to only find: ...
2
votes
3answers
29 views

Specifiy Unix TimeStamp Range in Parameter

I am launching a mrjob in bash and need to pass in as parameters a range of gz files which have unix time stamps in them as: filename_9127381923.gz. How to do this in the simplest possible way? I can ...
6
votes
1answer
163 views

Exclude one pattern from glob match

I have several files with the same base filename. I'd like to remove all but one foo.org #keep foo.tex #delete foo.fls #delete foo.bib #delete etc If I didn't need to keep one, I know I could use ...
5
votes
2answers
845 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 ...
0
votes
2answers
132 views

proper way to iterate through contents in a directory [duplicate]

I need to iterate through every file inside a directory. One common way I saw was using the for loop that begins with for file in *; do. However, I realized that it does not include hidden files ...
1
vote
1answer
24 views

How to copy with wildcard in directory name?

I would like to copy the html directory inside a directory like cms_drupal_PROJ-1-2 to /var/www. The last digit in the working directory is dynamic so at any given time all I know is ...
4
votes
8answers
269 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 ...
24
votes
8answers
2k views

Dealing with file names with special first characters (ex. ♫)

I have recently come across a file whose name begins with the character '♫'. I wanted to copy this file, feed it into ffmpeg, and reference it in various other ways in the terminal. I usually ...
2
votes
4answers
297 views

Passing wildcard * to a (bash?) script [duplicate]

I want to to remove all color codes which look like '@n', '@R' etc, from a moderately large size collection of text files. So in a file called 'remove_cc', I wrote the following: sed -ie 's/@r//g' ...
1
vote
1answer
58 views

Wildcards in exclude-filelist for duplicity

I am trying to exclude a "bulk" folder in each home directory from the backup. For this purpose, I have a line - /data/home/*/bulk in my exclude-filelist file. However, this doesn't seem to be ...
0
votes
1answer
75 views

move files of a particular pattern to another directory

In the directory /home/in I have files like this: crust.MC12345.txt crust.etcMC12345.txt crust.MC23456.txt crust.etcMC23456.txt crust.etctcMC23456.txt I only need to move crust.etcMC12345.txt ...
0
votes
1answer
64 views

Unix: What happens if I enter ls -d [2-q]*

Would it just ignore the bit after the -d option since you cant arrange characters lexically between 2 and q?
0
votes
1answer
205 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 ...
2
votes
1answer
29 views

search files using group permission

If i need to search files using group permission I use the following command echo **/*(AIE) where AIE stand for read/write/execute. For owner and group permissions the qualifier used are rwx and ...
1
vote
1answer
55 views

du skip symbolic links

I cannot find an example of what I want to do and, from what I'm reading, the default behavior of du on my system is not the proper default behavior. If I ls my /data folder, I see (removing the ...
2
votes
2answers
50 views

Wildcard for arbitrary depth

I want to use grep where paths are arbitrary depth under the directory /path/to/dir and has the file name foo. I thought that the wildcard for arbitrary depth is **, and I tried grep some_pattern ...
-5
votes
2answers
1k 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 ...
4
votes
2answers
785 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 ...
5
votes
3answers
396 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 ...
3
votes
4answers
80 views

How can I get the first match from wildcard expansion?

Shells like Bash and Zsh expand wildcard into arguments, as many arguments as match the pattern: $ echo *.txt 1.txt 2.txt 3.txt But what if I only want the first match to be returned, not all the ...
2
votes
1answer
121 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 ...
-2
votes
1answer
137 views

Find files using ls and wildcards

pwd : ../bin under bin I have a directory called datafiles. Use meta characters and the ls -lL command (with lower and upper case L) to list all filenames under the datafiles directory that contain a ...
0
votes
4answers
2k views

How to rotate all images in a directory with imagemagic?

I want to rotate all the images in a directory that match a pattern. So far I have: for file in `ls /tmp/p/DSC*.JPG`; do convert $file -rotate 90 file+'_rotated'.JPG done but that gives no ...
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 ...
1
vote
2answers
63 views

Find doesn't want to find *.sh in certain level [duplicate]

I have a problem with find. It doesn't find *.sh files if I am in certain directory level. It does, however, find *.sql files. /path$ cd do_not_upload/updates/1.1.1/ ...
11
votes
6answers
8k 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 ...
26
votes
1answer
1k views

Why does my regular expression work in X but not in Y?

I wrote a regular expression which works well in a certain program (grep, sed, awk, perl, python, ruby, ksh, bash, zsh, find, emacs, vi, vim, gedit, …). But when I use it in a different program (or on ...