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
sane-dc25(5)						   SANE Scanner Access Now Easy 					      sane-dc25(5)

NAME
sane-dc25 - SANE backend for Kodak DC20/DC25 Digital Cameras DESCRIPTION
The sane-dc25 library implements a SANE (Scanner Access Now Easy) backend that provides access to Kodak DC20 and DC25 cameras. At present, only the DC25 has been tested, but since the code is based on a DC20 interface program, it is likely to work for that model also. DEVICE NAMES
The current version of the backend only allows one camera to be connected. The device name is always "0". CONFIGURATION
The contents of the dc25.conf specify the serial port and baud rate to use. The baud rate specifies the maximum rate to use while down- loading pictures. (The camera is always initialized using 9600 baud, then switches to the higher rate). On my 90MHz Pentium, I usually have no problems downloading at 115200 baud as long as the system is not excessively busy and the "interrupt-unmask flag" is set in the IDE driver (hdparm -u1). Supported baud rates are: 9600, 19200, 38400, 57600, and 115200. The dumpinquiry line causes some information about the camera to be printed to stderr during startup. Note: This is not compatible with saned, so make sure you don't have any dumpinquiry lines if you are using saned (i.e. scanning on a remote machine using a network). Empty lines and lines starting with a hash mark (#) are ignored. A sample configuration file is shown below: port=/dev/ttyS0 # this is a comment baud=115200 dumpinquiry FILES
/etc/sane.d/dc25.conf The backend configuration file (see also description of SANE_CONFIG_DIR below). /usr/lib64/sane/libsane-dc25.a The static library implementing this backend. /usr/lib64/sane/libsane-dc25.so The shared library implementing this backend (present on systems that support dynamic loading). ENVIRONMENT
SANE_CONFIG_DIR This environment variable specifies the list of directories that may contain the configuration file. Under UNIX, the directories are separated by a colon (`:'), under OS/2, they are separated by a semi-colon (`;'). If this variable is not set, the configura- tion file is searched in two default directories: first, the current working directory (".") and then in /etc/sane.d. If the value of the environment variable ends with the directory separator character, then the default directories are searched after the explic- itly specified directories. For example, setting SANE_CONFIG_DIR to "/tmp/config:" would result in directories "tmp/config", ".", and "/etc/sane.d" being searched (in this order). SANE_DEBUG_DC25 If the library was compiled with debugging support enabled, this environment variable controls the debug level for this backend. A value of 128 requests maximally copious debug output; smaller levels reduce verbosity. SEE ALSO
sane(7) AUTHOR
Peter Fales, dc25-devel@fales-lorenz.net BUGS
Known bugs/limitations are: I haven't figured out how to trigger an option reload following a "scan." This causes problems when a new picture is snapped for example, the slider that is used to select the picture from the camera may not be updated immediately. More general comments, suggestions, and inquiries about frontends or SANE should go to the SANE Developers mailing list (see http://www.sane-project.org/mailing-lists.html for details). You must be subscribed to the list, otherwise your mail won't be sent to the subscribers. 11 Jul 2008 sane-dc25(5)
All times are GMT -4. The time now is 08:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy