Globbing means matching files by name patterns containing wildcards.

learn more… | top users | synonyms (2)

2
votes
3answers
115 views

!(*.sh) works on the command line but not in a script

When I use the code below in a terminal on Ubuntu, it works fine: rm !(*.sh) -rf But if I place the same line code in a shell script (clean.sh) and run shell script from terminal, it throws error ...
1
vote
2answers
28 views

zsh - complex filename matching [on hold]

I have files in the following filename format: filename.mainsuff filename.mainsuff_username filename.mainsuff_username_accounting filename.mainsuff_username_info How would I go about only listing ...
0
votes
0answers
38 views

What does the double star/asterisk wildcard expand to? [duplicate]

For example, Where are your test specs located? (./test/specs/**/*.js) Will that descend in all subdirectories under ./test/specs/, recursively? What authoritative source discusses this ...
1
vote
2answers
35 views

Piping contents of multiple files between programs while keeping contents separate

I would like to read in a number of files and pipe their output to subsequent programs while still maintaining them as individual pipelines of data. program1 *.txt | program2 | program3 folder I ...
2
votes
3answers
61 views

Copy only directories with .mp3 files with rsync

I'm trying to copy only folders with .mp3 files in them to another device. And only the .mp3s in them. The structure looks like this: Band/Year - Album/*.flac Band/Year - Album/*.txt Band/Year - ...
1
vote
1answer
41 views

du reports directory size as much bigger than the sum of its contents

Running du -shc * in the top directory gives 110G for a particular folder, whereas running the same command inside that folder gives a total size of 11G. How is that possible? Platform Details: OS: ...
1
vote
1answer
39 views

Copy array of multiple files with globbed extensions, in bash 3.2

I've found bits and pieces of each of the things I want to do across the Web, but nothing exactly fits my use case. I'm trying to write a script that copies multiple specific files to a directory on ...
2
votes
3answers
59 views

reverse cat files order

I need to do log analysis and I am facing problem that cat access.log* display latest log file first. I tried to sort logs which takes a lot of time because I have logs from couple of years back. And ...
2
votes
1answer
72 views

Unable to get back to bash prompt after strange command

I was messing about with different wildcards and ran the following command: ls testdir/!(*/) after which I was completely unable to get back to the bash prompt. None of ^C, ^D, or even ^Z worked: ...
1
vote
1answer
28 views

Handle wildcards matching no file in bash

I am trying to read files from a directory into an array but even when the file doesn't exist, its saved in array. I want to exclude the file name if it doesn't exist. a=(/tmp/nofileexists) ...
1
vote
1answer
61 views

Listing directories and understanding ls

On ls man page, I saw this -d, --directory list directory entries instead of contents, and do not dereference symbolic links on my current folder: drwxr-xr-x 2 oracle oinstall 4.0K Jul ...
3
votes
7answers
156 views

for loop in bash lists dot and double dot folders [duplicate]

for f in ~/common/.*; do echo $f done The entries listed are, /home/sk/common/. #undesired /home/sk/common/.. #undesired /home/sk/common/.aliasrc And i am putting a ugly ...
2
votes
5answers
139 views

Testing if files start with certain letters and contain no special character except for period at end next to file extension in a shell script

I have a shell script that runs a for loop to execute a command on multiple text files in a folder. I want to test if these files' names start with a specific set of letters (NA for instance), and ...
1
vote
1answer
65 views

Delete all files to which no corresponding file with another extension exists

My goal is to find a Linux command sequence, which deletes some files if a special condition is fulfilled: All files with the extensions .cut or .cut.bak in the current directory shall be removed, IF ...
3
votes
1answer
59 views

Parameter expansion in variable assigned with a wildcard

I have two files in my current folder (MA502) whose names are - MA502_TAAGGCGA-TCGCAGG_L001_R1_001.at.fastq MA502_TAAGGCGA-TCGCAGG_L001_R2_001.at.fastq I have many such folders - ex MA503, MA504 ...
2
votes
3answers
260 views

copy all files that have no extension

We can copy some file by extensions like this: cp *.txt ../new/ but how can I copy all files that have no extension?
0
votes
3answers
66 views

