All Questions
97 questions
4
votes
4
answers
313
views
BASH - Find file with regex - Non-recursively delete number-only filenames in directory
I'm wanting to non-recursively delete all files in a directory where each filename contains only numbers, using only a single line of BASH.
I somehow accidentally ran a shell script with commented out ...
7
votes
3
answers
699
views
Pass result of find command as another command's multiple options
I have a CLI tool that can take an option with multiple values - The syntax is like this:
CLI -I path/to/file1 -I path/to/file2 ...
How can I pass the result of the find command to this CLI?
For ...
0
votes
1
answer
72
views
find -exec bash -c {} +: why only one file of found two?
touch 1.txt 2.txt
find . -name "[12].txt" -exec sh -c 'echo "${1}"' sh {} + -exec echo {} +
./2.txt
./2.txt ./1.txt
Why echo within sh -c outputs only one file? Today I thought I ...
3
votes
5
answers
415
views
Replace empty lines in one file with lines from another file
I have file1.csv
"word 1"
""
"word 3"
""
"word 5"
"word 6"
and file2.csv
"replacement text 1"
"replacement text 2"
&...
0
votes
1
answer
107
views
How to pipe output of a command to another command (which does not take a file as input?) [duplicate]
What I want
Simplified command: echo "helloworld" | echo $1
I know, this would be possible with cat, but what if a command like echo does not take a file as input?
My actual command: ls -...
-1
votes
1
answer
177
views
shell endless loop for find command
I was working on a shell script where I came across this problem that I couldn't solve
The following command is supposed to find all shell files in /.
PATHS_SHELL=$(sudo find / -name '*.sh') ...
0
votes
0
answers
78
views
find with -execdir: returning nonzero on test failure
I'm using the following command in my CI/CD system to run some unit tests that are in Go modules in subdirectories:
find . -name go.mod -execdir go test -v -cover ./... \;
...which works great, except ...
4
votes
1
answer
967
views
Find directories with name, but filter them if they contain a specific top-level file in them
I want to find all directories that are named Contents and then from the list of found results, I want to filter them and only include those that have a file named Database.json directly inside them.
...
1
vote
2
answers
791
views
Script to find all empty git repositories on a machine
We know an empty git repository only has the .git directory in it.
I want to find all git repositories on a machine, which are empty.
I thought about this process:
Find all directories that are named ...
1
vote
1
answer
176
views
Using move command to move all files and subdirectories with find
I have a folder /home/storage/aggregate_data with many sub-folders which in turn contain many files and sub-folders.
I want to copy all the files older than 90 days within the folder /home/storage/...
1
vote
3
answers
1k
views
bash count files and directory, summary size and EXCLUDE folders that are fuse|sshfs
I need help for a bash script that counts files and folders in a specified directory on a Linux system (Debian), but I want to exclude a specified folder.
I have a main directory named workdir with ...
0
votes
1
answer
71
views
Question on the use of ~ in bash
I'm trying to find all bash scripts in home and its subdirectories with "find" and to do this I typed the following in the terminal:
find ~ -name '*.sh'
it returns the .sh files contained ...
4
votes
3
answers
3k
views
Is there a way to make find use shell's extglob shell option?
In short, I instinctively wrote a command like this to find the two files prefix.ext and prefix_suffix.ext down a hierarchy
find /some/path -type f -name 'prefix?(_suffix).zip'
but it doesn't work.
...
1
vote
3
answers
2k
views
find: How to efficiently search for big list of filenames
I need to find a few hundred files, where the base names are provided by some list (let's call it baseNames). I then need to search for these base names + three given extensions.
Example: Assume one ...
1
vote
0
answers
700
views
I have a text file with a list of files I need copied how do I do this?
I have a text file that has a list of files with each file name on a new line. Those files exist in multiple subfolders. I need to copy those files to a separate folder where all of the files that I'm ...