there was a post previously about this from around 2010
but i was unable to get the suggested scripts there to work.
the following code works for me when it's saved inside the
directory of files whose names i want to shorten, but i would
like to be able to store it in a file with a list of
directories and have it enter into each directory, shorten the
file names in that directory, and then move to the next
directory.
basically enter directory1 and perform the code below,
move to directory2 and do it again, then directory3, etc. etc.
thanks in advance for any help!
Last edited by methyl; 08-24-2012 at 09:08 PM..
Reason: please use code tags for code and data.
hi! thanks for the fast response.
the first example you gave wouldn't work because i need to shorten the file names in about 1500 different directories. hence i would like a program that can start at the first directory perform the code. move to the next directory, perform the code. move to the next, perform the code, and so on until it gets to the end of the list of directories.
in the second example you gave i'm not sure what "list_of_directories.txt" means or where i would find that. i'm very new to this whole bash thing so if you don't mind giving explanations that would be great!
as far as the code that i gave before (copied from an earlier thread), all it does is takes all of the files in a directory in which it is saved and shortens them to 30 characters and adds a 1 or 2 if some of the files have the same name after they've been shortened. so my end goal is to apply that code to files in many different directories so i don't have to go into each of the 1500 directories i have and run the code. thanks again for any help! hopefully that made sense?
how do you know the 1500 directories. That is the "list_of_dir"
I agree with methyl, your code looks like someone who can program but does not know shell. FORTRAN comes to mind.
Assume the directories you want to mess with are under two main directories. Assume they are /data1 /old_data1. you have many and we will assume those directories lie in a series of subdirectories under the two main ones. I will show you to expand them.
file name matching (expansion) looks like this to find sub directories /directory/*.
This gets everything, all files, including directories
This gets JUST directories, ~/ is shorthand in bash for your login directory.
Now you have a list of directories. Assuming you think your code works correctly
I added the code in red. Change the find command to include your directories.
If you already have a list, use that instead.
Just like in other languages, indentation helps readability....
Also modify whatever script created those directory atrocities to start with. Why? UNIX filesystems have limits to the length of filenames and they have length limits to the entire path: [/directorynames..../.../../../../,../loooongfilename]. If you can show us the output of
Also a caveat - lots of directories using lots of files use LOTS and LOTS of inodes. Each entry in a directory plus the directory name use an inode. You hit the limit you can't do much with the disk.... You run out of them, you lose. You have to be proactive. Really large directory files are a bad sign.
will show you how large a directory is. When you have directories in the MB range it is time to think about it long and hard.
Last edited by jim mcnamara; 08-24-2012 at 11:34 PM..
This User Gave Thanks to jim mcnamara For This Post:
I am trying to merge or combine all $1 values in validation.txt from multiple directories into one new file and output it here tab-delimited:/home/cmccabe/Desktop/20x/total/total.txt. Each $2 value and the header would then be a new field in total.txt. I am not sure how to go about this as cat is... (2 Replies)
Hi,
Can someone please help me with a Command to Search a FILE for a STRING in multiple DIRECTORIES.
I am searching for the VIP in HTTPD.CONF in multiple httpd instances.
I am using
find ./ -name "httpd.conf" | xargs grep 10.22.0.141 cut -d: -f3- | cut -d ' ' -f4 | sort | uniq -c
... (1 Reply)
Hi,
Need help ...I want to create multiple directories in different /file systems using for loop..eg.../ORCL_data01/oradata/orcl/ctl.
../ORCL_data01/oradata/orcl/data.
../ORCL_data01/oradata/orcl/redo.
Script :-
=========
for dir in `ls -d... (8 Replies)
Hello
I'm making script for Dallas temperature sensors (DS1820).
When a sensor is connected, it shows up as a directory in /sys/bus/w1/devices
in format 10-xxxxxxx. Inside the directory is a file called w1_slave which holds the temperature in format t=xxxxx.
Each sensor has unique... (2 Replies)
Hi All Genious,
I want to copy a file name XYZ .In a directory /HOME/dir/IXOS1/dir1
which contain multiple directories named not in pattern want to copy the XYZ in all of the directories available on path /HOME/dir/IXOS1/dir1 .
Thanks in advance . (2 Replies)
Hi,
Very unfamiliar with unix/linux stuff. Our admin is on vacation so, need help very quickly.
I have directories (eg 40001, 40002, etc) that each have one subdirectory (01).
Each subdir 01 has multiple subdirs (001, 002, 003, etc). They are same in each dir.
I need to keep the top and... (7 Replies)
Hi ,
I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory.
how to write this in a simple script, I have made my code complex
if ; then
taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
I have a large list of filenames from an Excel sheet, which I then translate into a simple text file. I'd like to use this list, which contains various file extensions , to archive these files and then remove them recursively through multiple directories and subdirectories. So far, it looks like... (5 Replies)
Please help - I need to copy a single file to multiple directories.
Dir structure:
Parent_Directoy
Filename1
Child_Directory1
Child_Directory2
Child_Directory3
Child_Directory4
....
So I need to copy Filename1 to all of the... (2 Replies)