Finding file by name recursively, deleting it and creating a symlink

temuri

Given:

Folder structure as (file.txt are plain text files in each directory, not symlinks):

/basedir/A/file.txt
/basedir/B/file.txt
/basedir/C/file.txt

The same file.txt that sits in /mydir:

/mydir/file.txt

I need a command that would run from /basedir that:

  • Finds recursively all /file.txt (in .A/, ./B and ./C)
  • Removes found file.txt files
  • Creates a symlink to /mydir/file.txt

Can that be done in a single bash command?

Thank you!

Stephen Kitt

This will do it:

find /basedir -type f -name file.txt -exec ln -sf /mydir/file.txt '{}' \;

This finds all files named file.txt under /basedir, and runs ln on each to replace it (-f) with a symbolic link (-s) to /mydir/file.txt.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Finding largest file recursively

From Dev

Creating a symlink with a colon in the name on cygwin bash

From Dev

finding folder name recursively and assigning it to a variable

From Dev

Finding a Column by Name and Deleting Columns to the right

From Dev

Creating symlink for a file on Windows 7 gives error

From Dev

Finding the base file name

From Dev

Recursively "find" file names containing string and symlink files in another directory

From Dev

Finding largest file size recursively from a directory

From Dev

Finding full path of a symlink'ed file (more quickly)?

From Dev

Deleting part of a file's name

From Dev

Creating a udev rule that uses information from a parent in it's SYMLINK name

From Dev

recursively add directory name to file name

From Dev

Finding a directory or file without name?

From Dev

Finding a subdirectory that matches a file name

From Dev

grep not finding name in text file

From Dev

Creating a file but with an specific name

From Dev

Append file name to beginning of [Markdown] file recursively

From Dev

Thread safe creating and deleting file in Java

From Dev

creating, editing and deleting a pdf-file with java

From Dev

How to replace recursively part of file name in bash

From Dev

Recursively list files containing an underscore in the file name

From Dev

Finding a string in a file and deleting all the text next to it in bash

From Dev

Is existing file removed when a symlink is created with the same name?

From Dev

Creating a linux symlink on Windows?

From Dev

Creating a Symlink in an NTFS share

From Dev

Creating Broken Symlink

From Dev

Creating symlink for Postgres

From Dev

Deleting a file and delete its name from a list

From Dev

Deleting specific folders recursively

Related Related

  1. 1

    Finding largest file recursively

  2. 2

    Creating a symlink with a colon in the name on cygwin bash

  3. 3

    finding folder name recursively and assigning it to a variable

  4. 4

    Finding a Column by Name and Deleting Columns to the right

  5. 5

    Creating symlink for a file on Windows 7 gives error

  6. 6

    Finding the base file name

  7. 7

    Recursively "find" file names containing string and symlink files in another directory

  8. 8

    Finding largest file size recursively from a directory

  9. 9

    Finding full path of a symlink'ed file (more quickly)?

  10. 10

    Deleting part of a file's name

  11. 11

    Creating a udev rule that uses information from a parent in it's SYMLINK name

  12. 12

    recursively add directory name to file name

  13. 13

    Finding a directory or file without name?

  14. 14

    Finding a subdirectory that matches a file name

  15. 15

    grep not finding name in text file

  16. 16

    Creating a file but with an specific name

  17. 17

    Append file name to beginning of [Markdown] file recursively

  18. 18

    Thread safe creating and deleting file in Java

  19. 19

    creating, editing and deleting a pdf-file with java

  20. 20

    How to replace recursively part of file name in bash

  21. 21

    Recursively list files containing an underscore in the file name

  22. 22

    Finding a string in a file and deleting all the text next to it in bash

  23. 23

    Is existing file removed when a symlink is created with the same name?

  24. 24

    Creating a linux symlink on Windows?

  25. 25

    Creating a Symlink in an NTFS share

  26. 26

    Creating Broken Symlink

  27. 27

    Creating symlink for Postgres

  28. 28

    Deleting a file and delete its name from a list

  29. 29

    Deleting specific folders recursively

HotTag

Archive