BASH

In a terminal example anything shown in bold after Terminal:~$ is a comment and is not to be run, e.g:

Terminal:~$ sudo apt-get install fish Then scratch your ear

So in the above Then scratch your ear is not to be run in the terminal

BASH Time and Date

BASH IP Tables

BASH File Formats

BASH History

HOWTO: Download Web Page And All Files Linked
$ wget -r -np -k http://syncapp.bittorrent.com/1.4.111/

HOWTO: Pattern Match Between 2 Lines
I Love Linux ***** BEGIN ***** BASH is awesome BASH is awesome ***** END ***** I Love Linux

sed -n '/BEGIN/,/END/p'

Thanks - http://www.shellhacks.com/en/Using-SED-and-AWK-to-Print-Lines-Between-Two-Patterns

HOWTO: Run and Disown A Terminal Process
In this example we will use Synaptic as our example programme.

Terminal:~$ sudo synaptic& or sudo synaptic & Output [1] 4711

Thanks Urban Penguin

HOWTO: Disown An Already Running Terminal Process
In this example Synaptic will be the already running process.

Terminal:~$ Press CTRL+Z bg Output [1]+ sudo synaptic & disown

You should now be able to close the terminal without Synaptic closing.

Thanks Urban Penguin

HOWTO: Take Ownership Of A Disowned Terminal Process
Terminal:~$ fg 1 Were 1 is the number of the job running in the background

Thanks Urban Penguin

HOWTO: Trim Leading White Space
sed 's/^ *//g'

e.g.

lynx -nolist -dump http://wiki.indie-it.com/wiki/Television_Paully |sed -n '/What I Am Currently Watching/,/What I Have Been Watching/p' |sed 's/^ *//g' |egrep '^[0-9]'

Thanks - http://stackoverflow.com/questions/9309882/delete-whitespace-in-each-begin-of-line-of-file-using-bash

HOWTO: Show Web Page Headers
Terminal:~$ curl -I www.bbc.co.uk

Sample output...

HTTP/1.1 200 OK Server: Apache Content-Type: text/html Content-Language: en-GB Etag: "4c572592f520bedc9a1e2c0238accaa6" X-PAL-Host: pal041.back.live.cwwtf.local:80 Transfer-Encoding: chunked Date: Fri, 06 Mar 2015 11:30:51 GMT Connection: keep-alive Set-Cookie: BBC-UID=15d4ff99887f5eab78a60516b12f651317b26b71e7f4e4a61ad0970254e467200curl/7.35.0; expires=Tue, 05-Mar-19 11:30:51 GMT; path=/; domain=.bbc.co.uk X-Cache-Action: HIT X-Cache-Hits: 1149 X-Cache-Age: 64 Cache-Control: private, max-age=0, must-revalidate Vary: X-CDN

Thanks - http://www.cyberciti.biz/tips/howto-watch-http-headers.html

HOWTO: Restore Tar Backup Over SSH
On the target filesystem, switch to root, change to the directory you want to extract to, then ssh in to the source server and cat to tar...

su - root cd / ssh root@192.168.1.201 "cat /backup/wwwdata.tar.gz" | tar zxvf -

Thanks - http://www.cyberciti.biz/faq/howto-use-tar-command-through-network-over-ssh-session/

BASH SHELLSHOCK REMOTE CODE EXECUTION VULNERABILITY CVE-2014-6271
Introduction

http://www.ubuntu.com/usn/usn-2362-1/

A bug discovered in the widely used Bash command interpreter poses a critical security risk to Unix and Linux systems – and, thanks to their ubiquity, the internet at large.

It lands countless websites, servers, PCs, OS X Macs, various home routers, and more, in danger of hijacking by hackers.

The vulnerability is present in Bash up to and including version 4.3, and was discovered by Stephane Chazelas. It puts Apache web servers, in particular, at risk of compromise: CGI scripts that use or invoke Bash in any way – including any child processes spawned by the scripts – are vulnerable to remote-code injection. OpenSSH and some DHCP clients are also affected on machines that use Bash.

Ubuntu and other Debian-derived systems that use Dash exclusively are not at risk – Dash isn't vulnerable, but busted versions of Bash may well be present on the systems anyway. It's essential you check the shell interpreters you're using, and any Bash packages you have installed, and patch if necessary.

The Security Patch for CVE-2014-7169 has been released as a standard security update. There is no need to add additional ppa's to receive this patch. Only the following is needed.

To ensure you have patched bash correctly, run the following command...

dpkg -s bash | grep Version

If you are on Ubuntu 14.04 LTS, you should see an output of:

Version: 4.3-7ubuntu1.4

If you are on Ubuntu 12.04 LTS, your output should be:

Version: 4.2-2ubuntu2.3

If you are on Ubuntu 10.04 LTS, your output should be:

Version: 4.1-2ubuntu3.1

If you are on Raspbian GNU/Linux 7 (wheezy), your output should be:

Version: 4.2+dfsg-0.1+deb7u3

Instructions

Centos
sudo yum update env x=' { :;}; echo vulnerable' bash -c 'echo completed' bash --version

Red Hat
sudo yum update env x=' { :;}; echo vulnerable' bash -c 'echo completed' bash --version

Debian
sudo apt-get update sudo apt-get install --only-upgrade bash env x=' { :;}; echo vulnerable' bash -c 'echo completed' bash --version

Raspian (Raspberry Pi)
sudo apt-get update sudo apt-get install --only-upgrade bash env x=' { :;}; echo vulnerable' bash -c 'echo completed' bash --version

Ubuntu
sudo apt-get update sudo apt-get install --only-upgrade bash env x=' { :;}; echo vulnerable' bash -c 'echo completed' bash --version dpkg -s bash | grep Version

Ubuntu 10.10 11.04 12.10 13.04 13.10

USE THIS AT YOUR OWN RISK. IT WORKS BUT YOU SHOULD REALLY UPGRADE YOUR DISTRO!!!

Also, I found that you had to find the .deb file and install it again, because it would display errors and get confused about versions and not fully finish the update...

dpkg -s bash | grep Version Version: 4.3-7ubuntu1.4 Config-Version: 4.2-5ubuntu3

So, we find the .deb file and run the debian installer again...

sudo dpkg -i /var/cache/apt/archives/bash_4.3-7ubuntu1.4_amd64.deb (Reading database ... 131036 files and directories currently installed.) Preparing to replace bash 4.3-7ubuntu1.4 (using .../bash_4.3-7ubuntu1.4_amd64.deb) ... Unpacking replacement bash ... Setting up bash (4.3-7ubuntu1.4) ... update-alternatives: using /usr/share/man/man7/bash-builtins.7.gz to provide /usr/share/man/man7/builtins.7.gz (builtins.7.gz) in auto mode Processing triggers for install-info ...

...and now we get no errors...

dpkg -s bash | grep Version Version: 4.3-7ubuntu1.4

OK? Now read on...

LATEST: 2014-09-28

I have successfully downloaded and installed JUST the .deb file without having to edit the sources list from the ORIGINAL LINK below.

Here is the procedure with my notes...

1. Check to see what architecture your system is using (either amd64 or i686)...

sudo uname -a

2. Download the currently installed version of BASH as a Debian Package file (.deb) into the directory you are in...

sudo aptitude download bash

3. Download the new version of BASH from the Ubuntu web site (this example is amd64)...

sudo wget https://launchpad.net/~ubuntu-security-proposed/+archive/ubuntu/ppa/+build/6414574/+files/bash_4.3-7ubuntu1.4_amd64.deb

4. Perform a test of installing the new version of BASH using that downloaded file and check for any errors...

sudo dpkg -i --simulate bash_4.3-7ubuntu1.4_amd64.deb

5. If all is well, now install the new version of BASH...

sudo dpkg -i bash_4.3-7ubuntu1.4_amd64.deb

6. Confirm the new version...

sudo dpkg -s bash |grep Version

7. Confirm the vulnerability test passes...

env X=" { :;} ; echo busted" /bin/sh -c "echo completed"

8. Restart all services that use BASH (as needed on your system)...

sudo service ssh restart sudo service apache2 restart sudo service dhcpd restart

9. Breath sigh of relief :)


 * 14.04 (trusty) amd64 - https://launchpad.net/~ubuntu-security-proposed/+archive/ubuntu/ppa/+build/6414574/+files/bash_4.3-7ubuntu1.4_amd64.deb
 * 14.04 (trusty) i386 - https://launchpad.net/~ubuntu-security-proposed/+archive/ubuntu/ppa/+build/6414577/+files/bash_4.3-7ubuntu1.4_i386.deb
 * 14.04 (trusty) all - https://launchpad.net/ubuntu/trusty/+package/bash
 * 12.04 (precise) amd64 - https://launchpad.net/~ubuntu-security-proposed/+archive/ubuntu/ppa/+build/6414580/+files/bash_4.2-2ubuntu2.5_amd64.deb
 * 12.04 (precise) i386 - https://launchpad.net/~ubuntu-security-proposed/+archive/ubuntu/ppa/+build/6414583/+files/bash_4.2-2ubuntu2.5_i386.deb
 * 12.04 (precise) all - https://launchpad.net/ubuntu/precise/+package/bash

ORIGINAL LINK

http://cloudgames.com/blog/fix-bash-exploit-old-new-releases-ubuntu-apt-get/

Gentoo
su - root

All Bash 3.1 users should upgrade to the latest version:

emerge --sync emerge --ask --oneshot --verbose ">=app-shells/bash-3.1_p18" env x=' { :;}; echo vulnerable' bash -c 'echo completed' bash --version All Bash 3.2 users should upgrade to the latest version:

