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

Questions tagged [recursive]

Operating on a directory and its subdirectories, recursively.

0
votes
0answers
34 views

Exclude the specified directory when use grep [duplicate]

I tried to recursively search $ grep -r "hold stat" . grep: ./C/APUE/apue.3e/figlinks/fig14.21: No such file or directory as a solution, exclude the dir with $ grep -r "hold stat" --exclude-dir ./...
1
vote
2answers
65 views

How to recursively copy a directory using cpio?

How do I copy recursively a directory within the list at my-files-to-copy.txt? cd my/source/dir cpio --create < my-files-to-copy.txt | (cd my/dest/dir && cpio --extract) my-files-to-copy....
1
vote
1answer
55 views

How to use istat on AIX like stat on Linux distributions

In Linux, I use the following command to show this output: find /backup/$INSTANCE/tsm/* -exec echo '"{}" ' \; | xargs stat --printf "chown %U:%G '%n'\nchmod %a '%n'\n" >> /tmp/permissions.txt ...
1
vote
1answer
33 views

How to search for a folder or file in parent folders [duplicate]

I tried to search for a folder in its parent folders instead of its child sub-folders (usually any search bash command will do). I need to know whether any reverse alternative for any search commands ...
0
votes
4answers
81 views

Recursively rename all the files without changing their extensions?

How to recursively rename all the files in several layers of subdirectories without changing their extensions? Below's a toned down version (to save room) of what I've got. For argument's sake, I ...
4
votes
1answer
461 views

Wget: downloading files selectively and recursively?

Question about wget, subfolder, and index.html. Let's say I am inside "travels/" folder and this is in "website.com": "website.com/travels/". Folder "travels/" contains a lot of files and other (sub)...
0
votes
2answers
49 views

setfacl -R doesn't work on Cygwin

I want to change the ACL and the default ACL for all directories and files in a base directory. In other answers (such as this one), the -R flag is used. However, I get $ setfacl -R -m u::rwx my_dir/ ...
0
votes
1answer
21 views

Copying a source directory using the command cp -rsf when target directory exists

On Centos 7, when I use the command: cp -rsf /path/of/source /path/of/target When the target directory exists, files would go to /path/of/target/source. How can I avoid that? EDIT: source and ...
0
votes
1answer
28 views

Copy files from a source folder recursively to destination/*file_extension*(ex. “txt”) folder

This is my code, something in the rec_copy() function isn't working properly, the extension named folders are created in the destination folder but the files are not copied there. #!/bin/bash if [ $# ...
0
votes
1answer
261 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
239 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
50 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
148 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
74 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
32 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
55 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
33 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
71 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
1k 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
64 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
832 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
75 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
4answers
1k 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
98 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
37 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
2k 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
488 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
144 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
460 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
62 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
2k 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
1k 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
69 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
66 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 ...
1
vote
1answer
496 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
371 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
63 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
110 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 ...
3
votes
1answer
592 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
49 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
607 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
254 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
391 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
615 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
7k 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
82 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
499 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
475 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
219 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
77 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’: ...