Monday, May 7, 2012

HTML to text file converter

Reason: The downloaded HTML novels included ads when you read them in webbrowser. If you have plain text file, you can read them in your Android system.

1. Download HTML files by using:

wget -r -l1 your_internet_folder

2. Generate one big file:

cat /your/path/to/html/*.html > t.txt

3. The following methods just valid for content lines start with special_string and end with control_string
:

grep "special_string" t.txt > tt.txt
sed 's/special_string//g' tt.txt > ttt.txt
sed 's/control_string//g' ttt.txt > your_file_name.txt

Tuesday, April 17, 2012

list old files in one folder

The command is:

find your_folder -type f -mtime +7 -ls

here -type f just list files (f), not include folder (d)
-mtime +7 list files modified before 7 days
-ctime -7 list files created after one week ago

Wednesday, August 10, 2011

UNIX script: transfer DOS file to UNIX file

/usr/bin/dos2unix -437 "$dosfile" $unixfile

or

tr -d '\r' < "$dosfile" > $unixfile

or

sed 's/^M$//' "$dosfile" > $unixfile

or

perl -pi -e 's/\r\n/\n/g' "$dosfile" > $unixfile

UNIX script: add new line at the end of file, if not exist

if [[ -n "`/bin/tail -1c $unixfile`" ]]; then
echo >> $unixfile
fi

Wednesday, June 22, 2011

use the Unix find command to search through files for a particular word

find [dir] -name [files] | xargs grep [text to search for]

For example,

find . -name “*.v” | xargs grep parity_check

find [dir] -name [files] -exec grep -l “[text to search for]” {} \;

for example

find . -name “*.v” -exec grep -l "parity_check" {} \;

Monday, May 23, 2011

change file permissions

#folder=/path/to/the/folder
# check folder existance
if [[ ! -a "$folder" ]] ; then
echo Folder $folder does not exist.
exit
fi
# list all files including sub folders
files=`find $folder -type f -follow -print`
for f in $files
do
if [[ -x $f ]] ; then
setfacl -m u:user2:rwx $f
setfacl -m m:rwx $f
else
setfacl -m u:user2:rw- $f
setfacl -m m:rw- $f
fi
done

Monday, April 25, 2011

disable fsck at boot time

Easy way to force or disable fsck at boot time with Debian?
Hi, I've got a Debian (etch) laptop using Ext3 and I'd like to avoid having fsck run at inconvenient times when booting (when I need it to boot quickly). I still want to make sure it is run periodically, but would like a way to either bypass the forced check or easily force the check at a convenient time by selecting a Grub menu item.

What would be the easiest way to do this? Is there already a boot option I can use?

I can tell you how to disable it at boot:
edit /etc/fstab the line that pertains to "/" patition, and change the last value to 0
However, it's not advised to do so.

Look at the man page on tune2fs

#tune2fs -c 0 -i 0d /dev/xxxx

How to avoid fsck prompts during the boot sequence?

Write 'FSCKFIX=yes' in /etc/default/rcS. You will not face the fsck problem from the next reboot onwards. However, if the disk is corrupted very badly, your presence may be required. I had done some kernel tweaks also for that. I will write about in subsequent tips.