Subscribe to Lily Avida Subscribe to Lily Avida's comments

Archive for the ‘unix’ category

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

Dang, I swear I look for these commands way too often. So here it is once and for all:

Extract a .gz file:
gzip -d file.gz

Extract a tar.gz file:
tar xvzf file.tar.gz

Long live the internet!

I found this line on centerkey.com:

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'

It was very useful, and created simple graphic tree of my sub-directories.

Live long the internet!