Many years ago, I converted a portion of my files to an arbitrary format with a specific extension. i no longer desire to have them in this format and i would like begin the process of replacing them because conversion is not an appropriate solution. unfortunately, they are mixed in separate folders of the same root folder with files in my current format of a different extension. I feel it would make this process easier if I were to move every folder that contained a file with the undesired format to a separate root folder. The files are stored on a Linux server and shared via samba. How can I do this with a couple of commands or a script? I am open to other suggestions as well. I want to avoid time spent editing text files. Ultimately, I'd like a command that produced a list of full paths for folders, sorted by the number of levels would be a nice touch. A list of all of the files is clearly not what I'm looking for.
|
feedback
|
|
find . -type f | sed "s#^.#$(pwd)#" returns full paths for all files + a leading / when run at root you could pipe that to grep and match the extension followed by and endline drop that in a text file for manipulations you can now count the /'s in a line and split the filename off the end and mv $line to /adir/filename this could all be in a single bash script...i am not quit good enough at the bash scripting to make it a oneliner but this gets you most of the way there. you may want to watch out for file clobbering if you do this though. just how i would handle it from HERE DOWN IS NEW since evidently it's my job to write you a fully functional script since you can't read online faqs or respond when asked in what way it fails: find . -type f | sed "s#^.#$(pwd)#" | grep '.xml'> test.txt ./atest.sh > test2.txt ----atest.sh begin---- #!/bin/bash while read line do dirname $line done What else do you need scripts for?? because i really have nothing better to do the output from that script is only directory names that contained files ending in .xml or directories ending in .xml | |||||||||
feedback
|
|
The SOURCE should be the upper most directory you are searching. If the files are stored all throughout your file system then SOURCE should be the file system itself.
Rename them like this:
It would be a good idea to run this with the | |||||
feedback
|