emerge --sync emerge --ask --oneshot --verbose ">=app-shells/bash-3.2_p52" env x=' { :;}; echo vulnerable' bash -c 'echo completed' bash --version

All Bash 4.0 users should upgrade to the latest version:

emerge --sync emerge --ask --oneshot --verbose ">=app-shells/bash-4.0_p39" env x=' { :;}; echo vulnerable' bash -c 'echo completed' bash --version All Bash 4.1 users should upgrade to the latest version:

emerge --sync emerge --ask --oneshot --verbose ">=app-shells/bash-4.1_p12" env x=' { :;}; echo vulnerable' bash -c 'echo completed' bash --version All Bash 4.2 users should upgrade to the latest version:

emerge --sync emerge --ask --oneshot --verbose ">=app-shells/bash-4.2_p48" env x=' { :;}; echo vulnerable' bash -c 'echo completed' bash --version

HOWEVER, IF YOUR GENTOO PORTAGE TREE IS VERY OLD, OR YOU DO NOT WANT TO UPDATE ALL YOUR SOFTWARE

su - root mkdir -p /usr/local/portage/app-shells/bash cd /usr/local/portage/app-shells/bash wget -O bash-4.2_p48-r1.ebuild http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-shells/bash/bash-4.2_p48-r1.ebuild?revision=1.4 cp -avrf /usr/portage/app-shells/bash/files. cd files/ wget http://mirrors.163.com/gentoo-portage/app-shells/bash/files/bash-4.2-execute-job-control.patch wget http://mirrors.163.com/gentoo-portage/app-shells/bash/files/bash-4.2-parallel-build.patch wget http://mirrors.163.com/gentoo-portage/app-shells/bash/files/bash-4.2-no-readline.patch wget http://mirrors.163.com/gentoo-portage/app-shells/bash/files/bash-4.2-read-retry.patch wget http://mirrors.163.com/gentoo-portage/app-shells/bash/files/bash-4.2-speed-up-read-N.patch wget http://mirrors.163.com/gentoo-portage/app-shells/bash/files/bash-eol-pushback.patch chown portage:portage bash* eix-update cd .. ebuild bash-4.2_p48-r1.ebuild digest emerge --fetchonly --verbose --update app-shells/bash eix -I bash emerge --ask --oneshot --verbose --update app-shells/bash eix -I bash env x=' { :;}; echo vulnerable' bash -c 'echo completed' bash --version

And, if necessary restart the services which may use BASH...

/etc/init.d/sshd restart /etc/init.d/apache2 restart /etc/init.d/dhcpd restart

Links
http://www.theregister.co.uk/2014/09/24/bash_shell_vuln/

https://forums.gentoo.org/viewtopic-t-1000670.html

http://packages.gentoo.org/package/app-shells/bash

HOWTO: Test Existence Of Directory
test -d /path/to/directory

You can use this to make sure a directory exists before copying or moving a file into it.

test -d /mnt/usb/backup && mv /home/website/backup-20140901.zip /mnt/usb/backup/

HOWTO: Dump HTTP Header Using WGET
wget --server-response --spider http://www.google.co.uk

HOWTO: Extract Without First Directory
tar -xzvpf filename.tar.gz --strip-components=1 -C /path/to/extract/to/

e.g. the Magento tarball has the folder /magento/ in it, so we remove that with...

tar -xjvpf magento-1.9.0.1.tar.bz2 --strip-components=1 -C /home/website/public_html/

HOWTO: Remove Blank Lines From A Text File
sed -i '/^$/d' file.txt

HOWTO: Sort Linux Password File By User ID (UID)
sudo sort -t : -k 3 -g /etc/passwd

-t = separator -k = column

HOWTO: Get Memcached Stats By Using Netcat
echo stats | nc 127.0.0.1 11211

HOWTO: Kick Users Off The System
Sometimes, you forget to log out from the system. To remove your old login, connect via SSH, find out the PID, then kill it.

The actual system login (via a keyboard attached) is always ttyX.

who -u plittlefield  tty2         2014-04-29 15:40  old         3333 root          pts/2        2014-06-02 10:45. 8336 kill -9 3333

HOWTO: FIX: Invalid Strange Characters In Output Of A Cron Job
Add the following to your crontab file, or the file /etc/environment...

LANG=en_GB.UTF-8

Thanks to LogikDevelopment

HOWTO: Force Filesystem Check On Reboot
sudo touch /forcefsck sudo reboot

ALIASES
Open a terminal and edit the .bashrc file:

Linux Terminal:~$ nano ~/.bashrc

Edit or add the following lines:

alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias get='get_iplayer/get_iplayer' alias grep='grep --color=auto' alias hg='history |grep' alias install='sudo apt-get install' alias l='ls -CF' alias la='ls -A' alias ll='ls -lah' alias ls='ls --color=auto' alias myip='curl ifconfig.me' alias ping='ping -c3 -n -i 0.2 -W1' alias pingg='ping www.google.co.uk' alias pingp='ping www.paully.co.uk' alias pingm='ping 10.0.0.1' alias pings='ping 192.168.0.1' alias rav='rsync -a -v' alias remove='sudo apt-get autoremove' alias rm='rm -iv' alias search='sudo apt-cache search' alias ss='gksudo software-properties-gtk' alias sshg='ssh username@server1.indie-it.com' alias update='sudo apt-get update' alias upgrade='sudo apt-get upgrade' alias uu='sudo apt-get update && sudo apt-get upgrade' alias uuf='sudo apt-get update && sudo apt-get dist-upgrade'

Reload the file:

Linux Terminal:~$ source ~/.bashrc

To confirm the entries:

Linux Terminal:~$ alias

TITLE OF X TERMINALS
Put the following lines in your ~/.bashrc

nano case $TERM in        xterm*|rxvt*|Eterm)                 PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'                 ;;         screen) PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"' ;; esac
 * 1) Change the window title of X terminals

HOWTO: Mass File Rename Deleting Part Of Name
e.g.

Scooby_Doo_Mystery_Incorporated_S02E25 Through The Curtain 720p x264.mp4 => Scooby_Doo_Mystery_Incorporated_S02E25.mp4

Do...

renamexm -v -s/" .*.mp4"/".mp4"/e *.mp4

HOWTO: Close A Program Remotely (and Nicely!) In Terminal
Yes, you could use pkill or killall, but there is a nicer way.

Log in to your PC via SSH, then...

Install the software...

sudo apt-get install wmctrl

List running apps...

paully@mythbuntu-server3:~$ DISPLAY=:0.0 wmctrl -l 0x01600004 -1 mythbuntu-server3 xfce4-panel 0x01800003 -1 mythbuntu-server3 Desktop 0x01600020 -1 mythbuntu-server3 xfce4-panel 0x01e00004 0 mythbuntu-server3 Terminal - paully@mythbuntu-server3: ~

Close the app...

DISPLAY=:0.0 wmctrl -c "Terminal"

http://manpages.ubuntu.com/manpages/quantal/en/man1/wmctrl.1.html

Change / Add / Delete Default Route Gateway
route del default gw 192.168.0.254 eth0 route add default gw 192.168.0.1 eth0

Print Tabs
awk '{print FNR "\t" $1 "\t" $2}'

Search A Column
awk '/proftpd.*Login successful/{print $7}' secure |sort |uniq -c |sort -nr

HOWTO: Show The Resolution / DPI Of An Image
identify -verbose photo.jpg |grep 'Resolution' Resolution: 72x72

Show which programs you've been running the most in current session
hash | sort -n

Extract A Single Page From One PDF
pdftk ~/path/to/big.pdf cat 1 output /tmp/page1.pdf

Extract All Pages Individually From One PDF
pdftk ~/path/to/big.pdf burst

How To Go To A Specific Line In LESS
Put +LINE_NUMBERg in front of the file you want to view...

less +50g /path/to/file

MAXIMUM AMOUNT OF RAM YOUR MOTHERBOARD WILL SUPPORT
Terminal:~$ sudo dmidecode -t 16 or sudo perl memconf

Thanks to 4Smidts.

DETAILS OF YOUR MOTHERBOARD
Terminal:~$ sudo dmidecode | grep -A4 'Base Board'

The above should return something similar too:

Base Board Information Manufacturer: ASUSTeK Computer INC. 	Product Name: M5A78L-M/USB3 Version: Rev X.0x Serial Number: 130208251600119

Other options include:

bios-vendor bios-version bios-release-date system-manufacturer system-product-name system-version system-serial-number system-uuid baseboard-manufacturer baseboard-product-name baseboard-version baseboard-serial-number baseboard-asset-tag chassis-manufacturer chassis-type chassis-version chassis-serial-number chassis-asset-tag processor-family processor-manufacturer processor-version processor-frequency

HOWTO: Display True Memory Usage
Most people use the free command to show RAM usage, but read it wrong. In the example below, it looks like the computer only has 67 MB available. However, Linux keeps data stored in RAM when reading disks and some more for programs just in case they need it, effectively being greedy for better performance.

What the Linux system is actually using or needs to use is shown on the 3rd line!

free -m total     used     free   shared     buffers     cached Mem:     4049      3982       67        0          16       3530 -/+ buffers/cache:  435     3614 Swap:    6142        53     6088

So, a slightly tweaked command would be...

free -m | awk 'NR==3 {print $4 " MB free."}' 3614 MB free.

(The above command for awk translates to "print 4th column of third line" :-)

