Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [recursive]

Operating on a directory and its subdirectories, recursively.

0
votes
1answer
46 views

Limiting recursive 'aws s3 ls' searches by number of items in the folder

Here's the scenario: I need to recursively search through tons and tons of folders and subfolders and spit out the results to a log file using the ls command, BUT, I need to stop searching a folder ...
1
vote
1answer
74 views

Bash - Recursive directory/file rename

I have the following script, that will replace all spaces in files and directories recursively: ################### SETUP VARIABLES ####################### number=0 # Number of ...
0
votes
2answers
39 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 ...
3
votes
3answers
60 views

substitute with SED recursively

Is it possible to substitute a sample recursively in multi directory with grep and sed like that ? grep -e "http://localhost:4000" -r ~/dev_web/_site | sed -e 's/http:\/\/localhost:4000/https:\/\/...
2
votes
2answers
50 views

Recursively grep through epub files

I tried the answers here, but without luck. find . -name "*.epub" -exec zipgrep pattern {} \; showed me "matched", but didn't give me the matching epub file back. Also, it returned huge blobs of ...
1
vote
1answer
29 views

Inline replace comments in files recursively

I have tried using the cloc tool with the --strip-comments parameter, which is correctly stripping the comments from all files recursively, with 2 issues: it cannot do it "in-place" the resulting ...
0
votes
0answers
25 views

wget with acceptance test, redirect fails the test

I'm running the command: wget -r --wait=2 --random-wait -P ./pdfs -A pdf -e robots=off https://www.<somesite>/documents The command has worked on other sites to recursively download all pdfs, ...
-2
votes
3answers
31 views

how to know list of file types under Directories & Sub-directories [closed]

Under CentOS, how to know file types under directories & sub-directories in one command? Output should look like: .inc, .inp, .odb, .a3db, .......
0
votes
1answer
41 views

Recursively copying directories with a given name

With a directory structure built using #!/bin/bash for name in A B do mkdir -p /tmp/src/${name}/copyme echo "do not copy" > /tmp/src/${name}/no.txt echo "copy" > /tmp/src/${name}/...
0
votes
2answers
366 views

how to untar specific files recursively in linux? [duplicate]

