gpt-3.5-turbo-1106· OpenAI
Arena Human Preference 55K
Write a bash script for copying and renaming files
- User
Write a bash script for copying and renaming files
- Assistant
Sure! Here's an example of a bash script that copies and renames files:
#!/bin/bash # Define the source and destination directories source_dir="/path/to/source/directory" destination_dir="/path/to/destination/directory" # Loop through the files in the source directory for file in $source_dir/*; do # Check if the file is a regular file if [ -f "$file" ]; then # Extract the file name and extension filename=$(basename "$file") extension="${filename##*.}" # Define the new file name new_filename="new_${filename}" # Copy the file to the destination directory with the new name cp "$file" "$destination_dir/$new_filename" # Print a message to the console echo "Copied $filename to $destination_dir/$new_filename" fi doneReplace "/path/to/source/directory" and "/path/to/destination/directory" with the actual paths of your source and destination directories. Save the script to a file, such as "copy_and_rename.sh", and make it executable with the command
chmod +x copy_and_rename.sh. Then you can run the script with./copy_and_rename.shin the terminal.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.