Creating a script that runs a simple command for all files in a directory

I need to use the text-based browser Lynx to dump 1000s of html files into text files, with the same filename. For any given filename.html the command is lynx filename.html --force-html --dump > ...
2
votes
3answers
106 views

Delete several sequential file names, but ignore part of the first

Sometimes, my scripts get trapped in infinite loops. When the loop creates new files, things get messy. I currently have this file name format: Task.4883.store.log where 4883 is a counter. I ...
2
votes
3answers
39 views

grep .* returns results from .bash_history and complains about

I'm new to Linux and so far I've been playing around with some utilities, specifically the grep utility. I decided to create a new file (aptly called 'newfile') with the following content: Lady of ...
3
votes
1answer
150 views

Bash substitution with variable defined from a glob pattern

The below example explains the issue. Why is the FILENAME printed correctly when echoed and perceived as a pattern when using substitution? #!/bin/bash FILEPATH_WITH_GLOB="/home/user/file_*" ...
3
votes
1answer
98 views

Filename Expansion: Find Utility Pattern Matching vs Bash Shell Pattern Matching

For filename expansion, the 'find' utility's '-name' option seems to function similarly, but not exactly the same as the bash shell's builtin pattern matching. Here are the relevant sections of the ...
4
votes
2answers
114 views

Difference between find ~ and find *

What is the difference between find * and find ~ for searching a file? In terminal when my present working directory on root,then in terminal root@devils-ey3:~# find * -print -quit ~ On same ...
1
vote
1answer
95 views

Why is Bash returning “No such file..” when pattern matching this string?

I have the following for loop: for f in ~/.lo-rcs/common/* do . $f done which is returning this error: bash: /home/sk/.lo-rcs/common/*: No such file or directory I keep classifying my bashrc ...
20
votes
9answers
2k views

Find files whose name is 4 characters long

I would like to find files whose name has only 4 characters. Example, there are three files under /tmp: $ ls /tmp txt file linux Output should only show file because it only has 4 characters.
0
votes
1answer
51 views

tar exclude files *.zip

Why don't *.zip patterns work in tar : tar cfjv backup.tar.bz2 --exclude mydir/files/*.zip mydir Is there another syntax?
1
vote
3answers
68 views

Find a file with the extension .csv in a directory matching a pattern

I have a folder in which I have many subfolders. The Root folder name is allCSV and sub foldername is will be like a_date(s), b_date(s), c_date(s) ... I want a file which is in a_date(s) and ends ...
1
vote
2answers
78 views

Copy .txt files in a certain directory

I have an issue in copying my file in my directories. I have .txt and .jpeg files in a lot of directories, and I want to copy only the .txt files according to the directory. For example, I have this: ...
10
votes
1answer
188 views

Why is nullglob not default?

In most shells nullglob isn't the default. That means, for example, if you run this command ls * in an empty directory, it will expand the *-glob to a literal ' * ', instead to an empty list of ...
4
votes
4answers
94 views

Searching file in a directory through bash script

I have written the following code to search all the file names in the current working directory that contain the letter 'f'. for i in * do echo $i if [ $i = "*f*" ] then echo "no" else ...
6
votes
2answers
166 views

Extended Glob: What is the difference in syntax between ?(list), *(list), +(list) and @(list)

I have a question after reading about extended glob. After using shopt -s extglob, What is the difference in the following? ?(list): Matches zero or one occurrence of the given patterns. *(list): ...
1
vote
2answers
80 views

Why can't unrar expand this expression?

I had three RAR files in the same directory: file1.rar, file2.rar and file3.rar. I wanted to extract them with one command using expansion, bearing in mind that asterisks have to be escaped in ...
4
votes
4answers
465 views

List all the files ending with 10 or 11 or 12

To list all the files ending with 10 or 11 or 12 I have tried ls *[10-12] and ls *[10,11,12] but these are not working. I don't know why. Can anyone help me?
5
votes
2answers
194 views

scp command behaves differently when used with expect utility

expect -c 'spawn scp -C -o CompressionLevel=9 ~/partFiles/* abc@10.200.4.15:/export/home/abc/; sleep 10; expect password; send "secretPassword\n";interact' throws - ~/partFiles/*: No such file or ...
0
votes
1answer
19 views

updatedb.conf, Ignore files using pattern match/globbing

Running locate command with a file name returns multiple entries as, a.py a.pyc a.py~ Obviously, i am not looking for binaries/compiled files. I tried to configure locate command to ignore files ...
2
votes
2answers
77 views

Does zsh expansion work differently in non-interactive scripts?

I'm currently working on a pretty simple zsh script. What I often do is something like: mv */*.{a,b} . When I run that within a zsh script, it seems to expand differently and fail while it works in ...
8
votes
1answer
296 views