Thanks to - http://thoughtsbyclayg.blogspot.co.uk/2008/09/display-free-memory-on-linux-ubuntu.html

Securely forward TCP connections on local port 1234 to remote2 port 4321
ssh -L 1234: http://remote2.example.com :4321 username@remote.example.com

CONSOLE SCREEN BLANKING
Terminal:~$ setterm -blank 0

To make this change permanent, create a file called 'setterm.start' in the /etc/local.d/ folder.

Terminal:~$ cat >/etc/local.d/setterm.start setterm -blank 0 CTRL+d chmod +x /etc/local.d/setterm.start

Download An Entire Web Site
wget --quiet --recursive --no-clobber --page-requisites --html-extension --convert-links --domains domain.co.uk --no-parent http://www.domain.co.uk/

Download Multiple Files / URLs Using Wget -i
First, store all the download files or URLs in a text file as:

cat > download-file-list.txt URL1 URL2 URL3 URL4

Next, give the download-file-list.txt as argument to wget using -i option as shown below.

wget -i download-file-list.txt

USB Scanner / Scanning On The Command Line
Example used is a Canon CanoScan N670U/N676U/LiDE20 flatbed scanner...

lsusb lsusb -d 04a9:220d -v sane-find-scanner scanimage -L scanimage --help -d plustek:libusb:006:004 scanimage -d plustek:libusb:006:004 --resolution 75 --format=tiff >/tmp/output.tiff

Thanks - http://theopoon.rinnovative.com/2012/08/22/canon-canoscan-n670u-on-ubuntu-12-04-server/

Array Looping
ARRAY=( one two three four ) for i in "${ARRAY[@]}" do    echo Showing $i... echo done

Fix SSH: stdin: is not a tty
Put this line at the top of your ~/.bashrc

if [ $(expr index "$-" i) -eq 0 ]; then return fi

Add A Zero To The Beginning Of A Filename
$ renamexm -t -v -s/^/0/r [0-9] *.mp3 rename 1 Subdivisions.mp3  => 01 Subdivisions.mp3  : tested rename 2 The Analog Kid.mp3 => 02 The Analog Kid.mp3 : tested rename 3 Chemistry.mp3     => 03 Chemistry.mp3     : tested rename 4 Digital Man.mp3   => 04 Digital Man.mp3   : tested rename 5 The Weapon.mp3    => 05 The Weapon.mp3    : tested rename 6 New World Man.mp3 => 06 New World Man.mp3 : tested rename 7 Losing It.mp3     => 07 Losing It.mp3     : tested rename 8 Countdown.mp3     => 08 Countdown.mp3     : tested

How To Burn A Directory On To A DVD
sudo apt-get install dvd+rw-tools mkisofs cdrecord mkisofs -r -o /tmp/mydvd.iso /path/to/folder growisofs -Z /dev/dvd=/tmp/mydvd.iso

Monitor The Progress Of dd with Pipe Viewer
dd if=/dev/mmcblk0 | pv -s 4G -peta | gzip -1 > /media/sda1/sd_backup.img.gz

This displays a progress indicator like the following.

0:15:01 [1.57MB/s] [====================>              ] 51% ETA 0:14:06

Progress Of DD Command
Begin dd in 1 terminal window. This will wipe an external USB drive...

dd if=/dev/zero bs=1M of=/dev/sdb

In another terminal window, run this...

watch -n5 'sudo kill -USR1 `pgrep ^dd`'

Now switch back to the first window...

4701814784 bytes (4.7 GB) copied, 197.487 s, 23.8 MB/s 4595+0 records in 4595+0 records out 4818206720 bytes (4.8 GB) copied, 202.506 s, 23.8 MB/s 4706+0 records in 4706+0 records out 4934598656 bytes (4.9 GB) copied, 207.578 s, 23.8 MB/s 4818+0 records in 4818+0 records out 5052039168 bytes (5.1 GB) copied, 212.662 s, 23.8 MB/s 4930+0 records in 4930+0 records out 5169479680 bytes (5.2 GB) copied, 217.737 s, 23.7 MB/s 5040+0 records in 5040+0 records out 5284823040 bytes (5.3 GB) copied, 222.771 s, 23.7 MB/s 5151+0 records in 5151+0 records out 5401214976 bytes (5.4 GB) copied, 227.784 s, 23.7 MB/s

Hide File Inside Image
How to hide files within a picture file (especially png and jpeg files) and all you'll need is a program like WinRAR or RAR.

Firstly you'll need to find two things: the first is a picture that you'll use to hide your file in, the second is the actual file you want to hide.

Put both in the same folder, open a command prompt and navigate there.

Once there you'll need to put your file that you want to hide inside a zip file (rar or zip will work just fine, put a password or whatever if you want too). After this type the following into the command prompt...

Windows

copy /b display.png + secret_message.rar fake.png

