Sponsored Content
Top Forums Shell Programming and Scripting Bash and Awk for creating directories and moving files Post 302218249 by Kiint on Thursday 24th of July 2008 07:52:44 PM
Old 07-24-2008
Bash and Awk for creating directories and moving files

I have a security system that FTPs the camera files to my machine, however I want to sort the pictures (taken every 30s) into directories by hour.

Every picture uses the following file format.
yymmddhhmmsstt.jpg (where tt is the milliseconds)

I am thinking the for loop is best

for file in *.jpg
do
?here?
done

I know its very vague, however the end result is I am guessing use awk (or better?) to create variables from the yy mm dd hh parts of the filenames, then creating directories based on those variables nested with a check to see if the directory exists, creating the directory if it doesnt.

i.e. (the way I imagine it working, I dont know how to actually construct the script to do this)

for file in 08072400123200.jpg
do
%y=08
%m=07
%d=24
%h=00
if not exist directory %y - mkdir %y
if not exist directory %y/%m - mkdir %y/%m
if not exist directory %y/%m/%d - mkdir %y/%m/%d
if not exist directory %y/%m/%d/%h - mkdir %y/%m/%d/%h
mv %y%m%d%h*.jpg %y/%m/%d/%h
done

Moving all the pictures taken within that hour into the respective subdirectories.

Any help would be much appreciated.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

2. UNIX for Dummies Questions & Answers

Moving files between directories using SFTP

I want to connect to an SFTP server, GET some files, then move those files to a different directory on the SFTP server so I don't try to GET them next time. But there doesn't seem to be a way to move files between directories on the remote server from SFTP. I missing something obvious? And if... (6 Replies)
Discussion started by: cjhancock
6 Replies

3. Shell Programming and Scripting

moving files and creating a link to it

Hi All, I am in a tricky situation where I have to move my files to a different mount point and create a link in place of the file which will point to the moved location. to explain you in details:- say I have two mount points /dir/mount1/ /dir/mount2/ I have my application... (5 Replies)
Discussion started by: rpraharaj84
5 Replies

4. UNIX for Dummies Questions & Answers

Moving files out of multiple directories and renaming them in numerical order

Hi, I have 500 directories each with multiple data files inside them. The names are sort of random. For example, one directory has files named e_1.dat, e_5.dat, e_8.dat, etc. I need to move the files to a single directory and rename them all in numerical order, from 1.dat to 1000(or some... (1 Reply)
Discussion started by: renthead720
1 Replies

5. Shell Programming and Scripting

moving files between directories !!

hi i have a list of directory in a text file with all directories name in a column.(this is not exactly a file but i need to do a grep and awk on a file to find that list) i have the source folders like abchome/abc/xxyz/nl_xxabc/mm// v01 ... (4 Replies)
Discussion started by: debu000
4 Replies

6. Shell Programming and Scripting

Moving files from several directories into parent

I am fairly new to bash(but am proficient in C++), and have only completed a few simple scripts. This is my first script that I actually need to do a serious task. All of my audiobooks are stored in traditional MP3 format: Music/Artist/Album/*.mp3 (which in this case is... (0 Replies)
Discussion started by: gamendorf
0 Replies

7. Shell Programming and Scripting

moving files to different directories

im trying to move media and other files which are in a specified directory to another directory and create another one if it does not exits(where the files will go),them also create a directory will the remaining files with different extensions will go.my first problem is that my script is not... (8 Replies)
Discussion started by: elginmulizwa
8 Replies

8. Shell Programming and Scripting

Need Help Moving Long List Of Files Into Directories

I am very new to BASH and I am having difficulties moving a long list of image files into similarly named directories. I've been trying to come with a script all night and no luck. Here is what my list of files looks like: DSC_0059_01.jpg DSC_0059_02.jpg DSC_0059_03.jpg DSC_0059_04.jpg... (5 Replies)
Discussion started by: jowens1138
5 Replies

9. Shell Programming and Scripting

Archiving and moving files into directories, creating directories, etc.

how can i move "dataName".sql.gz into a folder called 'database' and then move "$fileName".tar.gz * .htaccess into a folder called 'www' with the entire gzipped file being "$fileName".tar.gz? Is this doable or overly complex. so mydemo--2015-03-23-1500.tar.gz > database -... (5 Replies)
Discussion started by: wyclef
5 Replies

10. Shell Programming and Scripting

Need BASH Script Help to Move Files While Creating Directories

I've got this script to loop through all folders and move files that are more than 2 years old. I'm using the install command because it creates the necessary directories on the destination path and then I remove the source. I'd like to change the script to use the mv command since it is much... (4 Replies)
Discussion started by: consultant
4 Replies
gnomevfs-mkdir(1)						   User Commands						 gnomevfs-mkdir(1)

NAME
gnomevfs-mkdir - make a new directory at a VFS location SYNOPSIS
gnomevfs-mkdir URI DESCRIPTION
gnomevfs-mkdir makes a new directory at a URI location that supports the creation of new directories. OPERANDS
The following operands are supported: URI Specifies the location of the new directory in standard URI format. EXAMPLES
Example 1: Making a New Directory in the Home Directory example% gnomevfs-mkdir file:///home/user/newdir ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables: NLSPATH. EXIT STATUS
The exit value 0 is returned regardless of success or failure. FILES
The following files are used by this application: /usr/bin/gnomevfs-mkdir Executable to make a new directory at a VFS location ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWgnome-vfs | +-----------------------------+-----------------------------+ |Interface stability |External | +-----------------------------+-----------------------------+ SEE ALSO
gnomevfs-cat(1), gnomevfs-copy(1), gnomevfs-info(1), gnomevfs-ls(1) NOTES
Written by Stephen Browne, Sun Microsystems Inc., 2004. SunOS 5.10 6 Sep 2004 gnomevfs-mkdir(1)
All times are GMT -4. The time now is 05:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy