Questions tagged [recursive]

Operating on a directory and its subdirectories, recursively.

Use this tag when an important part of your question is to operate on a directory, its subdirectories, its sub-sub-directories, etc., and some or all the files in these directories.

346 questions
254
votes
3 answers

Difference between cp -r and cp -a

I'm looking for the difference between cp -r and cp -a. What does "recursive" mean in terms of copying files from a folder?
Randy
  • 2,649
  • 2
  • 14
  • 4
245
votes
14 answers

How to recursively find the amount stored in directory?

I know you are able to see the byte size of a file when you do a long listing with ll or ls -l. But I want to know how much storage is in a directory including the files within that directory and the subdirectories within there, etc. I don't want…
Rob Avery IV
  • 3,075
  • 3
  • 17
  • 14
190
votes
6 answers

How do I grep recursively through .gz files?

I am using a script to regularly download my gmail messages that compresses the raw .eml into .gz files. The script creates a folder for each day, and then compresses every message into its own file. I would like a way to search through this archive…
Kendor
  • 2,001
  • 2
  • 12
  • 5
146
votes
3 answers

Recursive glob?

I'd like to write something like this: $ ls **.py in order to get all .py filenames, recursively walking a directory hierarchy. Even if there are .py files to find, the shell (bash) gives this output: ls: cannot access **.py: No such file or…
Paolo
  • 16,955
  • 11
  • 31
  • 40
117
votes
7 answers

Flattening a nested directory

This is probably very simple, but I can't figure it out. I have a directory structure like this (dir2 is inside dir1): /dir1 /dir2 | --- file1 | --- file2 What is the best way to 'flatten' this directory structure…
turtle
  • 2,607
  • 5
  • 19
  • 16
96
votes
14 answers

How to remove all the files in a directory?

I am trying to remove all files and subdirectories in a directory. I used rm -r to remove all files, but I want to remove all files and subdirectories, excluding the top directory itself. For example, I have a top directory like images. It contains…
whiterose
  • 1,069
  • 1
  • 7
  • 4
95
votes
7 answers

Move all files with a certain extension from multiple subdirectories into one directory

I have a bunch of .zip files in several directories: Fol1/Fol2 Fol3 Fol4/Fol5 How would I do move them all to a common base folder?
InquilineKea
  • 6,152
  • 12
  • 43
  • 42
93
votes
6 answers

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 Here is the expected result, a "copy" of the…
Gudmundur Orn
  • 1,981
  • 1
  • 11
  • 9
92
votes
5 answers

How do I recursively delete directories with wildcard?

I am working through SSH on a WD My Book World Edition. Basically I would like to start at a particular directory level, and recursively remove all sub-directories matching .Apple*. How would I go about that? I tried rm -rf .Apple* and rm -fR…
codedog
  • 1,023
  • 1
  • 7
  • 5
91
votes
12 answers

How do I count all the files recursively through directories

I want to see how many files are in subdirectories to find out where all the inode usage is on the system. Kind of like I would do this for space usage du -sh /* which will give me the space used in the directories off of root, but in this case I…
xenoterracide
  • 57,918
  • 74
  • 184
  • 250
89
votes
5 answers

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 file. One problem is that suddenly all my text…
gaazkam
  • 1,400
  • 3
  • 10
  • 17
82
votes
11 answers

Using sftp to Transfer a Directory?

When I try to use sftp to transfer a directory containing files, I get an error message: skipping non-regular file directory_name The directory contains a couple of files and two subdirectories. What am I doing wrong?
haziz
  • 2,231
  • 4
  • 26
  • 37
70
votes
2 answers

How can I search a wild card name in all subfolders?

How can I search a wild card name in all subfolders? What would be the equivalent of DOS command: dir *pattern* /s in *nix?
Eduard Florinescu
  • 11,153
  • 18
  • 57
  • 67
70
votes
6 answers

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 exists, then the clone created will be…
jakub.g
  • 3,153
  • 5
  • 20
  • 17
67
votes
3 answers

Why doesn't mv utility need -R (recursive) option but cp does?

I always get messed up when need to use cp or mv: "do I need -R option when working with dir?" In GNU coreutils cp does need -R and mv doesn't. I just can not find any reason why cp needs -R option for copying dirs and mv doesn't. I think that…
wobmene
  • 963
  • 1
  • 7
  • 9
1
2 3
23 24