22

I have a huge directory structure of movie files. For analysis of that structure I want to copy the entire directory structure, i.e. folders and files however I don't want to copy all the movie files while I want to keep there file names. Ideally I get zero-byte files with the original movie file name.

I tried to and then rsync to my remote machine which didn't fetch the link files.

Any ideas how to do that w/o writing scripts?

4 Answers 4

21

You can use find:

find src/ -type d -exec mkdir -p dest/{} \; \
       -o -type f -exec touch dest/{} \;

Find directory (-d) under (src/) and create (mkdir -p) them under dest/ or (-o) find files (-f) and touch them under dest/.

This will result in:

dest/src/<file-structre>

You can user mv creatively to resolve this issue.


Other (partial) solution can be achieved with rsync:

rsync -a --filter="-! */" sorce_dir/ target_dir/

The trick here is the --filter=RULE option that excludes (-) everything that is not (!) a directory (*/)

17

On ubuntu you can try:

cp -r --attributes-only <source_dir> <target_dir>

It doesn't copy file data. From manpage of cp

--attributes-only
          don't copy the file data, just the attributes

Note: I'm not sure this option available for other distributions, if anybody can confirm please update the answer.

2
  • Thanks for the answer Rohan, unfortunately my Debian on Netgear's ReadyNAS won't know this option :( Commented Aug 14, 2012 at 6:24
  • 1
    works fine under Debian GNU/Linux 10 (buster)
    – jkeys
    Commented Aug 2, 2021 at 17:52
0

I needed an alternative to this to sync only the file structure:

rsync --recursive --times --delete --omit-dir-times --itemize-changes "$src_path/" "$dst_path"

This is how I realized it:

# sync source to destination
while IFS= read -r -d '' src_file; do
  dst_file="$dst_path${src_file/$src_path/}"
  # new files
  if [[ ! -e "$dst_file" ]]; then
    if [[ -d "$src_file" ]]; then
      mkdir -p "$dst_file"
    elif [[ -f $src_file ]]; then
      touch -r "$src_file" "$dst_file"
    else
      echo "Error: $src_file is not a dir or file"
    fi
    echo -n "+ "
    ls -ld "$src_file"
  # modification time changed (files only)
  elif [[ -f $dst_file ]] && [[ $(date -r "$src_file") != $(date -r "$dst_file") ]]; then
    touch -r "$src_file" "$dst_file"
    echo -n "+ "
    ls -ld "$src_file"
  fi
done < <(find "$src_path" -print0)

# delete files in destination if they disappeared in source
while IFS= read -r -d '' dst_file; do
  src_file="$src_path${dst_file/$dst_path/}"
  # file disappeard on source
  if [[ ! -e "$src_file" ]]; then
    delinfo=$(ls -ld "$dst_file")
    if [[ -d "$dst_file" ]] && rmdir "$dst_file" 2>/dev/null; then
      echo -n "- $delinfo"
    elif [[ -f $dst_file ]] && rm "$dst_file"; then
      echo -n "- $delinfo"
    fi
  fi
done < <(find "$dst_path" -print0)

As you can see I use echo and ls to display changes.

-3

ls > listOfMovie.txt; You will have the list of your films in a .txt file .For multiple directories see the man page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.