Linux Blog

xrandr – Set Primary Monitor

Filed under: Linux Hardware,Linux Software,Shell Script Sundays — Owen at 11:04 pm on Sunday, October 27, 2013

I had an issue with my dual monitor setup where my primary monitor was my second, but only in X. Rearranging the monitors in Gnome preferences did nothing to solve the problem. While not exactly a shell script, here is a one-liner to change your primary monitor with xrandr.

#!/bin/bash
xrandr --output DVI-0 --primary

The above uses xrandr to set the primary to DVI-0. I put this in my ~/bin folder, chmod’d and set it to start when Gnome starts. Problem solved!

Cleaning Up Files & Directories

Filed under: Shell Script Sundays — TheLinuxBlog.com at 8:30 am on Sunday, August 19, 2012

While not really a shell script as such, this is shell related and  it just so happens to be Sunday.

Find Empty Directories:

find . -type d -empty > empty_folders.txt

Find Empty Files

find . -type f -empty > empty_files.txt

The issue with these two commands is that within my jumble of unorganized mess I have an abundance of version control repositories (mostly SVN) and tons of source code with empty, but needed directories. Fear not if you have the same problem, you can filter them out by using:

grep -v empty_files.txt svn

Duplicate File Removal

There are multiple ways to remove duplicate files. I used to think a  recursive md5sum script was the way to go but that was before I found the utility fdupes.
Install via your package manager if it’s available and use recursively like:

fdupes -r [directory] > duplicates.txt

With fdupes you also have the ability to symlink or delete files, although because of the amount of source code, I’d rather review it manually.


With these utilities I was able to merge copies of photos remove a bunch of old files and empty directories and am one step closer to being digitally organized. If you have the same problem, hopefully they will help you too. If you have any cleanup or organization tools, please comment and let me know.

tee time!

Filed under: Shell Script Sundays — TheLinuxBlog.com at 3:19 pm on Sunday, June 10, 2012

This weekend was South East Linux Fest, although I’m bummed I couldn’t make it I did learn something new from taking an LPIC level 1 self assessment. What I learned about was the application tee.

The question was something like:

“What command outputs to stdout and also writes to a file”

My answer was “echo” but that was the wrong answer. The correct answer was tee.

I’d seen it before in either Slackware or Debian’s packages list but forgot totally about it. It’s a pretty handy utility to have in your arsenal if you ask me. Usage would be something like this:

date | tee date.txt

this will echo the current date out, and also write it to date.txt. Of course, there are plenty of useful options which can be viewed in the man page which is linked below.

Enjoy! Happy Shell Scripting!

Spring Cleaning

Filed under: General Linux,Shell Script Sundays — TheLinuxBlog.com at 6:30 am on Sunday, April 1, 2012

It’s that time of year, tree’s, plants and animals doing there thing. The time of the year where other wildlife and beings start cleaning up since the weather is nice. I guess it’s time for a post on some spring cleaning for the Linux folk

We will start off with a classic, sure to give you a clean start:
rm -rf .
Best done from root, just remember to press CTRL+c and/or reboot as quickly as possible when you realize what you have done.

On a serious note, I had a bunch of annoying hidden files in backup directories I wanted to get rid of. This did the trick.

find . -iname ".*"
find . -iname ".*" | wc -l
find . -iname ".*" | while read i ; do echo rm "$i" >> possibly_remove; done;

The above is conservative. ‘chmod 755 possibly_remove’, verify there are no files in there you actually want, you are in the correct directory then ‘./possibly_remove’ and you’re golden. Mmm. Spring freshness.

Since I like to live on the wild side, I run it without creating a file of files to delete that can be executed like this:

find . -iname ".*" | while read i ; do rm "$i"; done;

This will also work to cleanup nasty files that may have been accumulating a while that may be have left behind. It can be used to find and delete all Thumbs.db files by doing this:

find . -iname "thumbs.db" | while read i ; do rm "$i"; done;

The above is pretty careless, in most cases it probably wouldn’t hurt.

That is all the spring cleaning I have done, except for some random fsck’ing’ that was long overdue.

Automated Scanning with the Shell – UPDATE

Filed under: Shell Script Sundays — TheLinuxBlog.com at 10:00 am on Sunday, December 18, 2011

I wrote a little script a while back that would help to automate scanning from the shell.  Mark posted some suggestions that I’ll be implementing in this post. (Read on …)

Virtual Box Clone Script

Filed under: Shell Script Sundays — TheLinuxBlog.com at 8:30 am on Sunday, February 27, 2011

I was in need for a way to clone virtual box vms so I wrote a quick bash script to clone them. After writing it, I realized that I could just export a VM, and then import it. There are limitations such as no snapshot support and probably a bunch I’ve never thought about. Either way, hit the jump to see the outcome.

(Read on …)

Bash Script Renaming Files

Filed under: Shell Script Sundays — TheLinuxBlog.com at 3:15 am on Sunday, February 6, 2011

I recently needed to rename a bunch of files. I didn’t want to do it manually because it would take too long and I don’t like copying+pasting that many times. This is where shell-scripting comes in handy. (Read on …)

Optimizing Shell Scripts

Filed under: Shell Script Sundays — TheLinuxBlog.com at 6:30 pm on Sunday, January 23, 2011

optimizing shell scripts

I’ll be honest, I’m no expert on optimizing shell scripts. I’m hoping that readers will chime in with their tips / experiences. With that being said I do have a few tricks up my sleeve from hands on experience with code optimization using other languages.

(Read on …)

Asterisk AGI Area Code Lookup

Filed under: Shell Script Sundays — TheLinuxBlog.com at 6:00 am on Sunday, January 9, 2011


I’ve written about my Asterisk meddling before in my Asterisk AGI IP Address lookup post. This time I’m writing about an Area Code Lookup Script I wrote that was inspired by Nerd Vittles WiFi Finder. The script prompts the user to enter a 3 digit area code and then reads the results back to the user.

The tar.gz file needs to be extracted and the resulting files placed into your agi-bin. The source can be found here.

Here is what it sounds like for the 404 areacode (ogg / mp3). After recording this I found out it would probably be a good idea to unique the array so items are not read twice, but it works for me.

Remove all subversion .svn folders

Filed under: Quick Linux Tutorials,Shell Script Sundays — TheLinuxBlog.com at 2:30 am on Sunday, December 12, 2010

remove all subversion folders

This may be a no brainer for some of you elitists out there but if you need to (I don’t ask questions) remove all .svn folders within a project there is an easy way to do so. This would also work for other directories, but my main purpose for writing this is for .svn files / folders.

find . -iname ".svn" | xargs rm -r $1

I suppose you could also use svn export to get similar functionality, but if you’ve already checked out code, you wouldn’t want to waste precious internets and do it again would you?

C++ preprocessor “/lib/cpp” fails sanity check

Filed under: Shell Script Sundays — TheLinuxBlog.com at 8:59 am on Sunday, November 21, 2010

c-preprocessor-libcpp-fails-sanity-check

Not exactly a shell script, but might be handy.

C++ preprocessor "/lib/cpp" fails sanity check

In my case I had forgot to install g++. Now I feel like a complete idiot, not the first time though.

Next Page »