PHP script to create index file - joomla

I need a php script that will create or copy from a path a blank index.html file for each folder that doesn't have one.
If some one has one please share.
Thanks
H

Make your blank index.html - file and place it below your www- folder. Then, standing in the same place below your www- folder, try something like this:
find www -type d -exec cp -n index.html {}/index.html \;
...where www is your www-folder. This should copy the index.html - file to all folders below the www-folder, including the www-folder itself. The copy -n flag ensures existing index.html - files are not overwritten.
To make this into a php-script, you could just wrap it in a exec, like:
<?php
$path = 'path/to/www'; // www-folder
$index = 'path/to/index.html';
exec('find '.$path.' -type d -exec cp -n '.$index.' {}/index.html \;');
Place the code above in a php-file.
This solution is not platform independant, but will work on most flavours of *nix and mac.

Related

How can I delete all files in all subdirectories with a certain name?

I have been trying to use the command line to delete all files in all subdirectories with the name s_1_1102_c.jpg.
This question is similar to what I need How to remove folders with a certain name but it is removing directories and I only want to delete the files with the name s_1_1102_c.jpg.
I will need to remove this file from 260 subdirectories under the L001 directory. My directory structure is like this:
L001
C5.1
s_1_1101_a.jpg
s_1_1101_c.jpg
s_1_1101_g.jpg
s_1_1101_t.jpg
s_1_1102_a.jpg
s_1_1102_c.jpg
s_1_1102_g.jpg
s_1_1102_t.jpg
s_1_1103_a.jpg
s_1_1103_c.jpg
s_1_1103_g.jpg
s_1_1103_t.jpg
C6.1
s_1_1101_a.jpg
s_1_1101_c.jpg
s_1_1101_g.jpg
s_1_1101_t.jpg
s_1_1102_a.jpg
s_1_1102_c.jpg
s_1_1102_g.jpg
s_1_1102_t.jpg
s_1_1103_a.jpg
s_1_1103_c.jpg
s_1_1103_g.jpg
s_1_1103_t.jpg
Ultimately I need to remove several files from all subdirectories (s_1_1101_g.jpg, s_1_1101_t.jpg, s_1_1102_a.jpg, s_1_1102_c.jpg, s_1_1102_g.jpg, s_1_1102_t.jpg). So maybe there is a way to provide a list of the file names I need to delete.
How can I delete these files?
find . -name "s_1_1102_c.jpg" -exec rm -f {} \;
Note: This will find and delete the file in any subdirectory of the current one. So you could execute it in L001 or wherever else you want to do this.
for i in s_1_1101_g.jpg s_1_1101_t.jpg s_1_1102_a.jpg s_1_1102_c.jpg s_1_1102_g.jpg s_1_1102_t.jpg; do
echo rm L001/*/"$i";
done
If output looks fine, remove echo.
The final method I used to delete my files was given by #Peter - Reinstate Monica
for f in s_1_1101_t.jpg s_1_1102_a.jpg s_1_1102_c.jpg s_1_1102_g.jpg s_1_1102_t.jpg s_1_1103_a.jpg s_1_1103_c.jpg s_1_1103_g.jpg s_1_1103_t.jpg s_1_1104_a.jpg s_1_1104_c.jpg s_1_1104_g.jpg s_1_1104_t.jpg s_1_2101_g.jpg s_1_2101_t.jpg s_1_2102_a.jpg s_1_2102_c.jpg s_1_2102_g.jpg s_1_2102_t.jpg s_1_2103_a.jpg s_1_2103_c.jpg s_1_2103_g.jpg s_1_2103_t.jpg s_1_2104_g.jpg s_1_2104_t.jpg; do find /hpc/home/L001 -name $f -delete; done
I was concerned that my file list would be too long but it worked in this situation.

How to move and rename each file in folder to top folder? [linux shell] [bash]

I'm trying to create a simple script in linux shell that in a folderX goes through each of its folders, renames the files that finds there, and moves them to the root (folderX) folder....
I'm guessing that the logic is somewhat like this:
-0> //in folderX
-0>for each folder == $folderY //just the last part, what comes after ~/folderX/[this]
-1> cd ./$folderY
-1> for each fileInY == $fileInY //just the last part, what comes after ~/folderX/folderY/[this.something]
-2> rename fileInY = "$folderY - $fileInY"
-1> move * to folderX
-1> cd..
(but suggestions and different methods of approach are appreciated)
Thanks in advance!
-Gabix
folder="folderX"
find "$folder" -type f -exec cp '{}' '{}'.bak \; -exec mv '{}'.bak "$folder" \;
Set the root folder/directory in a variable folder and then use this to run find and then exec. Find files in the directory structure and first copy the name of the file to the name of the file followed by ".bak" and then move the file from the directory to the root folder/directory

script to find /rsync - a specific files between 2 dirs with identical internal folder structure

I have two dirs which contain all the files for a mobile phone system/rom. I'll call them /rom1 and /rom2
Both rom1 & rom2 have identical directory structure within.
The full file path to each is similar to
User/me/development/rom1/system
User/me/development /rom2/system
I want to copy / rsync -av all the folders and files with camera. * from rom1/system/ to its equivalent folder in rom2/system/
ie: generate a scrip that does... rsync - av User/me/development/rom1/system/app/camera.apk User/me/development/rom2/system/app/
In case it's useful I have already generated a list of all the folders and files including their file path (starting at /system) I want copied over. It looks like :
system/app/camera.apk system/bin/lib/camera.so system/vendor/camera/ system/very-long-list /etc etc...
I know how to use Individual Unix tools but I'm having trouble putting it all together to do what I want in a bash script.
this is a non functional example that will give you an idea of what Im trying to do.
DIR1=User/me/development/rom1/
OLDPATH=$(find . -name '*camera*.*' -exec $pwd { } \;) | NEWPATH=$(sed -s /rom1/rom2/ $OLDPATH) | for SELF in { } ; do
rsync --dry-run -Rav $DIR1$SELF $NEWPATH

Split a folder which has 100s of subfolders with each having few files into one more level of subfolder using shell

I have a following data dir:
root/A/1
root/A/2
root/B/1
root/B/2
root/B/3
root/C/1
root/C/2
And I want to convert it into following file structure:
root2/I/A/1
root2/I/A/2
root2/I/B/1
root2/I/B/2
root2/I/B/3
root2/II/C/1
root2/II/C/2
Purpose of doing it is I want to run some script which takes home folder (root here) and runs on it. And I want to run it in parallel on many folders(I, II) to speed up the process.
Simple assumption about file and folder name is that all are alphanumeric, even no period or underscore.
Edit: I tried following:
for i in `seq 1 30`; do mkdir -p "root2/folder$i"; find root -type f | head -n 4000 | xargs -i cp "{}" "root2/folder$i"; done
Problem is that it creates something like following, which is not what i wanted.
root2/I/1
root2/I/2
root2/I/1
root2/I/2
root2/I/3
root2/II/1
root2/II/2
You may wish to use a lesser known command called dirsplit, the usual application of which is to split a directory into multiple directories for burning purposes.
Use it like below :
dirsplit -m -s 300M /root/ -p /backup/folder1
Options implies below stuff :
-m|--move Move files to target dirs
-e 2 special exploration mode, 2 means files in directory are put together
-p prefix to be attached to each directory created, in you case I, II etc
-s Maximum size allowed for each new folder created.
For more information see :
dirsplit -H

Unable to create the md5sum file I need to create. Manually doing it would be far too labour-intensive

I need to create/recreate an md5sum file for all files in a directory and all files in all sub-directories of that directory.
I am using a rockettheme template that requires a valid md5sum document and I have made changes to the files, so the originally included md5sum file is no longer valid.
There are over 300 files that need to be checksummed, and the md5hash added to a single file.
The basic structure of the file is as follows:
1555599f85c7cd6b3d8f1047db42200b admin/forms/fields/imagepicker.php
8a3edb0428f11a404535d9134c90063f admin/forms/fields/index.html
8a3edb0428f11a404535d9134c90063f admin/forms/index.html
8a3edb0428f11a404535d9134c90063f admin/index.html
8a3edb0428f11a404535d9134c90063f admin/presets/index.html
b6609f823ffa5cb52fc2f8a49618757f admin/presets/preset1.png
7d84b8d140e68c0eaf0b3ee6d7b676c8 admin/presets/preset2.png
0de9472357279d64771a9af4f8657c2a admin/presets/preset3.png
5bda28157fe18bffe11cad1e4c8a78fa admin/presets/preset4.png
2ff2c5c22e531df390d2a4adb1700678 admin/presets/preset5.png
4b3561659633476f1fd0b88034ae1815 admin/presets/preset6.png
8a3edb0428f11a404535d9134c90063f admin/tips/index.html
2afd5df9f103032d5055019dbd72da38 admin/tips/overview.xml
79f1beb0ce5170a8120ba65369503bdc component.php
caf4a31db542ca8ee63501b364821d9d css/grid-responsive.css
8a3edb0428f11a404535d9134c90063f css/index.html
8697baa2e31e784c8612e2c56a1cd472 css/master-gecko.css
0857bc517aa15592eb796553fd57668b css/master-ie10.css
a4625ce5b8e23790eacb7704742bf735 css/master-ie8.css
This is just a snippet, but the logic is there.
hash path/to/file/relative/to/MD5SUM_file
Can anyone help me write a shell script (bash shell) that I can add to my path that will execute and generate a file called "MD5SUM_new"? I want the output file name to be "MD5SUM_new" so I can review the content before issuing a mv MD5SUM_new MD5SUM
FYI, the MD5SUM_new file needs to be saved in the root level of the template.
Thanks
This is quite easy, really. To hash all files under the current directory:
find . -type f | xargs md5sum > md5sums
Then, you can make sure it's correct:
md5sum -c md5sums

Resources