/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
Wednesday, August 10, 2011
UNIX script: add new line at the end of file, if not exist
if [[ -n "`/bin/tail -1c $unixfile`" ]]; then
echo >> $unixfile
fi
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" {} \;
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
# 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.
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.
Wednesday, March 30, 2011
Send email using telnet by port 25 of SMTP server with attachment
#! /usr/bin/ksh
#########################################
# send email with attachment out of KP #
#########################################
# Usage: mailout email@address
# or mailout email@address filename
#########################################
if [[ $# == 0 ]] then
echo argument number: $#
echo "Usage: mailout email@address filename"
echo " or: mailout email@address"
else
if [[ $# == 1 ]] then
SMTPserver="your.mail.server"
SMTPport=25
(
echo "helo your.unix.machine"
echo "MAIL From:"
echo "RCPT To:<$1>"
echo "DATA"
echo "To: <$1>"
echo "From: Your Name"
echo "Subject: your subject"
echo "your mail body"
echo "."
echo "quit"
) | /path/of/telnet $SMTPserver $SMTPport
else
SMTPserver="your.smtp.server"
SMTPport=25
(
echo "helo your.unix.machine"
echo "MAIL From:"
echo "RCPT To:<$1>"
echo "DATA"
echo "To: <$1>"
echo "From: Your Name"
echo "Subject: your_subject"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
echo
echo '---q1w2e3r4t5'
echo 'Content-Type: application; name="'$(basename $2)'"'
echo "Content-Transfer-Encoding: base64"
echo 'Content-Disposition: attachment; filename="'$(basename $2)'"'
uuencode -m $2 $(basename $2)
echo '---q1w2e3r4t5--'
echo "."
echo "quit"
) | /path/of/telnet $SMTPserver $SMTPport
fi
fi
#########################################
# send email with attachment out of KP #
#########################################
# Usage: mailout email@address
# or mailout email@address filename
#########################################
if [[ $# == 0 ]] then
echo argument number: $#
echo "Usage: mailout email@address filename"
echo " or: mailout email@address"
else
if [[ $# == 1 ]] then
SMTPserver="your.mail.server"
SMTPport=25
(
echo "helo your.unix.machine"
echo "MAIL From:
echo "RCPT To:<$1>"
echo "DATA"
echo "To: <$1>"
echo "From: Your Name
echo "Subject: your subject"
echo "your mail body"
echo "."
echo "quit"
) | /path/of/telnet $SMTPserver $SMTPport
else
SMTPserver="your.smtp.server"
SMTPport=25
(
echo "helo your.unix.machine"
echo "MAIL From:
echo "RCPT To:<$1>"
echo "DATA"
echo "To: <$1>"
echo "From: Your Name
echo "Subject: your_subject"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
echo
echo '---q1w2e3r4t5'
echo 'Content-Type: application; name="'$(basename $2)'"'
echo "Content-Transfer-Encoding: base64"
echo 'Content-Disposition: attachment; filename="'$(basename $2)'"'
uuencode -m $2 $(basename $2)
echo '---q1w2e3r4t5--'
echo "."
echo "quit"
) | /path/of/telnet $SMTPserver $SMTPport
fi
fi
Wednesday, March 23, 2011
debian 6 for acer aspire one
use dd if=debian6.iso of=/dev/sda to generate flash bootable net inst source.
Install with wire netcard
install wireless card by ndiswrapper and windows driver. Instead of using ifup/ifdown, or network start with interface file, should use iwconfig essid and dhclient. Put the script into /etc/init.d and link to rc2-5.d. run m-a to make it works.
For sound card, use alsactl init and reboot system.
For chinese input, install scim and rxvt-unicode.
Install with wire netcard
install wireless card by ndiswrapper and windows driver. Instead of using ifup/ifdown, or network start with interface file, should use iwconfig essid and dhclient. Put the script into /etc/init.d and link to rc2-5.d. run m-a to make it works.
For sound card, use alsactl init and reboot system.
For chinese input, install scim and rxvt-unicode.
Wednesday, March 16, 2011
Tuesday, February 22, 2011
Search whole disk content
grep -i -a -B10 -A100 'myTextFile' /dev/sda1 > myRecoveryFile.txt
vi myRecoveryFile.txt
vi myRecoveryFile.txt
Subscribe to:
Posts (Atom)