homehowtokbslinksaboutcontactprojectsmusic

Index > Knowledge Base > Linux/Ubuntu
Contents
Setup RDP for Ubuntu
User Management
CLI Useful Commands
Change terminal colors
Ubuntu netboot Images
Enable/Add partner repo
Get hostname via nslookup
SCP Commands
Zip using tar
Terminal access via web
Remove tab and trailing white spaces from file
Display permissions in numbers
Replace whitespaces in filenames
Go to specific line number via nano

CLI Useful Commands

Lazy unmount
umount -l mountpoint
Install qt
apt-get install libqt4-core libqt4-gui libqt4-dev pkg-config
Install ncurse in ubuntu
sudo apt-get install ncurses-dev
Create symbolic link
ln -s /source /destination
Remove symbolic link
rm /path to symbolic link
Find file(s)
find / "filename" -print
Check OS version
lsb_release -a 
Or
cat /etc/lsb-release
Local backup using rsync:
sudo rsync -azvv /path/to/source /path/to/destination
Remote backup using rsync:
sudo rsync --delete -axvv -e ssh remoteuser@remotehost:/path/to/remote/source /local/folder
An explanation of above options to commands:
--delete deletes files that don't exist on the system being backed up.(Optional)
-a preserves the date and times, and permissions of the files (same as -rlptgoD).
With this option rsync will: Descend recursively into all directories (-r),
copy symlinks as symlinks (-l),
preserve file permissions (-p),
preserve modification times (-t),
preserve groups (-g),
preserve file ownership (-o), and
preserve devices as devices (-D).
-z compresses the data
-vv increases the verbosity of the reporting process
-e specifies remote shell to use
Folder1 and 2 are place holders for the directories to be synchronized. Folder1 is the original folder, and 2 is the new folder, or existing one to be brought in sync with the first. Replace them with the folders you'd like. A / was added after folder1 so that only the contents, rather than whole folder, would be moved into the second folder. Set hardware clock to system clocke
hwclock --systohc
List running process
lsof
Monitor logs in console
tail -f /var/log/syslog
Install light light weight GUI to Ubuntu server
sudo apt-get install xubuntu-desktop
You can go even light excluding desktop addons like Evolution and OpenOffice etc.
sudo apt-get install --no-install-recommends xubuntu-desktop
Reset phpmyadmin session
rm /var/lib/php5/*
Install replace package
sudo apt-get install rpl
Replace val1 with val2
sudo rpl 'val1' 'val2' /temp/test.sh
Fix read only issue when in recovery mode, run the following command to make it writable
mount -o remount,rw /
mount -a
Check dhcp configuration and print out the errors if any
dhcpd -t
Set up static IP address, change addresses according to your setup
iface eth0 inet static
        address 192.168.5.5
        netmask 255.255.255.0
        network 192.168.5.0
        broadcast 192.168.5.255
        gateway 192.168.5.1
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 192.168.5.1
        dns-search testlab.nt
Autologon Ubuntu Desktop
cat << EOT >> /etc/lightdm/lightdm.conf

# Auto login
[SeatDefaults]
greeter-session=unity-greeter
user-session=xfce4-session
autologin-user=rkhan
autologin-user-timeout=0
EOT
Autologon Ubuntu server
cat << EOT >> /etc/init/tty1.conf

#Auto loing
exec /bin/login -f USERNAME < /dev/tty1 > /dev/tty1 2>&1
EOT
Or
echo "exec /bin/login -f USERNAME < /dev/tty1 > /dev/tty1 2>&1" >> /etc/init/tty1.conf
Usefull trafic monitoring tools bmon, slurm, tcptrack, iftop
apt-get install tcptrack
Disable crtl+alt+delete
/etc/init/control-alt-delete.conf
and comment
#exec shutdown -r now "Control-Alt-Delete pressed"
Allow user to reboot system
chmod +s /sbin/reboot

Archive using tar

backup /mybackup direcoty (adjust the directory)
tar -pczvf mybackup.tar.gz /mybackup
backup /mybackup direcoty (adjust the directory) with current time stamp
tar -pczf mybackup-$(date +%m%d%y).tar.gz /mybackup
extract from tar archive
tar -zxvf mybackup.tar.gz
Find the side of file/folder in linux
du -ch file/folder | grep total
Go Up

Ubuntu RDP

install packages
apt-get install xrdp; sudo apt-get install xfce4
setup session
echo "xfce4-session" > ~/.xsession
restart service
service xrdp restart
try it from windows machine, make sure to replace the ipaddress with the ip address of ubuntu machine you are connecting to
mstsc /v:ipaddress
Reference
Go Up

User Management

Add a new user to existing secondary group, create new user rkhan and add him to abc existing group
useradd -G abc rkhan
Setup password for user rkhan
passwd rkhan
Add existing user to multiple group
useradd -G admins,ftp,www,abc rkhan
get the id of rkhan
id rkhan
Add a existing user to existing group
usermod -a -G abc rkhan
change primary group of rkhan to abc
usermod -g abc rkhan
Remove user from group, rkhan from abc group
deluser rkhan abc
Go Up

Change terminal colors

command to set color
setterm -background white -foreground black -store
colors
0 = black
1 = blue
2 = green
3 = cyan
4 = red
5 = purple
6 = brown/yellow
7 = white
http://www.tuxradar.com/answers/482
Go to Top

Ubuntu netboot Image

Ubuntu 18.04 LTS (32 bit)
wget http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-i386/current/images/netboot/ubuntu-installer/i386/initrd.gz
wget http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-i386/current/images/netboot/ubuntu-installer/i386/linux
Ubuntu 18.04 LTS (64 bit)
wget http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/initrd.gz
wget http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/linux
Ubuntu 12.04 LTS (32 bit)
wget http://archive.ubuntu.com/ubuntu/dists/precise-updates/main/installer-i386/current/images/netboot/ubuntu-installer/i386/initrd.gz
wget http://archive.ubuntu.com/ubuntu/dists/precise-updates/main/installer-i386/current/images/netboot/ubuntu-installer/i386/linux
Ubuntu 12.04 LTS (64 bit)
wget http://archive.ubuntu.com/ubuntu/dists/precise-updates/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/initrd.gz
wget http://archive.ubuntu.com/ubuntu/dists/precise-updates/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/linux
Ubuntu 14.04 LTS (32 bit)
wget http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/installer-i386/current/images/netboot/ubuntu-installer/i386/initrd.gz
wget http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/installer-i386/current/images/netboot/ubuntu-installer/i386/linux
Ubuntu 14.04 LTS (64 bit)
wget http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/initrd.gz
wget http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/linux
Ubuntu 16.04 LTS (32 bit)
wget http://archive.ubuntu.com/ubuntu/dists/xenial-updates/main/installer-i386/current/images/netboot/ubuntu-installer/i386/initrd.gz
wget http://archive.ubuntu.com/ubuntu/dists/xenial-updates/main/installer-i386/current/images/netboot/ubuntu-installer/i386/linux
Ubuntu 16.04 LTS (64 bit)
wget http://archive.ubuntu.com/ubuntu/dists/xenial-updates/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/initrd.gz
wget http://archive.ubuntu.com/ubuntu/dists/xenial-updates/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/linux
reference
Go to Top

Enable partner repo

add-apt-repository "deb http://archive.canonical.com/ $(lsb_release -sc) partner"
reference
Go to top

Get hostname via nslookup and set for current session

if=`ls /sys/class/net`
nic=`echo $if | awk '{print $1}'`
ip=`ifconfig $nic | grep 'inet addr' | cut -d ':' -f2 | awk '{print $1}'`
name=`nslookup $ip | awk '{print $4}' | cut -d '.' -f1`
/bin/hostname $name
Go to Top

SCP Commands

Copy the file text.txt from a remote host to the local host (root directory, adjust the directory)
scp username@remotehost:/text.txt /
Copy the file test.txt from the local host to a remote host
scp test.txt username@remotehost.edu:/test.txt
Copy the directory test from the local host to a remote host's root directory (adjust the directory)
scp -r test username@remotehost.edu:/
Copy the file test.txt from remote host host1 to remote host2
scp username@host1:/test.txt \
username@host2:/
Copying the files test.txt and abc.txt from the local host to your home directory on the remote host
scp test.txt abc.txt username@remotehost.edu:~
Copy the file test.txt from the local host to a remote host using port 2264
scp -P 2264 test.txt username@remotehost.edu:/
Copy multiple files from the remote host to your current directory on the local host
scp your_username@remotehost.edu:/some/remote/directory/\{a,b,c\} .
scp your_username@remotehost.edu:~/\{foo.txt,bar.txt\} .
By default scp uses the Triple-DES cipher to encrypt the data being sent. Using the Blowfish cipher has been shown to increase speed. This can be done by using option -c blowfish in the command line.
scp -c blowfish some_file your_username@remotehost.edu:~
It is often suggested that the -C option for compression should also be used to increase speed. The effect of compression, however, will only significantly increase speed if your connection is very slow. Otherwise it may just be adding extra burden to the CPU. An example of using blowfish and compression:
scp -c blowfish -C local_file your_username@remotehost.edu:~
reference
Go to Top

Terminal access via web

install package
sudo apt-cache search shellinabox; apt-get install openssl shellinabox
configure port (optional)
sed -i 's/SHELLINABOX_PORT=4200/SHELLINABOX_PORT=8022/g' /etc/default/shellinabox
sed -i 's/SHELLINABOX_ARGS="--no-beep"/SHELLINABOX_ARGS="--no-beep -s /:SSH:localhost"/g' /etc/default/shellinabox
restart service
sudo invoke-rc.d shellinabox restart
reference 1
reference 2
Go to Top

Remove tab and trailing white spaces from file

remove indented tabs
sed -i 's/^[ \t]*//' advan.cfg
remove trailing white spaces
sed -i 's/[[:space:]]*$//' advan.cfg
ref # 1 ref # 2

Go to Top

Display permissions in numbers

for files
stat -c "%a %n" file
for folder
stat -c "%a %n" folder
reference
Go to Top

Remove whitespaces in filenames

for folders
find -name "* *" -type d | rename 's/ /_/g'    # do the directories first
for files
find -name "* *" -type f | rename 's/ /_/g'
Go to Top

Go to specific line number via nano

nano +107 filename
Go to Top