Home / Technology / programming / My Unix Commands
21 January, 2011

My Unix Commands

Posted in : programming, unix on by : admin

0 votes (0 stars)

Find text within files in sub directories
find . -type f -exec grep -il “text string” {} ;

Change the photo files name:
for f in 100_*.jpg; do mv $f ${f/100_/p}; done

Add an ‘s’ to thumbnail:
for f in p*.jpg; do mv $f ${f/./s.}; done

List all files including sub directories into file ‘a.txt’:
ls -R > a.txt

Remove the ‘s’ character from the result:
sed -e ‘s/s//g’ a.txt > b.txt

Remove duplicates:
uniq a.txt > b.txt

List directories in reverse order:
ls -r > ‘c.txt’

One fine swoop:

ls -R > a.txt; sed -e 's/s//g' a.txt > b.txt; uniq b.txt > c.txt; sed -e "s/.jpg/' => Array(2009,  2, 1, " "),/g" c.txt > d.txt; sed -e "s/100_/'100_/g" d.txt > e.txt;

OLD CODE:
ls -R > a.txt; sed -e 's/s//g' a.txt > b.txt; uniq b.txt > c.txt; sed -e "s/.jpg/'' => Array(2008,  12, 1, " "),/g" c.txt > d.txt; sed "s/p/'/g" d.txt > e.txt; sed ’s/Thumb.db//g’   e.txt > final.txt; ls -r > dirs.txt;

Create Direcotories a, b, c:
mkdir a; mkdir b; mkdir c