Linux

cat display.png secret_message.rar > fake.png

...where display.png is the picture in which you want to hide the file, secret_message.rar is the file you want to hide and fake.png is the file name that you want the result to be created as.

After this is done open the newly created image file in your paint package and verify that it opens correctly. To see the hidden file all you need to do is open it in your favorite compression program and your done! One hidden file that can be uploaded to image sites and so forth.

You can also put a password on the rar hidden rar file in order to add extra protection.

Find And Copy Files With Directory Structure
find /path/to/search/ -type f -name '*.mov' -print -exec cp --parents "{}" /path/to/copy/to/ \;

Change User Password One Liner Batch Mode
echo "username:password" | chpasswd

Beautify A Shell Script
http://www.arachnoid.com/linux/beautify_bash/

Convert Tabs To Spaces In a File
expand file.txt

BLINK LIGHTS ON NETWORK CARD
Terminal:~$ ethtool -p eth0 10

This will blink the lights for 10 seconds. However if you get this message...

Cannot identify NIC: Operation not supported

...you are out of luck because it only works with some chipsets and drivers:-

"-p initiates adapter-specific action intended to enable an operator to easily identify the adapter by sight. Typically this involves blinking one or more LEDs on the specific ethernet port."

ewrk3 s2io sky2 tg3 e100 pcnet32 bnx2 skge e1000 sk98lin ixgb

http://magazine.redhat.com/2007/09/05/tip-from-an-rhce-which-interface-is-eth0/

http://www.linuxjournal.com/content/fun-ethtool

http://linuxtoolkit.blogspot.co.uk/2012/02/using-ethtool-to-manage-ethernet-card.html

DETECT IP ADDRESS CONFLICTS
Install the relevant software, for Debian/Ubuntu:

Terminal:~$ sudo apt-get install arp-scan

For CentOS, Fedora or Redhat:

Terminal:~$ sudo yum install arp-scan

Once installed to use:

Terminal:~$ sudo arp-scan -I eth0 -l

This should return something similar to: Terminal:~$ Interface: eth0, datalink type: EN10MB (Ethernet) Starting arp-scan 1.8.1 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/) 192.168.0.1	1c:c1:de:1c:74:8f	Hewlett Packard 192.168.0.21	00:1b:a9:8a:52:d2	BROTHER INDUSTRIES, LTD. 192.168.0.41	f4:ec:38:a8:d0:de	TP-LINK TECHNOLOGIES CO., LTD. 192.168.0.52	00:1d:fe:df:2c:53	Palm, Inc 192.168.0.86	00:1d:fe:e9:1a:ca	Palm, Inc

USE CONNTRACK TO BLOCK AN IP ADDRESS
conntrack -L -s {IP-ADDRESS} conntrack -D -s {IP-ADDRESS}

Upload File By FTP Command Line
ftp -u ftp://username:password@www.domain.co.uk/remote/dir/file.txt file.txt

Speed Ping
alias ping='ping -c3 -n -i 0.2 -W1' alias pingg='ping www.google.co.uk' alias pingp='ping www.paully.co.uk'

Dictionary Attack On SSH
Oct 16 08:53:30 server2 sshd[23415]: Invalid user amcssa from 88.191.133.21 Oct 16 08:53:32 server2 sshd[23417]: Invalid user wupr from 88.191.133.21 Oct 16 08:53:34 server2 sshd[23419]: Invalid user glbt from 88.191.133.21 Oct 16 08:53:36 server2 sshd[23421]: Invalid user wusgg from 88.191.133.21 Oct 16 08:53:38 server2 sshd[23423]: Invalid user wundergr from 88.191.133.21 Oct 16 08:53:40 server2 sshd[23425]: Invalid user sos from 88.191.133.21 Oct 16 08:53:42 server2 sshd[23427]: Invalid user s0s from 88.191.133.21 Oct 16 08:53:44 server2 sshd[23429]: Invalid user sos1 from 88.191.133.21 Oct 16 08:53:46 server2 sshd[23431]: Invalid user overflow from 88.191.133.21 Oct 16 08:53:48 server2 sshd[23433]: Invalid user mariachi from 88.191.133.21 Oct 16 08:53:50 server2 sshd[23435]: Invalid user fsae from 88.191.133.21 Oct 16 08:53:52 server2 sshd[23437]: Invalid user wuma from 88.191.133.21 Oct 16 08:53:54 server2 sshd[23439]: Invalid user vsa from 88.191.133.21 Oct 16 08:53:56 server2 sshd[23441]: Invalid user pride from 88.191.133.21 Oct 16 08:53:57 server2 sshd[23443]: Invalid user yarn from 88.191.133.21 Oct 16 08:54:00 server2 sshd[23445]: Invalid user mixed from 88.191.133.21 Oct 16 08:54:02 server2 sshd[23447]: Invalid user mix3d from 88.191.133.21 Oct 16 08:54:03 server2 sshd[23449]: Invalid user washucrs from 88.191.133.21 Oct 16 08:54:05 server2 sshd[23451]: Invalid user kungfu from 88.191.133.21 Oct 16 08:54:07 server2 sshd[23453]: Invalid user lnyf from 88.191.133.21

