{{{1}}}

Contents

putInDir

putInDir is a bash script to move a file in a directory which has its name or, putInDirDate (see below), its date.

These two should be brought together ultimately (with options).

Versions

Usage

Call the script with the file to move as argument:

putInDir filename.dat

It will create a directory "filename" and move "filename.dat" in it.

To process all files of a given extension, use:

for f in *.zip; do putInDir "$f" ; done

Source

#!/bin/bash

  1. _ ___ ____ _
  2. _ __ _ _| |_|_ _|_ __ | _ \(_)_ __
  3. | '_ \| | | | __|| || '_ \| | | | | '__|
  4. | |_) | |_| | |_ | || | | | |_| | | |
  5. | .__/ \__,_|\__|___|_| |_|____/|_|_|
  6. |_|
  7. F.P. Laussy -- laussy.org
  8. Wed Apr 25 10:00:49 CEST 2012
  9. v°0.1
  10. This create a directory with the name of the file
  11. passed as an argument and move the file inside.
  1. Separating filename from extension

filename=$(basename $1) extension=${filename##*.} filename=${filename%.*}

  1. Create directory and translate the file

mkdir $filename mv $1 $filename

putInDirDate

Usage

Copy the file in the directory where files to be sorted are present (check extension in the script) and run. Be careful, it could be dangerous (no undo!)

Source

#!/bin/bash
#23 September 2017

for x in *.JPG; do
    d=$(date -r "$x" +%Y-%m-%d)
    mkdir -p "$d"
    mv -- "$x" "$d/"
done