Linux
Linux#
- Linux
- Bash Scripting
- UNIX Commands
- mv all files/dir to a subdir
- Get System Informations
- Set deafult shell
- xclip
- ls prefixed commands
- find
- Set hostname
- CPU Info
- CPU Temperature
- IP Related
- ssh
- sftp
- sshfs
- Device connected to the Network
- dd (Disk Dump) commands
- Create a backup
- Restore a backup
- Clone a hard disk
- Transfer a disk image
- Create an iso image of a CD/DVD
- Burn an iso image of a CD/DVD
- Rescue a file that contains bad blocks
- Create your own bootloader
- Create a backup of your MBR
- Restore a backup of your MBR
- Mount dd image of and entire disk
- When the hard disk has errors
- Network Clone
- Network speed test
- Links
- Task Autorun/Automation
- Disk Related
- GRUB
- Problems & Solutions
- Utilities
- Multitouch Gesture
- Raspberry Pi
Bash Scripting#
AWK#
https://www.gnu.org/software/gawk/manual/gawk.html
include/source/import#
https://gist.github.com/toransahu/0a816af786b7d0b98ab1e7079bf0426f
String Comparison#
- use
=
or==
- keep proper square spacing between operators & brackets (most imp)
- use
double quote
for strings and variables - sometime we need to use brackets to access env variables
https://gist.github.com/toransahu/4fd3abc369bb5c8a1ee424af07cb1563
Sub-String Comparison#
1 2 3 |
|
https://gist.github.com/toransahu/f812260a37947a299c5c26adddfa4cfa
If, elif, else, fi#
- Source: https://ryanstutorials.net/bash-scripting-tutorial/bash-if-statements.php
Switch Case#
https://www.shellscript.sh/case.html
UNIX Commands#
mv all files/dir to a subdir#
BASH
- https://askubuntu.com/questions/91740/how-to-move-all-files-in-current-folder-to-subfolder
1 |
|
TODO: zsh
1 2 |
|
Get System Informations#
Set deafult shell#
1 |
|
xclip#
1 |
|
ls prefixed commands#
ls lsA lsblk lscpu lshw lsipc lslogins lsof lspcmcia lss16toppm lsusb
lsa lsattr lsb_release lsdiff lsinitramfs lslocks lsmod lspci lspgpot lss3
find#
1 2 3 |
|
Set hostname#
1. at /etc/hosts#
127.0.1.1 mint-ThinkPad-L440
2. at /etc/hostname#
write mint-ThinkPad-L440
3. then tell the machine#
1 |
|
CPU Info#
1 |
|
CPU Temperature#
1 |
|
1 |
|
1 |
|
1 |
|
IP Related#
- ifconfig
- ip addr
- hostname -I
ssh#
1 |
In case of AWS EC2 SSH#
Connection freezes frequently on inactivity - source https://www.quora.com/Why-does-ssh-to-amazon-ec2-instance-gets-frozen-after-sometime - Solution - sudo vim /etc/ssh/ssh_config - add TCPKeepAlive yes - add ServerAliveInterval 5 where 5 is minute - sudo service sshd restart
sftp#
1 2 3 4 5 6 7 8 |
|
sshfs#
1 2 3 4 |
|
Device connected to the Network#
1 |
|
dd (Disk Dump) commands#
Create a backup#
dd if=/dev/sda of=/opt/backup_sda.img
Restore a backup#
dd if=/opt/backup_sda.img of=/dev/sda
Clone a hard disk#
dd if=/dev/sdb of=/dev/sdc
Transfer a disk image#
dd if=/dev/sdb | ssh root@target "(cat > backup.img)"
Create an iso image of a CD/DVD#
dd if=/dev/cdrom of=cdimage.iso
Burn an iso image of a CD/DVD#
dd if=cdimage.iso of=/dev/cdrom obs=32k seek=0
Rescue a file that contains bad blocks#
dd if=movie.avi of=rescued_movie.avi conv=noerror
Create your own bootloader#
dd conv=notrunc if=bootloader of=qemu.img
Create a backup of your MBR#
dd if=/dev/sdb of=mbr_backup bs=512 count=1
Restore a backup of your MBR#
dd if=mbr_backup of=/dev/sdb bs=512 count=1
Mount dd image of and entire disk#
You must use the start number of the partition.
fdisk -u -l disk_image
1 2 3 4 5 6 7 8 |
|
Then take the start of the partition that you want to edit, 64260
(disk_image2) in this case, and multiply it by 512
Ex: 512 * 64260 = 32901120
mount -o loop,offset=32901120 -t auto /mnt/storage/disk_image /mnt/image_partition_2
When the hard disk has errors#
Get the dd_rescue tool
dd_rescue /dev/sdb /opt/backup_sdb.img
Network Clone#
-
Destination:
nc -l -p 2222 | dd of=/dev/sda bs=16M
-
Source:
dd if=/dev/sda bs=16M | nc Destination 2222
Network speed test#
dd if=/dev/zero bs=1M count=100 | ssh user@machine 'cat > /dev/null'
Links#
-
Symbolic link
ln -s original link
-
Hard Link
ln original link
Task Autorun/Automation#
- src1 : https://developer.toradex.com/knowledge-base/how-to-autorun-application-at-the-start-up-in-linux
Daemons#
Shells#
Graphical#
Cron Jobs#
Intro#
The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, and /etc/cron.*/ directories. It also checks the /var/spool/cron/ directory.
- create cron job
crontab -e
and edit the opened file- add your task (in cron format)
- or, create a new cron job under
/etc/cron.*/
- add your task (in cron format)
Syntax#
1 2 3 4 5 6 |
|
-
to automate tasks based on time like
- on boot: @reboot
- hourly: @hourly or “0 * * * *”
- daily : @daily or @midnight or “0 0 * * *”
- weekly: @weekly or “0 0 * * 0”
- monthly: @monthly or “0 0 1 * *”
-
yearly: @yearly or @annually or “0 0 1 1 *”
-
-
-
-
- command to be executed
-
-
-
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
Operations#
- start:
sudo service cron start
- stop:
sudo service cron stop
- restart:
sudo service cron restart
- status:
sudo service cron status
- list:
crontab -l
orcrontab -u USERNAME -l
- delete all:
crontab -r
orcrontab -u USERNAME -r
Type#
- System Level
- need to define USERNAME
1 2 3 4 5 USERNAME /path/to/command arg1 arg2
- User Level
- by default takes USERNAME of creator
1 2 3 4 5 /path/to/command arg1 arg2
Operators#
- asterisk (*)
- every [minute/hour/day/month/day of week]
- comma (,)
- list of values
- like, on this days: 1,2,3,4,5
- dash (-)
- range
- like, on this days: 1-5
- seperator (/)
- stepper
- like, */2 in hour field means: every 2 hours
misc#
- print names of all valid files:
run-parts --list /etc/cron.d
- print script names which would run, but don't run them:
run-parts --test /etc/cron.d
Services#
.desktop file#
- Works on boot
- put
.desktop file with some script in ~/.config/autostart/
- write script like
1 2 3 4 5 6 7 8 9
[Desktop Entry] Type=Application Exec=sh /home/toran/Applications/linux_tweaks/LowBatterySound/LowBattery.sh X-GNOME-Autostart-enabled=false NoDisplay=false Hidden=false Name[en_IN]=Low Battery Warning Comment[en_IN]=Warning sound on battery less than 15% X-GNOME-Autostart-Delay=20
using /etc/rc.local#
using /etc/init.d#
Disk Related#
fdisk#
- manupulate disk partition table
- list devices:
sudo fdisk -l
lsblk#
- lists block devices
blkid#
- locate/ print block device attributes
df#
- reports filesystem disk space usage
du#
- estimate file space usage
- Summarize disk usage of the set of FILEs, recursively for directories.
GRUB#
Edit grub
configs#
1 |
|
grub
update#
1 |
|
Reboot into other OS#
1 |
|
Problems & Solutions#
Make Anaconda Python Default#
- put following in
.bashrc
or.zshrc
1 2
# added by Anaconda3 installer export PATH="/home/toran/anaconda3/bin:$PATH"
If cinnamon freezes#
- go to
tty0
ortty1
usingAlt
+Ctrl
+F1
orF2
- login
- type
w
andenter
- look under
FROM
column, where row is related tocinnamon session
- note the value for that cell, in my case its
:0
(with colon) - note type
export DISPLAY=:0 cinnamon &
andenter
sudo: unable to resolve host Ray: Connection timed out#
- Two things to check (assuming your machine is called my-machine, you can change this as appropriate):
- That the /etc/hostname file contains just the name of the machine.
- That /etc/hosts has an entry for localhost. It should have something like:
1 2 |
|
nemo context menu "open in terminal" not working#
source: https://forums.linuxmint.com/viewtopic.php?t=204933
1 |
|
Speedup mouse scroll#
Source: https://forums.linuxmint.com/viewtopic.php?t=221526
1 |
|
mousewheel.sh
to adjust the speed.
Utilities#
Multitouch Gesture#
- src: https://github.com/toransahu/libinput-gestures - by bulletmark
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Battery Monitor#
- Source: http://battery-monitor.maateen.me/
Battery Optimization#
SATA Power Management#
-
source: https://askubuntu.com/questions/809127/how-to-turn-off-one-of-sata-hdds-installed-in-the-computer-to-save-power
-
Using hdparm utility.
- It allows you to control your hard drives' power settings, apart from benchmarking and other stuff.
-
put the disk into standby mode
- whenever you access the disk, it should automatically wake up and work back again
1
hdparm -y /dev/sdX
- whenever you access the disk, it should automatically wake up and work back again
-
deeper resting mode
- may need to restart your computer in order to make the HDD work again
1
hdparm -Y /dev/sdX
- may need to restart your computer in order to make the HDD work again
PowerTop by Intel (Recommanded)#
1 2 3 4 |
|
TLP (Emergency)#
- Source: https://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html
1 2 3 4 5 6 |
|
Mono#
Install#
https://www.mono-project.com/download/stable/#download-lin
Verify#
Source: https://www.mono-project.com/docs/getting-started/mono-basics/ Scripts:
Thinkpad Touchpad Middle Button#
Install#
1 |
|
Config#
- restart
- alter touchpad setting and choose
use multiple fingers
in click actions
Finger Print Reader#
- src: https://launchpad.net/~fingerprint/+archive/ubuntu/fingerprint-gui
Installation#
-
First of all, if you have installed Fingerprint GUI manually before, get rid of it completely. Remove all binaries, shared libraries, any other files and undo all the changes you have made to your system config files (especially to files under /etc/pam.d/).
-
Add this PPA to your sources:
1 2
sudo add-apt-repository ppa:fingerprint/fingerprint-gui sudo apt-get update
-
Install the packages:
1
sudo apt-get install libbsapi policykit-1-fingerprint-gui fingerprint-gui
-
Log out of your session and log back in (we need the new session defaults to be picked up).
Uninstallation#
1 2 |
|
ZSH#
1 |
|
oh-my-zsh#
1 2 3 4 5 |
|
VIM#
Vundle#
- VIM plugin manager (VIM + Bundle)
- install from : https://github.com/VundleVim/Vundle.vim
- i.e. git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
Using Vundle#
- Mention bundle names (as a github repo) in .vimrc file
1 2 3 4 5 6 7 8 9 |
|
- Install using command
1 |
|
VIM as Python IDE#
Source: http://chrisstrelioff.ws/sandbox/2016/09/21/vim_and_vundle_on_ubuntu_16_04.html
-
~/.vimrc & ~/.editorconfig config files @ https://gist.github.com/toransahu/66c69903649f3d417d8ba4dc78324f60
-
cheat sheet: https://gist.github.com/toransahu/4a921c6fb73274479dbdfbcfe6dda483
Tmux#
Tmux Package Manager#
Source: https://github.com/tmux-plugins/tpm
~/.tmux.conf : https://gist.github.com/toransahu/53a523d973a212f52ce53474417e01b1
Tmux Plugins:#
- Sidebar: https://tmuxcheatsheet.com/tmux-plugins-tools/?full_name=tmux-plugins%2Ftmux-sidebar
Commands#
-
abbr.
- prefix:
ctrl + b
- prefix:
-
help:
ctrl + b ?
-
select, copy, paste within tmux
- enter scroll mode:
ctrl + b [
- enter select mode:
ctrl + space
- move cursor to select text
- copy to tmux buffer:
alt + w
- copy to system clip:
ctrl + b - y
- paste to any tmux:
ctrl + b ]
- enter scroll mode:
-
create/split pane
- vertical split:
prefix %
- hor split:
prefix "
- vertical split:
-
convert a pane to window:
prefix !
-
move to pane:
prefix arrows
-
close current pane:
prefix x
Load .bashrc with tmux#
By default tmux runs a login shell. When bash is invoked as an interactive login shell, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile. So you have to put source ~/.bashrc
in one of those files.
Another way to solve this issue is to put in your file .tmux.conf the line:
set-option -g default-shell "/bin/bash"
KeyBoard Custom Shortcuts Bindings#
Emulate right click from keyboard#
-
install xdotool
1
sudo apt install xdotool
-
bind keyboard shortcut with command:
xdotool click 3
Backup & Restore Cinnamon settings#
1 2 3 4 5 6 7 8 9 10 11 |
|
Raspberry Pi#
OS#
Raspbian with RPD Desktop#
- prepare https://www.raspberrypi.org/forums/viewtopic.php?t=135316
Raspbian Lite (without GUI)#
Install Desktop for Lite#
Source: https://www.raspberrypi.org/forums/viewtopic.php?t=133691
Enable ssh & enter SSID/WiFi details without keyboard#
Source: https://medium.com/@danidudas/install-raspbian-jessie-lite-and-setup-wi-fi-without-access-to-command-line-or-using-the-network-97f065af722e
Ubuntu Core/Snap#
Windows IoT#
Display#
Touch Screeen Config#
- 5 inch capacitive 800*480
/boot/config.txt
1 2 3 4 5 6 |
|
Backup Image from Burnt Image#
On a different linux PC using USB.#
- It won't work on the raspi!, it will get trapped in infinit loop
1 2 3 4 5 6 7 8 |
|
In Raspberry Itself using rsync
#
Network Drive Mount (sshfs)#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Remote Audio#
bluetooth#
Way 1#
1 2 3 4 |
|
- https://gist.github.com/mill1000/74c7473ee3b4a5b13f6325e9994ff84c
- https://raspberrypi.stackexchange.com/questions/48140/raspberry-pi-3-connecting-to-bluetooth-audio-device-on-raspbian-jessie
- https://markus.jarvisalo.dy.fi/2017/12/making-the-raspberry-pi-3-a-bluetooth-audio-receiver/
Way 2#
- https://www.instructables.com/id/Turn-your-Raspberry-Pi-into-a-Portable-Bluetooth-A/
1
$ sudo vim /var/lib/bluetooth/00:1A:7D:DA:71:11/config
wifi#
- shareport
- https://thepi.io/how-to-set-up-a-raspberry-pi-airplay-receiver/
enable ssh from card#
- put empty ssh file inside /boot/
set wifi/ssid from card#
- change inside /etc/network/interface
1 2 3 4 5 6 7 8 9 10 11 12 |
|
wifi to ethernet#
src: https://www.instructables.com/id/Share-WiFi-With-Ethernet-Port-on-a-Raspberry-Pi/
1 2 3 4 5 6 |
|