Use Shorewall To Block An IP Address
shorewall drop {IP-ADDRESS}

Use Shorewall To Allow An IP Address
shorewall allow {IP-ADDRESS}

How To Quickly Generate A Large File On The Command Line
To make a 1Mb file...

dd if=/dev/zero of=1mb_file count=1024 bs=1024

http://www.skorks.com/2010/03/how-to-quickly-generate-a-large-file-on-the-command-line-with-linux/

HOWTO Split An MP3 File For Burning Multiple Tracks To A CD
Use the mp3splt command line tool. The example below makes 6 minute long tracks and automatically adjusts the spilt to occur during moments of silence.

mp3splt podcast.mp3 -g %[@N=0,@o] -o "@n_@f" -t 6.0 -a

http://wiki.librivox.org/index.php/How_To_Split_With_Mp3Splt

Now you can use the method below to convert all the MP3 files to WAV files, and then burn them to a CD.

HOWTO Burn MP3 On To An Audio CD
First, you need to convert your MP3 (myfile.mp3) into a WAV (myfile.wav) file. You use the mpg123 command line tool for this. Make sure it is stereo. mpg123 --stereo --wav myfile.wav myfile.mp3

Or, for multiple files. for file in *.mp3; do mpg123 --stereo --wav "${file}".wav "$file"; done

Find your CD Burner cdrecord -scanbus

Then burn your WAV file on to the CD cdrecord dev=2,0,0 speed=4 -pad -audio myfile.wav

Or, burn all your WAV files on to the CD (just make sure they are numbered sequentially) cdrecord dev=2,0,0 speed=4 -pad -audio *.wav

Troubleshooting: If you receive this error, then use the --stereo switch shown above to convert it from mono. Inappropriate audio coding in 'myfile.wav'.

http://www.cyberciti.biz/tips/how-do-i-burn-mp3-onto-an-audio-cd-from-command-prompt.html

Play MP3 Files Over SSH Connection
That will play all mp3 files in the folder /home/user/music/artist on the server, and the sound will be on the client’s speakers.

ssh user@server "cat /home/user/music/artist/*.mp3" | mpg123 -

Play MP3 Files On Server Over SSH Connection
ssh user@server screen mpg123 -C /home/user/music/artist/*.mp3 CTRL+A D (to detach from running screen session)

Show Size Of Directories
Sorted by time...

du --time -s */ |sort -k 2

Sorted by size..

du --time -s */ |sort -k 1 -h

Calculator
echo $[1+1]

or

scale=2; echo "11.45 + 7.95" | bc

Foreach Loop In Script
for i in 1 2 3 do  /usr/bin/nmap -sP -n "192.168.0.$i" |grep 'IP' done
 * 1) !/bin/bash

Extract A Single File From A Tarball Archive
cd /tmp/ tar -xjvpf /path/to/stage4.tar.bz2 etc/conf.d/modules

Create Cool SHA Code From Date (Forum Spam Bot Prevention)
date -u +%jXfce|sha256sum|sed 's/\W//g'

Remove Blank Lines From Text File
cat myfile.txt |sed '/^$/d'

