All Questions
Tagged with recursive shell-script
39
questions
0
votes
1
answer
75
views
Can find reliably call itself from -exec without breaking the semantics of the two instances?
Following http://superuser.com/questions/1780479 and http://superuser.com/questions/1777606, we issue the following script to compare times of the same–full-path symlinks under directories $1 and $2:
#...
1
vote
4
answers
3k
views
Apply same sed command on multiple text files
I am doing some pre-processing on files. I have 2 text files which contains data in the following format.
Text File 1
"Name","Age","Class"
"Total Students:",&...
0
votes
3
answers
390
views
Recursively traverse directories and retrieve last timestamp file
Let's suppose I have the following timestamp like directory tree:
root
|__ parent1
| |__ 2021
| | |__ 01
| | | |__ 22
| | | | |__ 12H
| | |...
0
votes
1
answer
376
views
Make API requests recursively without large number of processes running
I have the following Script File 'bored.sh'. This file recursively calls itself.
curl "https://www.boredapi.com/api/activity" >>./bored.json
sleep 1s
bash ./bored.sh
I realized that ...
0
votes
1
answer
146
views
Perform loop in HPC within multiple subdirectories one after another
I know this is a repeated question, but none of the suggestions I saw kinda fit what I wanted.
I'm working with an HPC cluster that has different modules to perform different actions for high ...
3
votes
2
answers
416
views
How might one except hidden '.' files and directories from a script that renames them?
I have a script that renames, getting rid off the whitespace, every directory and file. It does it recursively:
#!/bin/bash
find -name "* *" -print0 | sort -rz | \
while read -d $'\0' f; ...
0
votes
1
answer
1k
views
How do I recursively tar+gzip folders with a specific name?
I have a large file structure with multiple nested folders. I would like to tar+gzip up every folder with a specific name and remove the original folder.
In this example the script I hope to have ...
0
votes
2
answers
5k
views
Unix how to copy file to directory and echo
I am trying to write a script using a for loop to copy files to a directory that will also echo the copy command to the terminal. I have successfully gotten the script to copy files, however, am ...
1
vote
1
answer
450
views
Append file name to beginning of [Markdown] file recursively
I have a folder with a whole lot of folders with a whole lot of Markdown files in each. What I'd like to do is recursively (if possible) prepend the file name as a heading in each file.
So, given foo....
1
vote
1
answer
252
views
Recursive thumbnail creation to different destination
I wish to show my photo collection on my television. In order to do this, I need to resize the photos to fit in a 1920x1080px window (because the performance is awful when dealing with the originals).
...
0
votes
1
answer
2k
views
Flattening directory and renaming files incrementally (MacOS)
Looking to flatten the directory (with duplicate child file names) while renaming all files, keeping duplicates OR appending all file names with an incrementing number (incrementing # + name would be ...
2
votes
2
answers
5k
views
how to unzip a zipped file which include various zip level files in unix/linux? [duplicate]
For example my folder name is
Test.zip
Test.zip includes various zip folders like te1.zip, te2.zip , te3.zip
even te1.zip include various zip folders.
So i need to unzip in linux at once.
Could ...
0
votes
1
answer
580
views
How do I write a shell script to flatten directories?
I wrote a simple script to delete useless files from a directory using the find command.
Now I'm wondering if I can add lines to the script to flatten directories, but not completely flattened.
e.g.,...
2
votes
2
answers
2k
views
Sort and mv files based on filename (with spaces), recursively
I have made a mistake and dumped files together into the same directory. Luckily I can sort them based on the filename:
'''
2019-02-19 20.18.58.ndpi_2_2688_2240.jpg
'''
Where the # bit or 2 in this ...
1
vote
2
answers
643
views
Bash recursive call fails
I am writing a function in ./bashrc to switch environment variables, commands, etc. This function is supposed to set up the necessary variables then call itself. Instead I get
bash: ./bash: No such ...
0
votes
2
answers
160
views
zip files within all sub-directories of a given parent directory
Say I have a parent_directory/ with the following sub-directories child1/, child2/ and child3/.
How do I script to zip all *.txt files in childx/ into childx.zip
I also want this childx.zip to be ...
1
vote
2
answers
12k
views
Recursively iterate through all subdirectories, If a file with a specific extension exists then run a command in that folder once
I need to recursively iterate through all the subdirectories of a folder.
Within the subdirectories, if there's a file with an extension '.xyz' then I need to run a specific command in that folder ...
0
votes
1
answer
3k
views
How to touch everything in a directory including hidden, like directory up `..`?
This question has parallels to question "touch all folders in a directory".
How to touch everything in a directory,
recursively
including hidden entries, like "directory up" .. and .
without de-...
2
votes
1
answer
5k
views
How to create recursive function call in unix
#!/bin/sh
checking()
{
cd "$1"
for D in *;do
if [ -d "$D" ]; then
cd "$D"
for d in *;do
echo "$d"
if [ -d "$d" ]
then
`checking() $d`
fi
...
4
votes
1
answer
2k
views
Recursive call script
I am trying to make a script that will list all files and directories in a given directory. I want to make this script to call itself, in the end showing all files and directories. I know that you can ...
3
votes
1
answer
351
views
Create symbolic link recursively for pictures with unique filename altough timestamp is not enough
The photos of my cameras (.CR2 or .JPG) have correct exif date + time but only in seconds, unfortunately not in milliseconds. Therefore some photos have the same date_time value (shot at the same ...
1
vote
4
answers
2k
views
Renaming files recursively in sh
I use Synology as storage for films from CCTV cameras. After copying a file from the CCTV system to Synology, I convert it to the AVI format. So my files have names like this:
10.01.07-10.01.48[M][@0]...
0
votes
2
answers
1k
views
explain recursion syntax
I'm new to shell, and UNIX / GNU/Linux.
I'm trying to understand this syntax that is part of a recursion function:
[ $i -le 2 ] && echo $i || { f=$(( i - 1)); f=$(factorial $f); f=$(( f * i ...
4
votes
1
answer
13k
views
Print recursively all directories and subdirectories
I am trying to print all directories and sub directories with a recursive function but I get only the first directory. Any help?
counter(){
list=`ls $1`
if [ -z "$(ls $1)" ]
then
...
-4
votes
2
answers
422
views
recursive script not working
I am trying to add recursive support to my filegrep script.
For some reason this does not work as expected:
RECURSIVE_MODE=off
# iterate over args
for ARG in "$@"
do
if [ -d "$ARG" ] && ...
1
vote
2
answers
275
views
Create symbolic link recursively, if file 1.JPG exists rename it to 1A.JPG
I have a shell script for creating symbolic links of all my photos from one year. The photos are from different cameras and are in subdirectories.
f=$(pwd);
export f;
q="2015/";
z="2015_Links/";
find ...
1
vote
2
answers
3k
views
List files in hierarchy of directory
I need to list files in hierarchy of directory. For that I wrote script like
foreach file ( * )
ls ${file}/*/*/*/*/*.root > ${file}.txt
end
But for this I have to know that in the directory ${...
1
vote
1
answer
711
views
Create tree of processes
I'm implementing pstree as an assignment,
and I would like to create test tree of processes, but I'm struggling to do so.
I tried to do something like this to create tree of background processes ...
2
votes
1
answer
3k
views
How do I copy all files that have been created or modified in the last 12 months?
I would like to copy all the files created in the last 12 months to a new folder leaving behind everything else. Including sub folders.
7
votes
4
answers
3k
views
Converting `for file in` to `find` so that my script can apply recursively
I have this idea of running a bash script to check some conditions and using ffmpeg to convert all the videos in my directory from any format to .mkv and it is working great!
The thing is, I did not ...
58
votes
6
answers
69k
views
Finding largest file recursively
I am trying to find the largest file in a directory recursively. If there is a subdirectory inside of that directory the function needs to go inside that directory and check to see if the largest file ...
0
votes
2
answers
344
views
check two partitions by selecting random files and running sha1 hashes on two files of each partition
A previous answer to a post mentions to run sha1 hashes on an images of a dd drive clone image.
Another answer to that post suggests mounting the dd image an then compare if the sha1 hashes of "...
6
votes
3
answers
13k
views
bash script calling itself with different arguments
I just can not get it right.
Script takes two arguments, target and command. Valid targets are specified within an array. If target is 'all', script should iterate through all targets.
#!/bin/bash
# ...
4
votes
2
answers
3k
views
Read all files in folder and subfolders - progress and size
Command I have is:
time find . -type f -print -exec cp {} /dev/null \;
This command finds all files in current folder and subfolders, print the name of each file and copy each of them to /dev/null. ...
3
votes
2
answers
2k
views
Moving large numbers of files and directories to a different directory
I'm trying to move the following move a large number of files that exist in the following structure to a /mnt/originals but I need to maintain the structure at the same time. I know cp would be a ...
0
votes
2
answers
3k
views
Using `ls` recursively without -R
I am trying write a shell script that has output similar to ls -R without using the option -R.
This is part of a programming assignment that forbids me from using -R, find and du. I need to identify ...
4
votes
2
answers
2k
views
Merging folders with practically the same name but different casing
When digging around in the advanced settings in Dropbox I lost a folder. I only discovered this about a month later. I managed to get this folder back from Dropbox however the file structure of the ...
7
votes
5
answers
5k
views
How to deal with spaces in a variable
I'm working on some scripting:
for x in `find ./ -name *.pdf`
do
echo pathname $x
done
My filenames are Test1 ( Volume II), Test2 ( Volume II).
I'm getting a return of
pathname Test1
pathname (
...
2
votes
3
answers
4k
views
Script to count files matching a pattern in subdirectories
I wrote the following script for finding the number of pdf and tex files from the current directory, including the subdirectories and hidden files. The following code is able to find the number of pdf ...