Operating on a directory and its subdirectories, recursively.

learn more… | top users | synonyms

2
votes
1answer
26 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 ...
2
votes
3answers
48 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
25 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
386 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
58 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
15 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
68 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
38 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
69 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
39 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
73 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
1answer
68 views

Change name of all PNG files in directory recursively

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 a2 b3 h.png How can I change the name of all the images in this ...
2
votes
2answers
134 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
172 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
45 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 ...
-2
votes
1answer
61 views

delete recursive subfolders with find

I need to delete recursive subfolders in a single line For one subfolder: find folder -name "subfolder" -exec rm -r "{}" \; or find folder -name "subfolder" -type d -exec rm -r "{}" \; But in the ...
1
vote
0answers
45 views

Recursively update all Folder “Date-modified” timestamps to date of newest file

I would like to recursively update the Date Modified field of a directory (and all its subdirectories) so that every folder has the same Date Modified timestamp as the most recently modified file that ...
-3
votes
2answers
70 views

Why rm does not work recursively by default?

I was discussing with a friend trying to figure out why rm command does not, for example, check if the path is to a file or a folder automatically and delete it recursively, by default, if necessary. ...
1
vote
1answer
48 views

Recursive bash function (directory iterator)

I know that my following task could be accomplished using simpler 'find' comment, but I am trying to implement a solution using a recursive call. I am looking through a specific directory and trying ...
1
vote
4answers
148 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]...
1
vote
1answer
44 views

Recursively compare directories with summary on different contents without examining file contents' differences

I want to compare the contents of two directories, recursively, showing which files are missing from one or the other, and which files have different content. But I don't want output on the ...
3
votes
1answer
52 views

Copy only files and only lines containing a string while preserving directory structure

Say I have a directory that contains other directories and files. I want to search for a string in each file and copy only the matching lines to another location while preserving directory structure. ...
2
votes
6answers
101 views

Rename multiple files to decrement number in file name?

I have incorrectly named files which are unsynced by -1. The problem is I need to rename 1000s of them. DBGC180_805754 DBGC180_805755 DBGC180_805756 to DBGC180_805753 DBGC180_805754 ...
2
votes
4answers
287 views

How to convert all files from gzip to xz on the fly (and recursively)?

I have a directory tree with gzipped files like this: basedir/a/file.dat.gz basedir/b/file.dat.gz basedir/c/file.dat.gz etc. How can I convert all of these from gzip to xz with a single command and ...
2
votes
1answer
46 views

What is the difference between -H and -L options of chown?

From the chown manpage: The following options modify how a hierarchy is traversed when the -R option is also specified. If more than one is specified, only the final one takes effect. -H if a ...
1
vote
2answers
118 views

How to recursively side by side diff directories with line numbers in the diff in unix?

My scenario is to perform side by side diff directories using: diff -ry <folder1> <folder2> along with the line numbers in the diff output. By default line numbers are not displayed in ...
2
votes
2answers
399 views

Copying faster than cp?

I am currently copying a large number of directories and files recursively on the same disk using cp -r. Is there a way to do this more quickly? Would compressing the files first be better, or maybe ...
3
votes
1answer
198 views

Make `rsync --link-dest` find files recursively

I'm using Rsync as a backup tool. When I create a new backup, I would like it to look in all the existing backup folders for each file and if it already exists, create a hard link. From the Rsync man ...
-7
votes
1answer
170 views

Difference between changing permission Recursively or without Recursively

What is the difference in the command chmod 777 * and chmod -R 777 * changing permission recursively or normally?
0
votes
2answers
290 views

How can one recursively rename directories without sed or rename?

I am trying to rename a few directories that contain "Fever" to contain "Malaria" instead. The instruction is to do it without sed or rename. So far, my errors include mostly lines like mv: cannot ...
0
votes
2answers
67 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 ...
8
votes
5answers
3k views

How to recursively remove execute permissions from files without touching folders?

I made a backup to an NTFS drive, and well, this backup really proved necessary. However, the NTFS drive messed up permissions. I'd like to restore them to normal w/o manually fixing each and every ...
1
vote
1answer
160 views

