AWK – By Example

Remove the columns $4 $5 $12 and $13. awk ‘BEGIN{FS=OFS=” “}{$4=$5=$12=$13=””}{print}’ file.txt Break down each line and numbers each field. awk ‘{print NR”: “$0; for(i=1;i<=NF;++i)print “\t”i”: “$i}’ Add list of numbers within a file. awk ‘{total+=$0}END{print total}’ file

Bash / Korn – Change the default session timeout

This short guide will show you how to set the default session timeout. We will set the TMOUT variable, of which is supported by both shells, Bash and Korn. To check your current timeout setting, enter the following, [root@localhost ~]# env | grep TMOUT To change this setting globally edit the /etc/bashrc. To change this … Read more

ffmpeg Commands

FFmpeg allows you to record, convert and stream digital audio and video in various formats. The installation guide can be found here Commands ffmpeg -i [source].flv -vn acodec copy [dest].mp3 Copy the sound of a video to an mp3 ffmpeg -i [source].avi -s 320×240 -b 1000k -vcodec wmv2 -ar 44100 -ab 56000 -ac 2 -y … Read more

Linux – Creating a new Logical Volume / Partition

How do I create a new Logical Volume / Partition ? We will be creating a new logical volume named DATA and mounting this on a new directory called DATA. First of we will create the logical volume, then we will create a file system on the Logical Volume. Once complete we will create a … Read more

Logical Volume Manager

What is LVM ? LVM (Logical Volume Manager) for the Linux Kernel is a method of allocating hard drive space into logical volumes, this also allows for the easy creation, resizing, or removal of new or existing partitions. There are 4 main terms with LVM ….. physical volumes – These are your physical disks, or … Read more

Ubuntu – Configuring an Interface

In order to configure an interface in Ubuntu you will need to edit the following file /etc/network/interfacesBelow is an example, auto [INTERFACE]iface [INTERFACE] inet staticaddress [IP ADDRESS]netmask [NETMASK]network [NETWORK]gateway [GATEWAY]  Once you have made the change to the interfaces file, run the following command /etc/init.d/networking restart

VI shortcuts

General Shortcuts dd delete a line x delete a character a append after cursor A append after line Useful for script editing :![command] allows you to run a command while still in VI :!! repeats previous command :! [command] % allows you to run a command, with % = current file name Motion h Move … Read more

Bourne – Different ways to execute a script

1. The following 2 types of syntax are both ways to execute a script. Using these methods a second shell will be opened and once the script has finished the variables will not persist. chmod +x [script] sh [script] 2. Below shows you a way in which you can run your script using the current … Read more

Bourne – Special Characters

& run command in the background * wildcard ? single wildcard < input redirect > input redirect | pipe outpt to one command from another # remark symbol, ignores characters after  It is best to avoid using these special characters when naming files. To pass these charaters to another program, you will need to prefix … Read more

Linux – How to Mount an ISO image

In order to mount your ISO you will need to add the ISO to your box, create the directory then mount the file, root@host:~$ mkdir /mnt/iso root@host:~$ mount -o loop -t iso9660 MYCD.iso /mnt/iso use the following command to confirm that you have mounted it correctly, root@host:~$ df -kh You should see, Filesystem           Size  Used … Read more

Debian – How to configure an interface as promisc

In order to configure your interface you will need to edit the following file, /etc/network/interfacesBelow is an example of this file, this would set eth0 an IP (172.16.11.1) and eth1 and eth2 to promisc mode. # This file describes the network interfaces available on your system# and how to activate them. For more information, see … Read more

Linux – Setting up VNC Server

Below is a short guide to set up a VNC server within Linux. INSTALL Install the package by running the following commands, Ubuntu/Debian – apt-get install vnc4server xinetd Fedora/Redhat – yum install vnc-server PASSWORD Set the password for vnc by running the command vncpasswd START VNC Start the vnc server by running the command vncserver.You … Read more

Linux – cp: omitting directory error

When trying to use the cp command you receive the error message, cp: omitting directory This can be overcome by using the -r option, cp -r [source file] [destination file]

BASH – Adding coloured text

This will simply print your text in red.  echo -e ‘\E[31mThis prints in red.’; tput sgr0 If you need any further information or want to know how to add bold, underlining, or background colours to your text click here. 

Linux – Unable to send email using Postfix

Below outlines the issue and resoultion when trying to send email using Postfix. Issue When trying to send an email on my linux platform I get the following error message in my mail.log ?? The IP you’re using to send mail is not authorized 550-5.7.1 to send email directly to our servers.      Please use the … Read more

The Ultimate Linux Command Reference Guide

 The Ultimate Linux Command Reference Guide Note: This was produced with Ubuntu. Tip: Theres quite a few in this list so I suggest that if your looking for something spefic use the search function (ctrl+F)…. a2p               – Awk to Perl translatoraconnect          – ALSA sequencer connection manageracpi              – Shows battery status informationacpi_listen       – ACPI event listeneraddr2line         … Read more

Linux – VNC Blank Screen

Edit the/root/.vnc/xstartup file so it reads, xrdb $HOME/.Xresources xsetroot -solid grey x-terminal-emulator -geometry 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” & gnome-session & After doing this kill the vnc processes and restart. Note : You may need to change the last line if you are using KDE.

Linux – Setting a Default Gateway

First of all run the command to enter the default gateway, route add default gw 10.10.10.100 Then to make sure it survives a reboot, edit the file ‘/etc/sysconfig/network‘ and add the line below. Of course changing the IP address to your default gateway – GATEWAY=10.10.10.100

Ubuntu – Cannot install via apt-get

Issue I cannot install via apt-get as I get the message, E: Package ssh has no installation candidate When running apt-get install [package name] you get, root@ubuntu:~$ sudo apt-get install sshReading package lists… DoneBuilding dependency treeReading state information… DonePackage ssh is not available, but is referred to by another package.This may mean that the package … Read more

Debian – Add a Default Gateway

Below should the configuration steps for adding a default gateway to Debian. root@host:~$ route add default gw [ip address]  Note : Remember to add it (to survive a reboot) to your ‘/etc/network/interfaces’.Add the following entry to required interface within the interface file – gateway [ip address] Below is an example : auto eth0iface eth0 inet … Read more

Want to become a Linux expert?

Here is our hand-picked selection of the best courses you can find online:
Linux Mastery course
Linux Administration Bootcamp
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial