Linux ip examples

ip address

ip get

ip route

Posted in Uncategorized | Leave a comment

Linux Netstat examples


netstat -nl

netstat -na

netstat -nr

sudo netstat -nap

Posted in Uncategorized | Leave a comment

copy files off my camera card to my pictures directory

=== Update 11/2013 ==

Sooo, I found that the below script didn’t do really what I wanted and I got a lot of files from 2012 in 2013 folders. So I’ve changed it around to use stat and maybe exif data in the future:

function rsyncFile()
for img in ${PATH}/*
echo “${img}”
ymd=`${STAT} -c %y “${img}” | ${CUT} -d’ ‘ -f1 | ${SED} -e ‘s/-/./g’`
year=`echo ${ymd} | ${AWK} -F. ‘{print $1}’`
month=`echo ${ymd} | ${AWK} -F. ‘{print $2}’`
day=`echo ${ymd} | ${AWK} -F. ‘{print $3}’`

${MKDIR} -p ${picturesPath}
echo ${RSYNC} -av “${img}” ${picturesPath}
${RSYNC} -av “${img}” ${picturesPath}



== End Update

Here’s a quick bash script I wrote to copy stuff from my camera memory card to my Pictures directory but so that it will create it in the format that I like:


So Feb 1st, 2013 pictures would be in directory:


The script is really just a function that takes 3 arguments, the month in ls format, the two digit representation of the month, and the year:


MONTHS="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"


function rsyncMonth()

  echo $month $numonth $year

  for img in `${LS} -l ${PATH} |${GREP} ${month}|${AWK} '{print $NF}'`
    day=`${LS} -ld ${PATH}/${img} | ${AWK} '{print $7}'`
    if [ ${day} -lt 10 ]
    ${MKDIR} -p ${picturesPath}
    ${RSYNC} -av ${PATH}/${img} ${picturesPath}

and you would call it below the function like:

rsyncMonth Jan 01 2013

to get all the pictures off the memory card that match January 2013.

Posted in software, tips | Tagged , , , | Leave a comment

ext4 recover deleted files (undelete) using ext4magic on CentOS 6

So the other day, I was helping a user get back some files that got deleted on the local disk of a CentOS 6.3 server. Here’s pretty much the steps I did:

  1. Unmount the partition: umount /tmp
  2. Make an image of the partition to work with on a partition that had enough space for it:
    1. cd /var/preserve
    2. dd if=/dev/mapper/vg_01-lv_tmp of=tmp_fs.img
    3. Or if you need to do it over the network you need to:
      ssh root@server “dd if=/dev/mapper/vg_01-lv_tmp” > tmp_fs.img
  3. Download and compile ext4magic at
    1. yum install e2fsprogs-devel uuid-devel libblkid-devel file-devel
    2. wget
    3. tar -xvpf ext4magic-0.3.1.tar.gz
    4. cd ext4magic-0.3.1
    5. ./configure
    6. make
  4. Since the files were delete 4 days ago, I decided to R recover (everything) after 5 days ago and before 2 days ago.
    1. sudo src/ext4magic -R \
      -a $(date -d “-5day” +%s) \
      -b $(date -d “-2day” +%s) \
      -d /var/preserve/RECOVER /var/preserve/tmp_fs.img

Boom, the files that I was looking for were in a MAGIC-1 directory since the missing files were in  directory tree that all got deleted.

Posted in software | Tagged , , , , | 2 Comments

Posting stuff to github

I finally started to upload stuff I work on in my own time/hardware on github. Check out my okayryan username.

So far I just have a named check zone wrapper and a fedora 18 ansible playbook.

Posted in software | Tagged | Leave a comment

one liner to simply check for pictures and video in my pictures home directory

I used this today to just check and make sure what files I can remove off my sdcard. I just simply checked the filesize on the files and make sure it was the same in my Pictures directory in my home directory. If I wanted to be very fancy, I could have done a sha1sum on the files to make sure the hashes were completely the same.

/media/ryan/8765-4321/DCIM/146EKZi8$ for a in `ls`; do ls -l $a; \
find /home/ryan/Pictures -name $a  -exec ls -l '{}' \; ; done &> /tmp/kodak

Posted in software | Tagged , | Leave a comment

publish photo shotwell piwigo invalid username password with & symbol

Just submitted a bug report for shotwell on Ubuntu 12.10:

Basically, when trying to publish a picture to my piwigo website, I get an invalid username or password if my password has a & in it.

Piwigo version: 2.4.5

shotwell version: 0.13.0

Ubuntu version: 12.10

Work around is just not use the & symbol in your password and it works fine.

Posted in software | Tagged | Leave a comment

how to replace newlines in linux using tr

I like to use sed for all my string replacements when I’m in bash or use the %s option in vim. Unfortunately, when I have to get rid of newlines, I always end up doing a macro that join lines and does an edit on them.

Now you don’t if you use the translate (tr) tool found in linux. You can use tr for other purposes by checking out the man page, but I pretty much just use it to strip out all the newlines in a text file. I simply just cat out a file and pipe it through tr to do my work:

To change all the newlines into semicolons:
cat file.txt | tr '\n' ';'
To change all the newlines into spaces:
cat file.txt | tr '\n' ' '

Just redirect the output to file if you want to save it.
Replace the newline with the number 3 and output the results to file3.txt:
cat file.txt | tr '\n' '3' > file3.txt

Posted in software, tips | Tagged , , , , | Leave a comment

Easy gcc compile using download_prerequisites in contrib and compiling gcc on CentOS 6 x86_64

For the longest time, I never noticed that there was a contrib directory in gcc’s source archive. Not only that, but the download_prerequisites script does an amazingly simple job that saves me minutes off a single gcc compile.

What does it do? download_prerequisites actually downloads the exact version of gmp, mpc, and mpfr that gcc needs to build. The extra boot is that it sets up the symbolic links and so when you do the configure and make for gcc, it will very much build the dependicies without fail almost every time. Here’s an example CentOS 6 x86_64 that I’ve done the other day

tar -jxvpf gcc-4.7.1.tar.bz2
cd gcc-4.7.1
mkdir objdir
cd contrib
cd ../objdir
./configure --build=x86_64-pc-linux-gnu  --prefix=/home/ryan/software/gcc/4.7.1 --disable-multilib
make install
Posted in software | Tagged , , , | Leave a comment

Recovered deleted pictures from canon sdcard

I was able to use the ZAR data recovery software to restore an entire directory full of images after someone deleted their folder via the camera.

Pretty good software and I like their name of “Zero Assumption Recovery.” Remember that if your data isn’t in 2 places, it doesn’t exist anywhere, make backups ASAP!

Posted in software | Tagged , , , | Leave a comment