wget not downloading files recursively

I saw some of the posts on this website about how to download files from a directory recursively. So, I executed the following line: wget -r -nH --cut-dirs=3 -A '*.bz2' -np http://www.xfce.org/...
2
votes
0answers
79 views

convert attachments of type winmail.dat (TNEF) to “real” attachments in stored email messages, recursively in MailDir

Some email messages contain the attachments in a format called TNEF (Transport_Neutral_Encapsulation_Format). This attachment is usually called winmail.dat. Extraction tools exist for linux, but ...
3
votes
1answer
614 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 ...
17
votes
9answers
6k views

Counting lines of code?

if I want to count the lines of code, the trivial thing is cat *.c *.h | wc -l But what if I have several subdirectories?
0
votes
1answer
31 views

“find” doesn't list all files under specific directories

I'm attempting to get a list of all files under specific folders, recursively, with the "find" command. find / -path "/usr/sbin/*" -o -path "/usr/bin/*" -o -path "/usr/local/sbin/*"-o -path "/usr/...
-4
votes
2answers
72 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
2answers
150 views

Rename all the files with a specific extension in all the subdirectory [duplicate]

I have a lot of directories. Each one of these has a file with a specific extension .ext. I want to rename these files. Example: // Note: The names are random, can have spaces and special ...
1
vote
1answer
122 views

Why is chmod recursively changing file permissions as well?

When I do chmod _+x -R /dir where "_" is any combination of (u,g,o,a), if after I do chmod g+X -R /dir, the files gain executable permissions as well. Why does this happen? This behavior only ...
0
votes
1answer
162 views

How could I quickly find a recursive symbolic link? [duplicate]

I am experiencing an issue with a indexing program running much longer than expected. I want to rule out the possibility of a recursive symbolic link. How could I find a symbolic link that is ...
1
vote
1answer
55 views

How to search recursively within several levels of embedded tar tgz files? [duplicate]

Can somebody help me to figure out a command to find a file recursively that is embedded in a tgz file which is within another tgz files recursively: MainFile.tgz → SubFile1.tgz → SubFile2.tgz → ...
2
votes
1answer
61 views

Will zgrep recursively search zips embedded within zips?

I am using the zutils version of zgrep v0.9 (not the gzip wrapper script) and to recursively grep zip files starting from the current folder I simply use: zgrep -r "MY_STRING" . This works fine. ...
0
votes
1answer
38 views

Bug in shell script for printing the tree-like structure of the curent diretcory

I have wrote the following script: #!/bin/bash if [ $# -eq 0 ] then read current_dir else current_dir=$1 fi function print_tree_representation () { for file in `ls -A $1` do ...
0
votes
0answers
153 views

how do I execute a command on multiple files located in different directories at once and directing the output to a new directory

I am trying to write a script that will execute a command on files in many directories while returning the output to another directory in an organised way. I did a dry run and got some good results ...
1
vote
2answers
626 views

Change Directory and execute command automatically then change directory back out

I'm attempting to write a script that will be run in a given directory with many single level sub directories. The script will cd into each of the sub directories, execute a command on the files in ...
0
votes
3answers
96 views

Grep in many directories, but only look in each dir's specific subdirectory, not all sub dirs

My case: dir1 subdir1 FooFile subdir2 dir2 subdir1 FooFile subdir2 So, if I cd dir1, I can easily do something like find . | xargs grep "Foo" in order to list the names of all ...
1
vote
1answer
240 views

How to find files and act on them (find + exec)

I have downloaded about 3200 websites to the depth 2. So now I have one master folder (abc) that contains many folders, containing files for each website. So my folder abc contains 3200 folders and ...
3
votes
3answers
144 views

How can strace monitor itself?

I have a hypothetical situation: Let us say we have two strace processes S1 & S2, which are simply monitoring each other. How can this be possible? Well, in the command-line options for strace, -...
4
votes
3answers
983 views

Copy only certain file types from a folder structure to another

I have a top folder with many sub-folders. It's named "a". There are many .png and .jpg files in there. I'd like to recursively copy "a" into a new folder "b", but only copy the .png and .jpg files. ...