Wednesday, January 8, 2014

How to Delete all files in directory except the ones that start with the letter ?

Delete all files in directory except the ones that start with the letter

In Unix, to delete all the files in a directory except the ones that start with the letter "a", do the following:

rm [!a]*

But let's say there are many files, and you want to delete everything except a file called "my_file". Use grep's inverse matching capability here:

rm $(ls * | grep -v my_file)

Of course if there are other files with "my_file" as part of their filename, then those won't be deleted either. The following will ensure that this doesn't happen:

rm $(ls * | grep -v '^my_file$')

How to Change MAC address in Linux Ubuntu Redhat Fedora ?

How to Change MAC address in Linux Ubuntu Redhat Fedora

If you wish to change your MAC address in Linux, all you have to do is bring the interface down then use the hw ether switch:

ifconfig eth0 down
ifconfig eth0 hw ether 02:01:02:03:04:08
ifconfig eth0 up
if you want your pc to change its MAC address on boot add that to a script in /etc/init.d/ folder, and also add symbolic link(ln) to /etc/rc2.d, /etc/rc3.d, /etc/rc4.d, /etc/rc5.d which refers to the script in /init.d/

---------------------------

#!/bin/bash

ifconfig eth0 down
ifconfig eth0 hw ether 02:01:02:03:04:08
ifconfig eth0 up
/etc/init.d/networking restart

How to find ram processor type linux ?

How to find ram processor type linux
How to find ram processor bios cache connector slot system board type linux

     # man dmidecode
     # dmidecode -t memory
     # dmidecode -t processor
     # dmidecode -t bios
     # dmidecode -t cache
     # dmidecode -t system
     # dmidecode -t connector <---------
     # dmidecode -t slot <---------
     # dmidecode -t baseboard
     # dmidecode -s processor-version

How To Protect Linux files accidental deletion ?

Protect Linux files accidental deletion

You can protect your most important files from accidental deletion by giving them a “sticky bit” attribute:

#chmod +t filename

#chattr +i filename

How to locate command across external devices in Linux ?

How to locate command across external devices in Linux


By default, updatedb indexes only your root partition when run. To be able to extend locate’s reach and get updatedb to index external devices such as USB harddisks and flash drives, edit the /etc/updatedb.conf file. Modify the following line:

PRUNEPATHS=”/tmp /var/spool /media”

so that it reads

PRUNEPATHS=”/tmp /var/spool”
This adds the devices mounted in the /media directory to the search path

How to Find active IPs Linux LAN ?

HOWTO Find active IPs Linux LAN

#for ip in $(seq 1 254); do
ping -c1 -w1 192.168.1.$ip>/dev/null && echo “192.168.1.$ip is UP”
done

This will ping each computer on the 192.168.1.x subnet one time, with a one second interval between pings. The output should be something like
192.168.1.1 UP
192.168.1.17 UP
192.168.1.24 UP

------------------ OR

      # netdiscover -r 192.168.0.0/24
      # fping -g 192.168.1.0/24
      # nmap -sP -n $ip
           (replace eth0 with your NIC):
     # sudo arp-scan -I eth0 -l