Stack Exchange Network

Stack Exchange network consists of 175 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
2answers
49 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
2answers
48 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 ...
-6
votes
1answer
61 views

What is the meaning of -r and -R in copy command?

I read that they stand for recursively in the man page. However, I am not sure what their role is in the command. When I tried to copy some empty directory into another directory with, $ cp EMPDIR ...
0
votes
2answers
23 views

Recursively copying a folder to an empty subfolder

How to copy all the content of the folder /foo/bar, which contains the file /foo/bar/a to an empty subfolder /foo/bar/subfolder without ending up with the file /foo/bar/subfolder/subfolder/a. Doing cp ...
0
votes
1answer
38 views

Move Files Recursively but only if they are not open by another process

I want to modify the script text below, to change the file permissions, owner and move it, only if the file is not open by another process. cd /mnt/usbdrive/DVR sudo chown 777 -R /mnt/usbdrive sudo ...
1
vote
1answer
103 views

Recursively converting Windows files to Unix files

I have a PHP application with is located on Linux with multiple directories (and sub-directories) and many PHP, JS, HTML, CSS, etc files. Many of the files have Windows EOL control characters and I ...
0
votes
2answers
71 views

Recursive conversion of jpeg files

I use this commandline to convert jpegs to pdfs inside a folder. for f in *.jpg; do echo "Converting $f"; convert "$f" "$(basename "$f" .jpg).pdf"; done However, I would like to convert all .jpg ...
0
votes
0answers
40 views

How to run command recursively on files within directory and sub-directories within? [duplicate]

How can I run the command below recursively on all directories and sub-directories within? [someone@someones-pc ~]$ for i in *.mp4; do ffmpeg -i "$i" -i watermark.png -filter_complex "overlay=1623:25"...
0
votes
1answer
201 views

Use SCP from local machine to recursively copy current working directory to remote?

Trying to do something like (in pseudo-unix): scp -r <pwd> username@remote.com:~/<dirname of toplevel> In other words, I'm trying to copy the current directory I'm in locally (and the ...
3
votes
1answer
61 views

Command “tree” vs “tree -R”

So I'm asking myself why there is the "-R" argument for the "tree" command. The manual says "-R Recursively cross down the tree each level directories ...", but I don't see any difference in the ...
0
votes
0answers
37 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
392 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
195 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
256 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
97 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
2k 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
171 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
44 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
68 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
421 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
340 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
56 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
232 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
120 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
105 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
34 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
227 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
2k 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
105 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
1k 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
284 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
2k 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
123 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
40 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
3k 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 ...
3
votes
2answers
941 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
222 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
749 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
67 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 ...
13
votes
2answers
3k 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
2k 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
81 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
81 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
689 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
523 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
87 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
156 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
677 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
56 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.