Showing posts with label grep. Show all posts
Showing posts with label grep. Show all posts

Wednesday, July 19, 2017

How to get the serial number of your network device in linux?


1. sudo lshw -C network | grep -i serial
    lshw    - Command used to list the details of all available hardware in a system.
    -C      - Option used to specify hardware "class".
        network - We asked "lshw" to list only the network devices.

    grep    - Command used to print lines that matches the given pattern
    -i    - Option used to ignore case sensitivity
    serial    - Pattern used to fetch the lines that contains the word "serial"

Example:
$sudo lshw -C network | grep -i serial
[sudo] password for :
       serial: 78:f2:9e:f3:88:e7

   
2. /sbin/ifconfig | grep -i hwaddr or sudo ifconfig | grep -i hwaddr
    ifconfig-Command used to configure network devices.
    grep    - Command used to print lines that matches the given pattern
    -i    - Option used to ignore case sensitivity
    serial    - Pattern used to fetch the lines that contains the word "serial"


Example:
$/sbin/ifconfig | grep -i hwaddr
eth0      Link encap:Ethernet  HWaddr 78:f2:9e:f3:88:e7  


3. GUI Way
Applications -> System Tools -> Settings

                                  You will land in the following screen
Settings panel



Click on Network the following window will be open


Network settings panel


The green highlighted part is our interest.




Thursday, November 1, 2012

how to view all the uninstalled packages in a debian based linux?

dpkg - > is a debian package manager command
dpkg -l - > will list all the packages with their status installed/deinstalled/removed/half-installed etc

The first 2(actually 3) letters of the output of " dpkg -l " command are significant to us, because it tells the current state of the package.  if it is
ii  - installed
rc - removed but configuration files are kept
So, " $dpkg -l | grep ^rc "
will display all the package that are removed but configuration files are still kept.

Note: if you purged configuration files of a package during removal using
"apt-get remove --purge < package_name >" then those packages will not be displayed.

For more information about dpkg :
i) man dpkg
ii) dpkg -l - > Read the first 4 lines ;-)
iii) Read this http://linuxprograms.wordpress.com/2010/05/11/status-dpkg-list/

Wednesday, August 24, 2011

How to initialize sound in debian based Linux?

I met with this weird problem today, No sound output from my system with any player say banshee, totem etc... But yesterday it works fine. I checked all the sound settings in volume control it seems everything is perfect, but no sound output :(. Atlast i got the solution for this. Just give the following command in the terminal as root.

#alsactl init
The above command initializes the alsa sound card driver :). So after this audio works find

My audio driver is
:~$ lspci | grep -i audio
00:1b.0 Audio device: Intel Corporation 82801JD/DO (ICH10 Family) HD Audio Controller (rev 02)

My system's snd module details:
:~$ lsmod | grep snd
snd_hda_codec_realtek 163294 1
snd_hda_intel 16811 4
snd_hda_codec 46002 2 snd_hda_codec_realtek,snd_hda_intel
snd_hwdep 4054 1 snd_hda_codec
snd_pcm_oss 28671 0
snd_mixer_oss 10461 1 snd_pcm_oss
snd_pcm 47226 4 snd_hda_intel,snd_hda_codec,snd_pcm_oss
snd_seq_midi 3576 0
snd_rawmidi 12513 1 snd_seq_midi
snd_seq_midi_event 3684 1 snd_seq_midi
snd_seq 35463 2 snd_seq_midi,snd_seq_midi_event
snd_timer 12258 3 snd_pcm,snd_seq
snd_seq_device 3673 3 snd_seq_midi,snd_rawmidi,snd_seq
snd 34375 17 snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_rawmidi,snd_seq,snd_timer,snd_seq_device
soundcore 3450 1 snd
snd_page_alloc 5045 2 snd_hda_intel,snd_pcm

# <- Refers the root user in terminal
$ <- Refers the non-root user in terminal
Am using BOSS 4.0 Linux.

Wednesday, March 23, 2011

What is cron,crontab & how to use it?

Cron :
is a daemon process which checks the crontab every minute for checking is there any scheduled task to execute. After this checking it goes to sleep and waits for the next minute to wokeup and check the crontab. The cron daemon is one of the bootup process which starts running from the bootup of the system. If you want to check the cron daemon process, issue the following command in terminal

$ps -e | grep cron


Crontab(le) :
is a file which has the entries for scheduled tasks. The entries follows the following syntax.
M H DOM MOY DOW Task(command)
Where,
M -> Minute entry. Value range (0-59)
H -> Hour entry Value range (0-23)
DOM -> Day of Month Value range (1-31)
MOY -> Month of the Year Value range (1-12)
DOW -> Day of week Value range (0-6) where 0-Sunday, 1-Monday, ....

Example entry:1

Min Hour DOM MOY DOW Task

*   *    *   *   *   date  >> /tmp/every_minute.txt 


* <- means 'for all' The above entry will works on every minute and just appends the output of the command 'date' into the file '/tmp/every_minute.txt'. By opening the every_minute file in gedit you can see the output on every minute. If you want any other task to automate in the backend or chage the time when it needs to run configure the task entry as your need. Example entry:2
Min Hour DOM MOY DOW Task
30 22 * * * rm -r /tmp/*

The above entry will run everyday night 10.30(22.30) and removes everything from the /tmp/ Directory.

So how edit crontab:
In terminal type the following command
$crontab -e

Now the crontab file will opens in your default terminal editor(Mostly vi or vim). Now just add the Example 1 at the bottom of the file then save and exit.
Now open the /tmp/every_minute.txt file you can see it is updated each minute with the output of the date command.

For more information about cron, crontab
$man cron

$man 5 crontab


Location of files related to Cron :
Files in /var/spool/cron, /var/spool/anacron
Files in /etc/cron* ex. /etc/cront.d/, /etc/cront.weekly/
File /etc/crontab


Details Based on:
BOSS GNU/Linux (And most of the debian derived linux)

Tuesday, January 18, 2011

how to find the pattern within files?

Using grep we achieve this..
Say we have to find out the word "gdk" from all the '.c' files in a directory.. the command would be

$grep -i "pattern" files

ex: $grep -i "gtk" *.c          <===== Will search all .c files in the current directory.
ex: $grep -i "gtk" file1, file.23, file <== Will search only in the specified files.

Tuesday, January 11, 2011

How to fetch n number of lines before or after a pattern match..

Lets assume there is a file which has 1000 lines. Now i want to see 20 lines from the a pattern (say pattern is 'top secret'). How come..?

Step 1: open the file in command prompt using 'cat' command with -n option(this option shows the content of the file with the line numbers).

Ex: $cat -n ./secrets.txt

step 2: piping the output of the 'step 1' to grep command with -i option(this ignores the case of given pattern i.e case insensitive) and pattern.

Ex: $cat -n ./secrets.txt | grep -i 'top secret'

step 3: now your output gives a line number(say 654) with the give pattern match, so, now using the head & tail commands with the line numbers we get the required output.

Ex: $head -654 | tail -10

Thats all.. :)