Delete Characters On Just The First Line
This deletes all the quotation (") characters on just the first line of a CSV file...

sed '1s/"//g' /tmp/oldfile.csv > /tmp/newfile.csv

http://sed.sourceforge.net/sed1line.txt

Format A USB Flash Drive With Linux Filesystem
Identify your drive:

cat /proc/partitions dmesg |tail

Repartition drive:

fdisk /dev/sdb d n p 1 [enter] [enter] w

Format drive:

mkfs.ext3 -L "BACKUP-32GB-B" -v /dev/sdb1

Output examples:

thinkpad ~ # dmesg |tail sd 10:0:0:0: [sdb] Assuming drive cache: write through sd 10:0:0:0: [sdb] No Caching mode page present sd 10:0:0:0: [sdb] Assuming drive cache: write through sdb: sdb1 sd 10:0:0:0: [sdb] No Caching mode page present sd 10:0:0:0: [sdb] Assuming drive cache: write through sd 10:0:0:0: [sdb] Attached SCSI removable disk thinkpad ~ # cat /proc/partitions major minor #blocks  name 8       0  312571224 sda 8       1    1228800 sda1 8       2   83103744 sda2 8       3  114118656 sda3 8       4  114109695 sda4 8      16   31696896 sdb thinkpad ~ # fdisk /dev/sdb Command (m for help): p Disk /dev/sdb: 32.5 GB, 32457621504 bytes 64 heads, 32 sectors/track, 30954 cylinders, total 63393792 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xc3072e18 Device Boot     Start         End      Blocks   Id  System Command (m for help): n Partition type: p  primary (0 primary, 0 extended, 4 free) e  extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-63393791, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-63393791, default 63393791): Using default value 63393791 Command (m for help): p Disk /dev/sdb: 32.5 GB, 32457621504 bytes 64 heads, 32 sectors/track, 30954 cylinders, total 63393792 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xc3072e18 Device Boot     Start         End      Blocks   Id  System /dev/sdb1           2048    63393791    31695872   83  Linux Command (m for help): w The partition table has been altered! Calling ioctl to re-read partition table. Syncing disks. thinkpad ~ # mkfs.ext3 -L "BACKUP-32GB-B" -v /dev/sdb1 mke2fs 1.42 (29-Nov-2011) fs_types for mke2fs.conf resolution: 'ext3' Filesystem label=BACKUP-32GB-B OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1982464 inodes, 7923968 blocks 396198 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 242 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done thinkpad ~ # umount /media/BACKUP-32GB-B/ thinkpad ~ # fsck.ext3 -v -C0 /dev/sdb1 e2fsck 1.42 (29-Nov-2011) BACKUP-32GB-B: clean, 11/1982464 files, 168470/7923968 blocks

Shell Command Line Calculator
echo 'scale=25;57/43' | bc

http://www.basicallytech.com/blog/index.php?/archives/23-command-line-calculations-using-bc.html

What Desktop Session Am I Using?
echo $DESKTOP_SESSION

Date Yesterday
date -d "1 day ago" '+%Y-%m-%d'

Last X Command Used
Find the last time you used tar...

!tar:p

Run that same command again...

!tar

Thanks to CLIMagic

Files Matching Pattern And Remove File Extension
for FILE in *.conf; do echo "${FILE%%.*}"; done

Largest Directories Or Files
Directories...

du -Sh | sort -rh | head -n 15

Files...

find. -type f -exec du -Sh {} + | sort -rh | head -n 15

Thanks to Xmodulo.com

Find And Tar Files
The + means tar will only be called once...

find. -type f -exec tar -czvf backup.tar.gz '{}' \+;

Working example...

find public_html/app/design/frontend/ public_html/skin/frontend/ -type f -mtime -12 -print -exec tar -czvf paullys_tweaked_files.tar.gz '{}' \+;

Text In Types Of Files
find. -type f -name '*.doc' -exec grep -Hn "text here" {} \;

Find Then Rename / Add Extension To All Files
find. -type f -exec mv '{}' '{}'.jpg \;

Files Owned By A User
find /path/to/search/ -user nobody -print

Zero Length Files
find /path/to/search/ -size 0

e.g.

Find any zero length files named tmp.* older than 1 day and delete them...

find /tmp/ -type f -size 0 -name 'tmp.*' -mtime +1 -exec rm -rf {} \;

Find And Delete
Find any files older than 7 days, then delete them but show what you are deleting.

find /path/to/directory -type f -mtime +7 -exec rm {} \; -print

Find And Copy
Find any text files, then copy them to a different directory.

find. -name "*.txt" -exec cp {} /path/to/directory \;

Find And Move
Find any text files, then move them to a different directory.

find. -name "*.txt" -exec mv {} /path/to/directory \;

Files Newer Than Another File
touch --date "2011-12-31" /tmp/foo touch /tmp/bar find /tmp/ -type f -newer /tmp/foo

Files Older Than X File
find /path/to/search -type f -name 'fish' \! -newer /path/to/search/in/fish \! -samefile /path/to/search/in/fish |sort

e.g.

find /home/MailScanner/archive-nfs/ -type f -name 'messages' \! -newer /home/MailScanner/archive-nfs/20150327/messages \! -samefile /home/MailScanner/archive-nfs/20150327/messages |sort

Text Files Created In The Last 30 Days
This will find *.txt files...

find ~/Documents/ -type f -mtime -30 -name '*.txt' -print

This will find true ASCII files...

find ~/Documents/ -type f -mtime -30 -print -exec file {} + | grep ASCII

Most Recently Changed Files
find. -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort

Multiple File Types
find /path/to/search/ -type f \( -name "*.epub" -or -name "*.mobi" \) -printf '%f\n' |sort |uniq

Empty Directories / Folders
find. -empty -type d

All Email Forward Files
find /home/ -maxdepth 2 -type f -name '.forward'

Schedule With AT Command
http://www.brunolinux.com/02-The_Terminal/The_at_Command.html

at 8pm

at midnight tonight

at 3pm tomorrow

To view scheduled 'at' jobs:

atq

To delete scheduled 'at' jobs:

atrm 2

Where '2' is the job number found by using the 'atq' command