I have lots of tar(.tar.bz2) files containing multiple file types in a recursive directory. I want to extract just one type of file(let's say .txt files) from all the directories. How do i do that? I ...
0
votes
3answers
43 views

wget only parent pages using {..}

I have been trying to download specific pages in website. The site uses common URL to go to next pages like below. https://example.com/pages/?p=1 https://example.com/pages/?p=2 https://example.com/...
0
votes
2answers
321 views

Move all .txt files into one directory [duplicate]

I have almost 6000 directories with thousands of files: all/recup_dir.1/1.txt all/recup_dir.1/2.jpg ... all/recup_dir.5987/1.txt all/recup_dir.5987/2.txt ... and I want to move all .txt files in the ...
0
votes
3answers
53 views

Fast string replace in recursive directories

How can I do a fast text replace with recursive directories and filenames with spaces and single quotes? Preferably using standard UNIX tools, or alternatively a well-known package. Using find is ...
5
votes
3answers
596 views

How to chmod only on subdirectories?

Given the following directory tree: . ├── d1 │   └── workspace ├── d2 │   └── workspace ├── d3 │   └── workspace ├── d4 │   └── workspace └── d5 └── workspace I need to set the permissions for ...
5
votes
2answers
84 views

How to iterate through dynamically changing list of files - Ubuntu bash

I have the function: function vacatetmp () { echo "Vacating TMP folder ${1}...." for i in "$1"/*; do if [ -f "$i" ]; then caseit "$i" elif [ -d "$i" ]; then ...
0
votes
1answer
33 views

Make all files in a dir executable (non-recursively) while strictly-ensuring non-recursivness

I grasp the heading of this question odd, but I do wonder if in some situations there should be a need to take extra caution and somehow "enforce" non-recursivness when changing permissions with chmod ...
0
votes
2answers
955 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 ...
2
votes
2answers
241 views

Accidentally created symbolic link to a folder in that folder

I was creating a symbolic link to folder1/folder2 in home-folder. But I accidentally did: ln -s folder1/folder2 while in folder2 instead of in home-folder. So I ended up accidentally creating a ...
0
votes
2answers
81 views

why find is recursively listing .log files even though the search pattern is not quoted

The find command I am using is recursively listing all the .log files even though the matching pattern is not quoted. As far as I know, if the search pattern is not quoted, it will be expanded by the ...
0
votes
1answer
273 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-...
1
vote
0answers
54 views

Just recursively changed the ownership of “/” to my own user by accident. How screwed am I? [duplicate]

Was messing around with an external drive and wanted to change the permissions of a folder. However, I accidentally ran sudo chown myuser -r /. I have never felt so dumb in my life. I immediately ...
10
votes
1answer
1k views

cp behaves weirdly when . (dot) or .. (dot dot) are the source directory

This answer reveals that one can copy all files - including hidden ones - from directory src into directory dest like so: mkdir dest cp -r src/. dest There is no explanation in the answer or its ...
1
vote
1answer
738 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 ...
0
votes
1answer
60 views

Combination of totally opposite grep options

I did: grep -r -H -L txt ~ And grep -r -l -L txt ~ Does it lists all the files? Because I am getting a really long output.
0
votes
1answer
56 views

Start Recursive Script as systemd unit

I want to execute a script on startup. The script is recursive and calls itself. When I added systemd unit for the same, it is executing but getting stopped in 1 min due to DefaultTimeoutStartSec. It ...
0
votes
0answers
212 views

Recursively mounting root in a chroot

I have a (slightly complex) script which logs me into a chroot filesystem image for various purposes (not jail or security related, just needing different root environments for some things). In some ...
1
vote
1answer
389 views

How to remove all occurrences of .DS_Store in a folder

Think of it as going to the most high level folder, doing a Ctrl Find, and searching .DS_Store and deleting them all. I want them all deleted, from all subfolders and subfolders subfolders and so on. ...
0
votes
3answers
304 views

Recursively find files by content

I want to recursively find files in my source tree by contents. I've tried the following using grep: $ grep -rn printf | grep %s | grep bcm_errmsg\(rv\) This returns me every line as I wanted but ...
0
votes
0answers
55 views

Rsync won't sync recursively two directories in 2 different NTFS partitions

I am using Linux Mint 17, arch x64. When trying to sync two directories from 2 different locally mounted NTFS partitions, it won't recurse, but instead copy only the files found in the 1st level ...
1
vote
1answer
90 views

Different behaviors between find -exec and piping through xargs [duplicate]

I wanted to recursively run chmod go+w in a particular folder including hidden files, and I first tried find . -name ".*" -o -name "*" -exec chmod go+w {} \; but I found that it wasn't affecting ...
1
vote
1answer
522 views

Using rename to rename files and directories

I'm using the Linux rename command line tool to search recursively through a directory to rename any directories as well as files it finds. The issue I'm running into is the rename command will rename ...
0
votes
3answers
47 views

If file data starts with a certain hex sequence, run strings command on the file

I want to recursively crawl a directory and if the file has \x58\x46\x53\x00 as the first 4 bytes, I want to run strings on the file.
1
vote
4answers
515 views

Recursively rename files by using a list of patterns and replacements

I have the following file structure: Some directory Some file.txt Another file here.log Yet another file.mp3 Another directory With some other file.txt File on root level.txt Another file on root ...
0
votes
1answer
203 views

find and copy exec command not recursive [duplicate]

I'm running this command to find all the files named deploy.php in my whole project and make a copy of them and place them in the same directory as they were found, with name deploy_bkp.php find . -...
6
votes
2answers
364 views

filter in “find” ignored when output fed to tar

I have the following directory structure: test/ test/1/ test/foo2bar/ test/3/ I want to compress directory "test" excluding everything which is in subdirectories (depth not predefined), which ...
4
votes
1answer
487 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
3answers
6k views

How to copy “just files” recursively

Suppose I have this structure for folder0 and subfolders and files in it. folder0 subfolder01 file011 file012 subfolder02 file021 file01 file02 I ...
0
votes
1answer
63 views

Parallelize recursive deletion with find

I want to recursively delete all files that end with .in. This is taking a long time, and I have many cores available, so I would like to parallelize this process. From this thread, it looks like it's ...
10
votes
4answers
479 views

How to extract a specifically named folder from a recursive directory, delete the others?

I realize the title is vague, best explained with an example. I have this kind of directory tree that is obtained from unzipping a zip file: x -> y -> z -> run -> FILES AND DIRECTORIES HERE So ...
0
votes
2answers
427 views

Is it safe to do recursive compression with tar, gzip and pigz?

If I make a .tar.gz via tar czvf - ./myfiles/ | pigz -9 -p 16 > ./mybackup.tar.gz, Can I safely unzip an already gzip'd file ./myfiles/an_old_backup.tar.gz within the ./myfiles directory via ...
0
votes
1answer
119 views

Does `mv --context` (for selinux, a.k.a. -Z) correctly apply labels recursively to directory contents?

mv -Z applies the default selinux context. Does it differ from all other invocations of mv, and work on all the files in a moved directory individually?
1
vote
2answers
75 views

Move directories despite of errors

When moving a directory to another drive, if there are errors in the process, nothing will be deleted. I am getting this kind of errors: mv: cannot stat ‘originaldirectory/longpath/irrelevantfile’: ...
1
vote
2answers
114 views

recursively mark all files in a directory as modified without changing file content

I am on a system which deletes files which haven't been modified in 30 days. I need some way to preserve important files by marking them as being recently modifed. What is the best way I can do this? ...
3
votes
1answer
106 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
1answer
102 views

Diffing two directories recursively based on checksums?

I'm trying to find what files don't exist by a checksum of their content. I have two directories /foo and /bar, both of these directories represent arbitrary states on the system, I want to find all ...
0
votes
1answer
492 views

Move Files from Directory up one level

I have a filestructure with several subfolders where I'd like to search for all subfolder containing a certain string ("sub*") and then move all of the files in these found folders up one level from ...
1
vote
3answers
400 views

Change name of all PNG files in directory recursively [duplicate]

I have a directory called assets and it contains a file structure similar to this: ├── a │   ├── b │   │   ├── c.png │   │   └── d.png │   └── b2 │   ├── e.png │   ├── f.png │   └── g.png ...
3
votes
2answers
8k views

Replace string in multiple files using find and sed

So I've arrived at the conclusion that for recursively replacing all instances of a string in directory (only for .java extensions files) I need to use find . -type f -name "*.java" -exec sed -i 's/...
1
vote
1answer
539 views

How to create directories containing index.html with wget --recursive?

I'm pretty happy how wget -r works and downloads the things. I have set up a localhost server which serves a website and the pages look like this: http://localhost:8080/ http://localhost:8080/foo ...
0
votes
1answer
165 views

counting recursively files and directories

I need some help for this : Let's say I am in a directory and in this directory there are other directories and files etc... I would like to use a recursive function to count all the files and ...