Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you want to move files that contain a certain pattern within the file contents, you can use grep to search for the pattern and then move the matching files. Here's an example:

Suppose you want to move all files containing the pattern example from the current directory to the target_directory:

for file in *; do if grep -q "example" "$file"; then mv "$file" target_directory/ fi done

If you want to move files that contain a certain pattern within the file contents, you can use grep to search for the pattern and then move the matching files. Here's an example:

Suppose you want to move all files containing the pattern example from the current directory to the target_directory:

for file in *; do
  if grep -q "example" "$file"; then
    mv "$file" target_directory/
  fi
done