Bash wildcard to match exactly n characters

Is there a wildcard in bash to match exactly 5 characters, shortening a pattern like ?????
2
votes
3answers
172 views

tar unix not changing directory

I am executing a tar command to compress files which are present in another directory. I executed following command: tar -czf /backupmnt/abc.tar.gz -C /backupmnt/statusService/ * I want to create ...
6
votes
2answers
212 views

Exclude one directory in `ls` matching pattern

I'm trying to ls dirs that have .png files inside (no need for recursiveness, though it would be extra useful), exept one. Exlude one directory i.e. ls */*.png works fine. ls (^one)*/*.png ...
0
votes
4answers
147 views

Foreach loop for ls output

I am trying to process some files in directory using foreach loop for ls output: IFS=$'\n' for i in $(ls -1Atu); do echo "$i" done At first time i thought it works, but when i created file ...
2
votes
2answers
356 views

ls pattern matching

I know that [] is working in ls pattern matching: $ ls foo.c foo.h $ ls foo.[ch] foo.c foo.h but I cannot find where this is documented. I would like to know the syntax that would match these: ...
2
votes
1answer
59 views

Prevent glob expansion in foo=“*”; echo $foo [duplicate]

In Bash, when I do: foo="*" echo $foo It expands * to the contents of the current folder. How do I make sure it just prints a literal *? The same, by the way, happens with a regular echo "$foo", ...
1
vote
2answers
113 views

How can I select 3 character files in Bash?

I know that a question mark is considered a special character and it has special meaning. Question mark represents a single character that can be any type. In my practice lesson we have an example : ...
3
votes
1answer
47 views

Shell glob - substitute file path arg with file's contents

In curl command, there is --data option, which substitutes the file contents when the option value is prefixed by @ symbol like, curl -X POST --data @abc.json hostaddr.com abc.json file contents ...
0
votes
2answers
37 views

is it possible to open files in subdirectories with less?

I sometimes use less to quickly page through a small collection of files using something like less brscan/*/* and then I use :n to cycle through the files If I have a folder/s e.g. brscan/ ├── ...
4
votes
2answers
84 views

Expand wild cards in command before executing it

Suppose I want to type something like this: rm build/* tmp/* I am about to run it but I want to expand the wildcards before executing so I can verify what is about to happen. How can I do this? ...
28
votes
2answers
847 views

find(1): how is the star wildcard implemented for it to fail on some filenames?

In a file system where filenames are in UTF-8, I have a file with a faulty name; it is displayed as: D�sinstaller, actual name according to zsh: D$'\351'sinstaller, Latin1 for Désinstaller, itself a ...
4
votes
1answer
265 views

Why does `du -sh *` complain about invalid options?

I've searched my best through Google, but for the life of me I can't figure out what to use instead of * (asterisk) after a recent update (even Wikipedia seems to think du -sh * and du -sh * should ...
4
votes
2answers
136 views

brace expansion and * expansion

Assume in the working directory, there is only one djvu file. I would like to backup the file into a file with file name having extra .bk at the end. cp *.djvu{,.bk} copies the djvu file into a file ...
21
votes
7answers
1k views

`command .*` acts on the parent directory [duplicate]

Someone of our team wanted to recursively change the user permissions on all hidden directories in a users home directory. To do so he executed the following command: cd /home/username chown -R ...
3
votes
2answers
60 views

Shell globbing without matching files

I frequently make use of shell file name globbing to do things like operate on all of /dev/sda, /dev/sdb, /dev/sdc, etc by doing /dev/sd[a-f], however, this relies on there being files on disk that ...