Bash script deleting my files, and editing files in subdirectories question
So the purpose of this code is to rename files in a directory to a new name, number, and filetype. However anything that has already been renamed in my folder gets deleted. Like if I have:
This would take some work to keep them in subdirs. I see you already use the globstar ./** for recursion but didn't include the shopt -s globstar
This is bash4 feature, so let's write bash code and use all of it's nice features:
These 2 Users Gave Thanks to neutronscott For This Post:
Sorry, I'm really new to bash. Could someone explain how each part of these code segments work in 3 year old terms? And what the second one does? I like to understand what is going on. These were taken from Neutronscott's reply. Thanks
EDIT: Okay, I see what you did here. Though I'm not sure what the "$0" is for on the end of the printf statement.
EDIT: and I understand everything here other than '%s%03d.%s'
Last edited by TheGreatGizmo; 02-03-2014 at 11:10 PM..
continue just resumes at the next iteration of the enclosing for loop. In this particular code that means stop processing the current file and start processing the next file.
The current code is less than ideal as it will rename existing renamed files and skip files.
see below:
This slight update should be a little safer.
This User Gave Thanks to Chubler_XL For This Post:
Hello everyone,
I'm am a newbie to coding so I am reaching out in hopes that I can get some help from this forum.
I am trying to run the script below from a single directory, however the directory has many subfolders. In each of those subfolders is a file, uniquely named to that specific... (3 Replies)
Hii,
Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories.
Eg.
file1: test1.log
file2: test2.log
file3 test.zip
After running the script
file1: string_test1.log
file2: string_test2.log
file3:... (4 Replies)
Hi frnds,
My requirement is I have a zip file with name say eg: test_ABC_UH_ccde2a_awdeaea_20150422.zip
within that there are subdirectories on each directory we again have .zip files and in that we have files like mama20150422.gz and so on.
Iam in need of a bash script so that it unzips... (0 Replies)
Hello out there,
Our system has a pdf generator that creates pdf files. We dont need them pas 120 days.
So I have this command in my crontab. I currently set it to "0" for testing. But normally have it set to -mtime 120 to remove files out of the folders from PDF out to several other potential... (7 Replies)
Hello,
I have a CentOS server that contains a 'storage' directory. Within that directory, there could be any number of subfolders (all with unique names that match usernames).
Under each username folder, there are two additional folders: db and files
/STORAGE/user1/db/... (3 Replies)
Hi, I need a script that will:
1. Go through about 20 different folders, each containing about 20 1d files. The 1d files go something like this:
22.253 37.707 78.117 112.374 127.944 156.067 180.956 233.785 249.256 ... (1 Reply)
Hello dear Community,
I have a task to wrtie a script which will gzip not zipped files in a directory and itīs subdirectories. I succeeded in gzippung the directory but not the subdirectories:
#/bin/bash
#go to the directory where to zip
cd $1
#Zip unzipped files
for i in `ls | xargs... (2 Replies)
okay i'm going to try to say this uber-simple:
I use dropbox (file-sync service). in order for dropbox sync files, they must be its children eg. somewhere under /home/jzacsh/Dropbox].
I want to now use it to keep my development files in sync across my machines:
easy: just move my dev. files... (2 Replies)
Hi,
I have been doing files editing (using "vi") to change the period (e.g. 0902 to 0903) for 100 files each week as shown in the example below. I would like to have a script to solve this manual files editing. Please advice.
Example:
Change from:
... (2 Replies)
hi guys,
We have to implement new local (/etc/default/login) USER security policy on almost 50 stations.
so editing /etc/default/login and /etc/default/passwd will be way too long work.
Can we do the same using some script, I mean editing the above files and putting variables as RETRIES=3, ... (5 Replies)