/ Published in: Bash
This command line aims at moving directories from a target location to the present working directory (pwd), backing the pwd directories up as it encounters them.
The script works by:
1. Iterating through the contents of the target directory (using the unix ls command)
2. Checking whether the current object is a directory
3. Moving the pwd directory to a backup location using the unix mv command
4. Moving the target location's directory to the present working directory
5. Printing out the modified directory's name using the unix echo command
The script works by:
1. Iterating through the contents of the target directory (using the unix ls command)
2. Checking whether the current object is a directory
3. Moving the pwd directory to a backup location using the unix mv command
4. Moving the target location's directory to the present working directory
5. Printing out the modified directory's name using the unix echo command
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
for subdir in `ls targetDir`; do if [ -d "$subdir" ]; then mv "$subdir" "backup/$subdir"; mv "targetDir/$subdir" "$subdir"; echo "$subdir"; fi; done