Archive for 'Linux' Category
Date formats with Linux
$ date +%B” “%d”,”” “%Y May 02, 2012 $ date +”%m-%d-%y” 05-02-12
bash shell tips for filenames
# remove empty files rm -f $(find . -empty) # change all filenames from upper to lower case rename ‘y/A-Z/a-z/’ * # change all filenames from spaces to underscores find -name “* *” -type f | rename ‘s/ /_/g’
Bash script to create a .m3u from a directory
#!/bin/bash dir=`echo ${PWD##*/}` echo “Create a .m3u playlist for $dir …” ls *.mp3 -1 >> “$dir.m3u” ls *.mp4 -1 >> “$dir.m3u” ls *.m4v -1 >> “$dir.m3u” echo “Found these media files:” cat “$dir.m3u”
using awk to print columns from a file
1st column $ awk ‘{ print $1 }’ < file> newfile 2nd column $ awk ‘{ print $2 }’ < file> newfile nth column $ awk ‘{ print $n }’ < file> newfile
Add Linux swapfile as virtual memory
Add a 1 GByte swapfile: $ dd if=/dev/zero of=/swapfile bs=1M count=1024 $ mkswap /swapfile $ swapon /swapfile to make it available on boot, edit /etc/fstab file and include: /swapfile swap swap defaults 0 0