im trying to write a script that will put files with different extensions into their specified directories
In the directory are files of various types, i want to arrange the files on individual directories under their type. There are three distinct types of files: 1) Text documents - files with extensions. Doc,. Txt,. Pdf, ... 2) multimedia files - with the extensions. Mpg,. Avi,. Mp3 ... 3) graphics files - with the extensions. Jpg,. Gif,. Png ... 4) All other files Files types 1-3 to move into individual directories and files of other types have to move in directories with names corresponding to the extension (you can bring them to uppercase - BAK, CPP ,...). i want the script to run with the following parameters: 1)-m path - if specified, the multimedia files will be moved to the directory PATH 2)-d PATH - specifies the path where you have to move your documents 3)-l indicates that when the file names should lead to lower case 4)-x indicates that they move to lower case file extension any ideas ??i am a newbie and im trying to learn bash scripting so i thought of this question
Since you are a self-professed "newbie", I will add commentary to the script.
Build the list of extensions for each filetype group: "d" for document, "i" for image, "m" for multimedia, and "o" for other. You can override the default list by setting the FILEREXTLIST_X environmental variable to a colon separated list of extensions or you can add to the default list by setting FILEREXT_X environmental variable to a colon separated list of extensions.
For an error message, see below
Sets the default directories for each filetype group.
The extmap array will be used to map extensions to directories -- it will be populated below.
On of your requirements is:
Quote:
... other types have to move in directories with names corresponding to the extension (you can bring them to uppercase - BAK, CPP ,...).
I have to admit that having this be the default option is a recipe for sadness, imho you should not move files only if requested. So the -a maps files with 'other' extension to a directory with the extension in all lower case, -A maps to upper case.
The -X ext option allows you to add to the extension list for each filetype group
The -x dir option allows you to set the directory for each filetype group
Use the -x=ext=directory to explicitly map an extension to a specified directory. Multiple colon separated extensions may be specified.
I leave filling out the help function up to you
Map all the extensions of each filetype group to their directories. The spliting apart the list of extensions was done by appending a colon to IDS, which lets the shell do the hard work.
OK, how I decided to move the files may be considered a bit cheesy. The script echos out the appropriate mv commands that are subsequently sent to sh to process. This lets me sets take advantage of the -n option to print out what would be done, but not actually move files around.
I am trying to use bash to loop through a directory /path/to/data using a prefix match from /path/to/file. That match is obtained and works using the code below (in green)... what I can not seem to do is populate or update the corresponding prefix_file.txt in /path/to/data with the values in each... (3 Replies)
In the bash below I am trying to create sub-directories inside a directory from files with specific .bam extensions. There may be more then one $RDIR ing the directory and the .bam file(s) are trimmed (removing the extension and IonCode_0000_) and the result is the folder name that is saved in... (2 Replies)
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,
I have a command in my bash script, searchDirectoryName.sh:
DIR_NAME=$(find . -type d)
echo "${DIR_NAME}"
.
./Dir1
./Dir1/1.0.2.1
./Dir2
./Dir2/1.1
./Dir3
./Dir3/2.2.1
How can I select only following directory names with second subdirectoies and without first ./ in the... (3 Replies)
Hi,
I do have question for un tar a file. I have several 'tar'ed files. For example: SRS.tar.bz2. I was trying to untar them in a linux server using the command:
tar xvjf SRS.tar.bz2
It worked perfectly. but when I open this file in my mac computer all the files are extracted into a... (7 Replies)
Hi All ,
I have a directory called "/usr/local/apache/docs/" inside this docs i have below directories ,
bash-2.05# pwd
/usr/local/apache/docs/
bash-2.05#ls -l | less
2 drw-r-xr-x 3 root root 512 Aug 8 2010 Form1
2 drw-r-xr-x 3 root other 512 Mar 8 ... (4 Replies)
Hi ALL
I have small script that find 777 dir now i want to count these directories,Keep in mind there are many directories.
This IS my code below.
#!/bin/bash
check=/var/www/html
find $check -type d -perm 777 | while read DIR
do
... (2 Replies)
Hi everyone.
I need to write a script which will download files/folders (a huge collection) to the local file server (centOS 4.4 Server),
and check regularly (every 6 hours or so if any new files are present, or if the old ones were modified to update contents).
Any insights on how to tackle... (2 Replies)
Can anyone help me on this. I have a file that looks like this:
color red green blue
color pink yellow
number one two
gender male
gender female
The output would look like this:
color red green blue pink yellow
number one two
gender male female
I have over 5000 rows and i dont want... (5 Replies)
Dear UNIX experts:
Hi, I have a text file which the contents are arranged vertically down, line by line.
How do use a loop (I think) to make it arrange in vertical arrangement with a tab delimitated and write to a new file?
Eg: of source file
Hello World
Good-day
Thanks
Welcome
The... (8 Replies)