Linux Tips and Tricks

Linux Tips and Tricks

Free Linux CD

December3

You all know, the Linux is free and open source operating system. So you can download the linux operating system from the respective websites.

As i know, UBUNTU team is distributing the CD's through post (that too free of cost)

Register yourself here and request the CD's and spread the operating system worldwide 🙂

https://shipit.ubuntu.com/

posted under Uncategorized | No Comments »

Uptime command

December3

uptime gives a one line display of the following information. The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.

$ uptime
 10:00:26 up 12 min,  2 users,  load average: 0.26, 0.44, 0.39
 

This is the same information contained in the header line displayed by w(command)  

$ w
 10:00:23 up 12 min,  2 users,  load average: 0.29, 0.45, 0.39
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
kamaraj  tty7     :0               09:48     ?    50.38s  0.18s x-session-manag
kamaraj  pts/0    :0.0             09:58    0.00s  0.16s  0.00s w
 

posted under Uncategorized | No Comments »

Read the CPU Temperature

November8

You can see the current CPU Temperature in the below files

$ ls -l /proc/acpi/thermal_zone/TZS*/temp*
-r–r–r– 1 root root 0 2010-11-08 11:05 /proc/acpi/thermal_zone/TZS0/temperature
-r–r–r– 1 root root 0 2010-11-08 11:05 /proc/acpi/thermal_zone/TZS1/temperature

$ cat /proc/acpi/thermal_zone/TZS0/temperature
temperature:             51 C

$ cat /proc/acpi/thermal_zone/TZS1/temperature
temperature:             52 C
 

posted under Uncategorized | No Comments »

Print the BIOS information

November8

Hi all,

we can use the command called dmidecode to display the BIOS information.

dmidecode is a tool for dumping a computer’s DMI (some say SMBIOS) table contents in a human-readable format. This table contains a description of the system’s hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision. Thanks  to  this  table, you  can retrieve this information without having to probe for the actual hardware.  While this is a good point in terms of report speed and safe‐      ness, this also makes the presented information possibly unreliable.

More information :      man dmidecode

Note : You have to execute this command as root.

 

posted under Uncategorized | No Comments »

The Cat Command

November4

 cat

 

Normally we use the cat command to display the small files. And sometimes we use to create a file.

we can use the cat command for the following purpose.

1) Display the line number.

2) Display the end of the line with $

3) squeeze Multiple blanks to one blank line.

4) view tab seperated lines

Now we see the examples.

1) Display the line number.

$ cat test_script.sh
#!/bin/sh
yesterday=`date -d "yesterday" +%Y%m%d`
echo $yesterday

$ cat -n test_script.sh
     1    #!/bin/sh
     2    yesterday=`date -d "yesterday" +%Y%m%d`
     3    echo $yesterday
 

Note : You have to use the -n option with the cat command to display the line numbers.

2) Display the end of the line with $

echo "test" >> Test
echo "" >> Test
echo "testing" >> Test

cat -e Test

test$
$
testing$
 

Note: Every line of the end you can see the letter $. Just create a line with some space and see where the $ symbol goes.

3) squeeze Multiple blanks to one blank line.

The following commands shows that in the testing_file we have some empty lines.

$ cat -n testing_file
     1    test
     2   
     3   
     4   
     5   
     6   
     7   
     8    another line
     9   
    10   
    11   
$ cat -e testing_file
test$
$
$
$
$
$
$
another line$
$
$
$
 

Now use the -s option in the cat command,

-s, –squeeze-blank
              suppress repeated empty output lines

$ cat -s testing_file
test

another line

$
 

4) view tab seperated lines

I created a file called tab_test with tab seperated words.

$ cat tab_test
this    is    tab    seperated    line
testing    for    cat    command
 

Now i am gonna include the -t option with the cat command.

       -T, –show-tabs
              display TAB characters as ^I


$ cat -t tab_test
this^Iis^Itab^Iseperated^Iline
testing^Ifor^Icat^Icommand
$

In the about output you can see the tab space is filled with ^I (cap symbol followd by capital i )

$ echo "this is not tab seperated line" >> tab_test

$ cat -t tab_test
this^Iis^Itab^Iseperated^Iline
testing^Ifor^Icat^Icommand
this is not tab seperated line

 

posted under Uncategorized | No Comments »

Terminal Calculator

November3

In this example, i am gonna to show how to create a Terminal Calculator.

