You can run the command below to get the pid of last(latest) started job(process) on Linux.
echo $$
Output:
4852
You can run the command below to get the pid of last(latest) started job(process) on Linux.
echo $$
Output:
4852
Use sed command to delete a string or pattern of string in linux.
echo "parrot-bird" | sed 's/-.*$//'
Output:
parrot
Above command will delete anything after the pattern "-".
Shellshock is a recent bash vulnerability.It affects all systems which are bash based.
To check if your system is affected by shellshcock, run this code.
env x='() { :;}; echo vulnerable' bash -c 'echo this is a test'
if you see “vulnerable” as output, then your system is vulnerable.
This bug was detected about a month ago and patches are available here.
In order to stream video or audio through rtsp/rtp/udp, live555 media server can be used.
Download the server from the location below.
http://www.live555.com/mediaServer/#downloading
Run the server from the location where your audio or video files are and the media server will stream the file over rtsp
./live555MediaServer
LIVE555 Media Server
version 0.84 (LIVE555 Streaming Media library version 2014.09.11).
Play streams from this server using the URL
rtsp://ip-address/video-filename.mpg
Now you can play the stream in vlc player by going to “media->Open Network Stream” .Paste the link “rtsp://ip-address/video-filename.mpg” in the box and press play.
In Linux systems you can check and modify MTU(Maximum transmission unit) of TCP/IP over ethernet.
Command to show MTU:
ip link list
Output:
1: lo: mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 18:03:73:bf:a3:11 brd ff:ff:ff:ff:ff:ff
4: eth1: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:60:6e:00:f1:7d brd ff:ff:ff:ff:ff:ff
Modify MTU of eth0 with command below
ip link set dev eth0 mtu 1000
Set MTU permanently in Debian or UBuntu Linux
/etc/network/interfaces
Set MTU permanently in rpm based Linux
/etc/sysconfig/network-scripts/ifcfg-eth0
NOTE: you can also get or set MTU values with ifconfig command.
When you try to run vlcplayer as root you might encounter below message.
VLC is not supposed to be run as root. Sorry.
If you need to use real-time priorities and/or privileged TCP ports
you can use vlc-wrapper (make sure it is Set-UID root and
cannot be run by non-trusted users first).
By using the trick below you should be able to run vlcplayer as root.(This was tested in Ubuntu 12.04.4 LTS)
sed -i 's/geteuid/getppid/g' /usr/bin/vlc
Now you should be able to run vlc with root.
Iprout2 can be used to access two different networks in parallel from a Linux machine.If you have a Linux machine with interfaces eth0 and eth1, and you want to access internet through eth0 and use eth1 to access restricted resources.you can configure iproute2 to achieve this.
Consider eth0 and eth1 has below ip addresses and subnets.
eth0(internet)
ip:172.16.0.188
netmask:255.255.0.0
gateway: 172.16.0.4
eth1(private)
ip: 10.105.12.8
netmask: 255.255.255.192
gateway: 10.105.12.62
Now add the script below in your bashrc file to make it permanent after reboot.
-------------------START-------------------
#Verify if a rule is already present and create with name 100 if not present
ip rule show | grep -i 100 > /dev/null
if test "$?" -ne "0";then
ip route add 10.105.12.0/26 dev eth1 src 10.105.12.8 table 100
ip route add default via 10.105.12.62 dev eth1 table 100
ip rule add from 10.105.12.8/32 table 100
ip rule add to 10.105.12.8/32 table 100
fi
#Configure/add individual routes if needed
route -n | grep -w "10.105.12.62" > /dev/null
if test "$?" -ne "0"; then
route add -net 10.103.20.0/24 gw 10.105.12.62
route add -net 10.103.20.0/24 gw 10.105.12.62
fi
-------------------END-------------------
Print numbers(for example 1 to 10) in bash.
for i in {1..10};do echo "$i"; done
Output:
1
2
3
4
5
6
7
8
9
10
If you have a file with single column and you want to convert it in a single row, you can use the below shell command .
Suppose you have text file(hw.txt) with following column.
cdrom
cpu
disk
ide
memory
netcard
partition
printer
scanner
scsi
gfxcard
sound
usb
wlan
bluetooth
monitor
Entries above can be aligned horizontally by executing the command below.
for i in `< hw.txt`; do echo -n ${i}" ";done; echo ""
It will output
cdrom cpu disk ide memory netcard partition printer scanner scsi gfxcard sound usb wlan bluetooth monitor
NOTE: "echo -n" does the trick.
Command below will display ubuntu version.
lsb_release -a
Your OS version will be displayed on description option.
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.4 LTS
Release: 12.04
Codename: precise