Alfred’s Computing Weblog

Alfred Java-cored Computing Weblog

Archive for the ‘linux’ Category

Linux | Find string in files

leave a comment »

Problem
I am trying to search for a string from the XML files (yup, more than an XML file)

Solution
I use grep with option “-an” which will print out the file name and line number of the found string.
The command below will search for text “my text” from all XML files in my current working directory.

grep -an "my text" *.xml

15 Practical GREP, resource

Written by Alfred

August 17, 2011 at 14:58

Posted in linux

Tagged with , , ,

Disable BEEP sound in Terminal

leave a comment »

I’m not sure this is the best solution or not, but its work!
This is an output of my google when I want to disable the error beep sound in terminal.
The beep sound I’m talking about is the annoying sounds like
“beep” or “tuuu” when you’re over pressing backspace or type something wrong in terminal.

The solution that I’m going to share here is COPY from netty5.
I feel that its very useful especially to those who is not familiar with terminal,
coz everything can be done by few mouse clicks.

1. Move your pointer to the top-left corner of your desktop.
2. Click on “Applications” > “Accessories” > “Terminal”. A terminal will be pop up.
3. On the Terminal, click on “Edit” > “Profiles..”. A small windows named “Profile” will be pop up and a “Default” profile is selected by default.
4. Click on “Edit” in the Profile window. Another small window will be pop up.
5. Click on “General” tab, UNCHECK the “Terminal bell”, and close all poped up windows. And you’re done. no more “beeeep” or “tuuuuu” sounds 🙂

FYI, I’m using Ubuntu 9.04 at the moment.

Written by Alfred

June 16, 2009 at 18:36

Posted in linux

Tagged with , , ,

Linux | Shell Script : Compare File Last Modification Date

leave a comment »

test is a very useful command in Linux, esp when you’re writing a shell script.
There is some very useful function the test can do it for you easily.
Today, I would like to introduce the powerful tools in test to do file’s last modified time comparision.
The keyword is -nt and -ot. Both command required 2 inputs to be place before and after the keyword,
eg: FILE1 -nt FILE2.

-nt indicates that FILE1 is NEWER (modification date) than FILE2.
-ot indicates that FILE1 is OLDER (modification date) than FILE2.

Here is a sample yet complete shell script to describe it..

#!/bin/bash
file1=newer_file.txt
file2=older_file.txt

if test $file1 -nt $file2
then
    echo "$file1 is NEWER than $file2"
else
    echo "$file1 is OLDER than $file2"
fi

Written by Alfred

February 10, 2009 at 17:17

Posted in linux

Tagged with , , ,

Linux | SoftLink

leave a comment »

Softlink, aka Symbolic link, is a reference to another path / file. its like a pointer in common programming.

Create softlink
Format: ln –s {target} {link_name}
Eg:
$> cd /
$> mkdir -p tmp/test/aa/bb/
$> ln -s tmp/test/aa/bb/ tmp/link
$> ls -l tmp/
.. lrwxrwxrwx 1 root root 15 Feb 6 11:26 link -> tmp/test/aa/bb/

1. Go to root path
2. create folder with subfolders
3. make softlink (/tmp/link) to /tmp/test/aa/bb/

Remove softlink
Format: rm {link_name}
eg: $> rm /tmp/link

Reminder: do not include the slash after the softlink

Written by Alfred

February 6, 2009 at 12:38

Posted in linux

Tagged with ,

Linux | Run backend process

leave a comment »

to run a linux backend process :

$> nohup ./start.sh &

Written by Alfred

November 4, 2008 at 10:46

Posted in linux

Tagged with , ,

bad interpreter – no such file or directory

leave a comment »

I hit this error recently “bad interpreter – no such file or directory” when I trying to run/execute a shell script in linux box. The shell script is quite simple, just to initialize a java class.

This “bad interpreter – no such file or directory” is cause by the line-feed / carriage-return issue among windows-linux OS. The shell script is initially written in windows before I ftp it into linux box and run.

To solve it, is very simple — dos2unix.
$> dos2unix my-script.sh

The dos2unix is DOS/MAC to UNIX text file format converter (according to linux manual). It helps to solve the CR/LF conflicts between windows and *nix.

Besides, do remember to do another command to make an .sh file executable in linux — chmod.

$> chmod +x my-script.sh

Written by Alfred

May 9, 2008 at 11:22

Posted in linux

Tagged with ,