Open your .bashrc file from your home directory (It is a hidden file). Before making changes, please take a backup of the .bashrc file.

Open the file and add the below lines in your end of the .bashrc file.

#calculator function

function calc
{
  echo "${1}" | bc -l;
}

And save the .bashrc file.

Now, just restart your console. and type the below command.

$ calc 5+5
10

$calc 10*5
50
 

If you like to calculate the sine and cosine values, then you have to use it like this

$ calc "s(45)"
.85090352453411842486

$ calc "c(90)"
-.44807361612917015236
 

posted under Uncategorized | No Comments »

Find Prime Number using Factor Command

October31

Hi All,

Here is the one line command which i written to find out the number is prime or not.

1
2
3
4
5
6
7
8
$read number;result=`factor $number | wc -w`; [ $result = "2" ] && echo "$number is prime Number" || echo "$number is not prime number" ; echo "Factors of" `factor $number`
78
78 is not prime number
Factors of 78: 2 3 13
$read number;result=`factor $number | wc -w`; [ $result = "2" ] && echo "$number is prime Number" || echo "$number is not prime number" ; echo "Factors of" `factor $number`
13
13 is prime Number
Factors of 13: 13

If you like to check for all the numbers then use the below command

1
2
3
4
5
6
7
8
9
10
11
12
$ for i in `seq 1 10`; do result=`factor $i | wc -w`; [ $result = "2" ] && echo "$i is prime Number" || echo "$i is not prime number" ; done
 
1 is not prime number
2 is prime Number
3 is prime Number
4 is not prime number
5 is prime Number
6 is not prime number
7 is prime Number
8 is not prime number
9 is not prime number
10 is not prime number

To display only the prime numbers

1
2
3
4
5
$ for i in `seq 1 10`; do result=`factor $i | wc -w`; [ $result = "2" ] && echo "$i is prime Number"; done
2 is prime Number
3 is prime Number
5 is prime Number
7 is prime Number

Note : Change the seq command input for more output

posted under Uncategorized | No Comments »

Kill the User and his Processes

October31

Here is the one line command which kill the specific user and his all running processes.

kill -9 `ps aux | awk -v var=”kamaraj” ‘$1==var { print $2 }’`

The above command will kill all the processes of the user kamaraj

Note : some processes needs root access to kill

posted under Uncategorized | No Comments »

Creat Directories and Sub Directories in one command

October31

We use mkdir command to create directories. In the mkdir command we have a option called -p, which is used to create directory and sub directories in one shot.

kamaraj@kamaraj-laptop:~/Desktop/testing/test$ man mkdir | grep -A2 “\-p”
-p, –parents
no error if existing, make parent directories as needed

Example :

I am going to create directory in the below manner.

a directory contains the directory b
b directory contains the directory c
c directory contains the directory d

kamaraj@kamaraj-laptop:~/Desktop/testing$ cd test/
$ tree
.

0 directories, 0 files
$ pwd
/home/kamaraj/Desktop/testing/test
$ ls -lrt
total 0
$ mkdir -p a/b/c/d
$ ls -lrt
total 4
drwxr-xr-x 3 kamaraj kamaraj 4096 2010-10-31 12:05 a

$ tree
.
`-- a
       `-- b
             `-- c
                   `-- d
4 directories, 0 files

$

tree command is used to display the directory structure in the tree format ( parents and its childs )

posted under Uncategorized | No Comments »

Find and Replace with SED

October31

Normally we use SED command to replace one word to another.

The following example will replace the word old with the word new in the test.txt file

$ echo “old is old” > test.txt

$ cat test.txt
old is old

$ sed -i ‘s/old/new/’ test.txt

$ cat test.txt
new is old

Note : The above sed command only replaced the first occurance. If you want to replace all the occurance in the line. you have use ‘g’

$ sed -i ‘s/old/new/g’ test.txt

Now, we see how to replace in all the files from the current directory.

$ find . -type f -exec sed -i ‘s/old/new/g’ {} \;

Here is the sample script to take backup of the original file before you do the changes with SED command.

#!/bin/bash
for i in *; do
cp $i $i.bak
sed -i ‘s/old/new/g’ $i
done

SED tutorial: http://www.grymoire.com/Unix/Sed.html

posted under Uncategorized | No Comments »
« Older EntriesNewer Entries »

Recent Comments

    Categories