Operating on a directory and its subdirectories, recursively.

learn more… | top users | synonyms

0
votes
2answers
41 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 ...
3
votes
5answers
355 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
35 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/...
1
vote
0answers
24 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
477 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 ...
16
votes
9answers
5k 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
10 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
52 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
43 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
37 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
34 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
35 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
34 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
36 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
68 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
79 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
68 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 ...
1
vote
1answer
134 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 ...
2
votes
2answers
57 views

How can strace monitor itself?

I have a Hypothetical Situation. (1) 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 ...
4
votes
3answers
416 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. ...
1
vote
3answers
43 views

Run a command over directories with name recursively

I have the following directory structure in AIX. codeRepo/REPO1/AREA1/objects codeRepo/REPO1/AREA2/SUBAREA1/objects codeRepo/REPO1/AREA2/SUBAREA2/objects From codeRepo I want to run chown myUser * ...
3
votes
3answers
177 views

Recursive Function not Working

I know that this is a ridiculous idea, but I'm trying to get a script to work that branches through every directory on the file system. The file's name is "Everywhere.sh". Here's the code: #!/bin/...
-3
votes
1answer
56 views

Why wget is not willing to download recursively?

The command $ wget -r http://www.comp.brad.ac.uk/research/GIP/tutorials/index.html only downloads index.html and robots.txt for me, even though there are links in it to further pages in the same ...
1
vote
1answer
44 views

wget for recursive download of dxf files

There is a web server with many dxf type files which can only be downloaded one at a time. I thought it should be a good idea to use wget to download all of those files at the same time. Unfortunately,...
6
votes
3answers
286 views

Flatten the output of a recursive directory listing

Is there a way to list out all the files within a directory tree in a single list, sorted by modification time on Linux? ls -Rlt lists out files recursively, but they are grouped under different ...
3
votes
2answers
64 views

Find files recursively, but choose largest from among those with duplicate names

Given a nested directory structure containing various files, I would like to find all the files within it, but where there are multiple files with the same name, I'd like to return just the largest ...
1
vote
2answers
50 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
1answer
203 views

How to find all files containing a specific string recursively on a BusyBox 1.4.2?

How to find all files containing a specific string within directory and all subdirectories on a BusyBox v1.4.2? I need to find string "AA:CC:DD:00:EE:55" or "AACCDD00EE55" BusyBox v1.4.2 (2012-06-01 ...
3
votes
1answer
69 views

Recursive find/replace, taking directory depth into consideration

I've had good luck doing basic find/replace: find . -name "*.php" -exec sed -i -e "s/<?php include 'http:\/\/www/<?php include '..\//g" \{\} \; I am wondering if there is a way to achieve a ...
2
votes
1answer
202 views

Recursively execute imagemagick composite command in directory tree

I have a large directory tree with many sub-folders and lots of images within each one. I found a script that applies watermark to all images within a directory, in-place, overwriting the original ...
0
votes
1answer
375 views

Copy all files matching criteria on find command with -exec

Below are my attempts at copying all files except .out and .class files into a subdirectory titled homework21/. Note homework21 is a subdirectory of the folder in which I am working in. me@ice4:~/...
1
vote
1answer
300 views

Recovering from a chown -R / [duplicate]

I've made today the greatest error on my server using root user: chown -R 33:33 / instead of chown -R 33:33 . within some webroot folder. Well, this brought ssh down. I made it this far to get it ...
31
votes
6answers
1k views

How to copy a folder recursively in an idempotent way using cp?

When I use cp -R inputFolder outputFolder the result is context-dependent: if outputFolder does not exist, it will be created, and the cloned folder path will be outputFolder. if outputFolder ...
1
vote
2answers
124 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 $...
0
votes
2answers
100 views

Recursive rm doesn't work for me

Suppose, we have the following files in a directory: test.txt test.txt~ /subdir test1.txt test1.txt~ When I run rm -r ./*.*~ inside top dir only test.txt~ is removed. Why doesn't it perform ...
1
vote
2answers
168 views

copy recursively skipping directories with specific name

I have a directory with ~100 Gb. I need to copy this directory to other place skipping specific folders (there is a lot of them). The following is a wrong code to demonstrate my needs. $ cp -r ~/...
3
votes
3answers
581 views

Bulk remove a large directory on a ZFS without traversing it recursively

I want to remove a directory that has large amounts of data on it. This is my backup array, which is a ZFS filesystem, linear span, single pool. The data is in this pool called san, mounted on /san ...
3
votes
2answers
287 views

remove whitespace from all items in a directory and sub directory

I have a directory which contains files and sub directories, some of which have whitespace in their names. Further more each of these sub directories contains files with whitespace in their names. Is ...
3
votes
2answers
232 views

Recursive copy files with rename

If I have input folder files_input that has subfilders like 01-2015, 02-2015, 03-2015 etc and all these subfolders have other subfolders. Each subfolder has only one file called index.html. How can ...
2
votes
3answers
4k views

How to I copy the directory and subfolders but ignore certain files in the subfolder?

I believe the question is best asked with an example. /home test1.txt test2.txt /home/my-folder test3.txt test4.txt test1.txt, test2.txt and my-folder folder are inside /home. ...
3
votes
2answers
327 views

File deletion under special conditions, recursively if possible

I am looking for a unix command sequence, which is able to perform a quite complex, conditional deleting action. All files with the extensions "[NAME].cut" and "[NAME].cut.bak" shall be deleted, IF ...
5
votes
2answers
657 views

How to recursively check if a specfic user has read access to a folder and its contents?

I need to pass a user and a directory to a script and have it spit out a list of what folders/files in that directory that the user has read access to. MS has a tool called AccessChk for Windows that ...
1
vote
0answers
155 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 ...
14
votes
3answers
3k views

How to copy a directory recursively using hardlinks for each file

I want to create a "copy" of a directory tree where each file is a hardlink to the original file Example: I have a directory structure: dirA/ dirA/file1 dirA/x/ dirA/x/file2 dirA/y/ dirA/y/file3 ...
2
votes
2answers
200 views

Efficient search of unique owners of files and directories

I would like to view the unique owners of all the files and directories underneath a certain directory. I have tried: ls -ltR <dir-path> | grep -P '^[d|\-]' | awk '{print $3}' | sort | uniq ...
2
votes
2answers
194 views

List files recursively in Linux CLI with path relative to the current directory, max 250 char

I'm trying to list all the files with names no longer than 250 characters (including the directory it is part of, from the relative path my command is inside). I've seen a similar thread , but that ...
0
votes
1answer
84 views

How do you combine -r and -c for gunzip?

I am trying to recursively gunzip files (-r) but don't have permission in their original location to store them. I know to change the location for a single file you do gunzip {file} -c > {new file ...
0
votes
1answer
286 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.
6
votes
4answers
593 views

Converting `for file in` to `find` so that my script can apply recursively

I've been working on my first bash script for some time now (I just started UNIX this week). I have this idea of running a bash script to check some conditions and using ffmpeg to convert all the ...
6
votes
7answers
2k views

How to copy a folder structure and make symbolic links to files?

I have a folder SOURCE that contains several sub-level folders, each with its own files. I want to copy this folder in a new folder COPY where I need to copy the directory structure but keep the ...