#!/usr/bin/env bash BASE_DIR=$1 if [ ! -d "${BASE_DIR}" ] ; then echo "$BASE_DIR is not a directory"; fi ## Find those files that are older than a month find "$BASE_DIR" -maxdepth 1 -mtime +30 -type f -name '*.jpg' | while IFS= read -r file; do ## Get the file's modification year year="$(date -d "$(stat -c %y "$file")" +%Y)" ## Get the file's modification month month="$(date -d "$(stat -c %y "$file")" +%b)" ## Create the directories if they don't exist. The -p flag ## makes 'mkdir' create the parent directories as needed so ## you don't need to create $year explicitly. [[ ! -d "$BASE_DIR/$year/$month" ]] && mkdir -p "$BASE_DIR/$year/$month"; ## Move the file mv "$file" "$BASE_DIR/$year/$month" done
Tag Archives: bash
Batch rename files with Cyrillic filenames to Latin ones (transliterate file names)
If you have a bunch of files with Cyrillic file names, there is a chance that some old devices such as TV embedded players, car audio systems, mp3 players may not recognize them or fail to read. The quick and dirty solution is to rename these files to Latin only characters. In order to save some time I use this handy bash script. It works flawlessly on both Windows (Git Bash) and native Linux systems. Continue reading
Add GIT branch information to Bash prompt
I’ve seen such as fancy Bash prompts on various tutorials and Linux examples over the Internet and I’ve always wondered how is achieved. I never really had a enough free time to learn more about it and explore the options. But being jobless for a month gave me opportunity to play with the thinks I like 🙂
My solution is pretty simple: when you navigate to git controlled folder, the bash prompt will show “@ branch” after the directory name. Nothing fancy.
Just open your ~/.bashrc configuration file with your favorite editor and add the following:
get_git_branch () { git name-rev HEAD 2> /dev/null | sed "s/[a-zA-Z0-9]\+\ \(.*\)/ @ \1/" }
than put this into your PS1 string:
$(get_git_branch)
so it become something like that
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w$(parse_git_branch) \n\$\[\033[00m\] '
Restart your terminal or type bash to start new bash session. Navigate to git controlled folder to test. It should look like this:
How To Get The Log Instead of Just Revision Numbers by svn merge info
svn merge command is really great – it can be used to determine which revisions are already merged and which are eligible to merge from particular branch. But has one big drawback – it can output just the revision numbers, but not the corresponding log messages. So, it’s really hard to determine what has been commited actually with these revisions. Of course, you can run svn log command for the revisions in question, but what if there are, lets say, 50 commits?
You could build a list of commit messages by piping mergeinfo into the svn log command using xargs. It looks like this:
svn mergeinfo --show-revs=eligible ^/branches/version | tr "\\n" "," | xargs -i svn log -c {} ^/branches/version
To make the command little bit easier and shorter, you may consider to add an alias in your ~/.bash_aliases file as follow:
alias svnlog='tr "\\n" "," | xargs -i svn log -c {}'
Now, you can shorten the command like that:
svn mergeinfo --show-revs=eligible ^/branches/version | svnlog ^/branches/version
How to Undo Changes in “nano” Text Editor in Ubuntu
Nano has experimental undo/redo feature. As you’ll see from the nano manual (type “man nano” in a Terminal to read that), you’ll need to start nano with the -u option
$ nano -u somefile.txt
… and then you can use Alt-U to undo and Alt-E to redo.
It’s little bit frustrating that you have to type the “-u” option every time when you want to edit a file, but hopefully there is a solution and its name is “alias”.
Aliases are a way for you to customize the commands by giving them aliases (nicknames). You can use them to remember commands with a lot of options or make their names shorter and easier to type. To setup aliases, all you need is to open the ~/.bash_aliases file and type in:
alias nano='nano -u'
If you want to add more aliases, enter each of them on separate line.
Now, typing “nano” is equal as typing “nano -u”. Tricky, yeah?