====== Linux ======
-[[linux:RBS|Razer Blade Stealth in Linux]]
-[[linux:lampp|LAMPP local server]]
-[[linux:git|Git basics]]
-[[linux:bash|Bash]]
-[[linux:sed|sed]]
===== PATH =====
PATH is the //environment variable// containing a set of directories that should be searched for programs
#print user PATH
$ printenv PATH
/bin:/sbin:/usr/bin:/usr/sbin
$ echo "$PATH"
/bin:/sbin:/usr/bin:/usr/sbin
#How it works
$ ping 127.0.0.1
PATH=/bin:/sbin:/usr/bin:/usr/sbin
│ │
│ ╰──▶ /sbin/ping ? found!
╰──▶ /bin/ping ? not found.
#Add a folder to path for current shell session
$ PATH=$PATH:/path/to/app/folder
==== Local installs of binaries and PATH correction ====
=== Install the binary ===
There is debate as to where binaries that you install yourself should be put in the filesystem. The proper places to put them seem to be :
/opt/ <- for bundled applications, typically grabbed from a software developper
/usr/local/ <- for applications built by the administrator for local use, i.e. using "make" or other
/home/USER/opt/ <- for single-user use only
[[http://refspecs.linuxfoundation.org/fhs.shtml|FHS Reference]]
=== Add it to the user's PATH ===
Include the following line in /home/USER/.profile :
EXPORT PATH="/path/to/bin/folder:$PATH"
This will only be active **after logging out**. If you want to activate it without logging out for a current shell session run the following command :
$ source /home/USER/.profile
//Note that the path must point to the **folder containing** the binary and not to the binary itself.//
=== Add it to cinnammon start menu ===
Cinnammon has implemented a handy GUI Editor you can access by right-clicking the 'Menu' icon and selecting 'configure'. You can also launch :
$ cinnamon-menu-editor
Using bash you can create a symbolic link to a .desktop file anywhere on your system and place that link in /usr/share/applications
$ ln -s path/to/target/file.desktop LINK_NAME
Make sure the .desktop file has proper permissions :
$ chmod 644 path/to/file.desktop
The menu entry will appear after logging out.
=== Locate a binary ===
$ type man
man is /usr/bin/man
----
===== AppImages =====
Extract the content of an AppImage :
./your.AppImage --appimage-extract
This is useful if you want to get the Icon.
[[https://github.com/AppImage/AppImageKit/releases|Link to AppImage Daemon]] //This Daemon scans well known places for appimages and creates menu entries and extracts icons//
----
===== Grub =====
Config file is located at ''/etc/default/grub''
The line for a splash image is ''GRUB_BACKGROUND=/path/to/image.jpg''
----
===== Limit CPU usage =====
There are various ways to limit the CPU usage of a process. One simple way is using ''cpulimit''
$ cpulimit -P /path/to/executable -l %CPU (e.g. 40) -b (background)
[[https://linoxide.com/linux-how-to/limit-cpu-usage-processes-linux/|Ressource site]]
----
===== Fonts install (bash) =====
To quickly install folders containing many OpenType fonts (OTF) or TrueType fonts (TTF), copy to the following locations :
$ sudo cp -r /path/to/OTF-folder /usr/share/fonts/opentype/
$ sudo cp -r /path/to/TTF-folder /usr/share/fonts/truetype/
Regenerate font cache :
$ sudo fc-cache -f -v
**Note :** This will install fonts system-wide. To install for a single user only copy the files to :
~/.fonts/
and regenerate font cache.
===== Manipulate pdf =====
==== Modifying page order ====
Use (pdftk (ubuntu) -> deprecated) or pdf-stapler (fedora) :
//For example to extract two pages out of a pdf//
$ pdf-stapler cat in.pdf 2-3 out.pdf
Old syntax with pdftk : $ pdftk in.pdf cat 3-4 output out.pdf
=== Ubuntu and derivatives ===
pdfshuffler is a front end for python-pyPdf and a great tool for merging or splitting pdf files with a GUI.
==== Reducing PDF size ====
Found from [[https://askubuntu.com/questions/113544/how-can-i-reduce-the-file-size-of-a-scanned-pdf-file|
this answer]] on AskUbuntu :
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
''-dPDFSETTINGS'' can be the following :
*''/screen'' lower quality, smaller size. (72 dpi)
*''/ebook'' for better quality, but slightly larger pdfs. (150 dpi) - __This one gives quite a good ratio of quality-loss/size-reduction__
*''/prepress'' output similar to Acrobat Distiller "Prepress Optimized" setting (300 dpi)
*''/printer'' selects output similar to the Acrobat Distiller "Print Optimized" setting (300 dpi)
*''/default'' selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file
===== Repair FAT32 FS errors =====
When FAT32 filesystems mount in read-only it's often related to corrupted filesystem.
Run **dmesg** to check. If you see lines such as :
[54259.098330] FAT-fs (sdb1): error, corrupted directory (invalid entries)
[54259.098338] FAT-fs (sdb1): Filesystem has been set read-only
[54304.610623] FAT-fs (sdb1): error, corrupted directory (invalid entries)
[54304.690012] FAT-fs (sdb1): error, invalid access to FAT (entry 0xf7d0f91e)
[54304.690213] FAT-fs (sdb1): error, invalid access to FAT (entry 0xff27ff23)
[54304.690314] FAT-fs (sdb1): error, invalid access to FAT (entry 0xff0dff13)
Run the following command :
$ sudo umount /dev/sdX#
$ sudo fsck.msdos -aw /dev/sdX#
//[[https://serverfault.com/questions/331779/how-do-i-debug-this-fs-error-on-a-flash-device?newreg=6fb41732994749cc8d802f6233af86ea|Stack Exchange thread on the subject]]//
===== Data Recovery =====
Try [[https://www.cgsecurity.org/wiki/TestDisk_Download|Test Disk & PhotoRec]] written by Christophe Grenier
=== For .mov ===
//PhotoRec 7.1-WIP//
In FileOptsMenu check :
[X] mov/mdat Recover mdat atom as a separate file
Two files are created for every .mov recovered. Concatenate with :
cat f123_ftyp.mov f456_mdat.mov > 1.mov
cat f456_mdat.mov f123_ftyp.mov > 2.mov
One of the two files will be good. Sometimes one file is .mp4 and the other is .mov :
cat f54114560.mp4 f51781632_mdat.mov > 1.mov
===== Mount NTFS =====
If a NTFS volume mounts in read-only, remount using :
$ su
$ mkdir /mnt/ntfs
$ mount -t ntfs /dev/sd[X] /mnt/ntfs
===== mplayer =====
==== Configuration Files ====
=== Global ===
*/etc/mplayer/mplayer.conf
=== Local ===
*~/.mplayer/config
*~/.mplayer/input.conf
*~/.mplayer/menu.conf
==== Common Options ====
fs=yes #enable fullscreen
noborder=yes
ontop=yes
geometry=+3200
osdlevel=0
===== Using Apple USB SuperDrive =====
=== Required packages ===
sg3-utils
=== Find USB Drive ===
(usually sr0 or sr1)
$ ls /dev | grep 'dvd'
=== Send activation byte sequence ===
(change sr0 accordingly if needed)
$ sg_raw /dev/sr0 EA 00 00 00 00 00 01
===== QCAD Tutorial removal =====
This is not specifically linux-related but since every time I install it (especially on MacOS systems) it's such a pain to find the plugins/ folder from where to remove the plugins blocking the trial version of QCAD here's an easy way to find them :
Go to Help > About > Plugins and just click on the name of one of the plugins.
In MacOS it will be QCAD > About > Plugins instead.
===== LAMPP Local Server =====
Start stop the server using :
sudo /opt/lampp/lampp start/stop
Put your sites and data in :
/opt/lampp/htdocs/example_site
===== Fixes =====
==== Wired network doesn't work after suspend (does not work) ====
Identify your wired interface card module. Realtek 8169 is known to have this issue with some kernels.
$ lsmod
Look for :
....
hid 118784 2 usbhid,hid_generic
ahci 36864 4
r8169 86016 0
libahci 32768 1 ahci
mii 16384 1 r8169
...
Edit (create if it doesn't exist) the file :
$nano /etc/pm/config.d/unload_modules
Append the following line :
SUSPEND_MODULES="$SUSPEND_MODULES r8169"
Replace module name if necessary
//Note to self : Added "mii" module to the list, the fix didn't seem to hold after reboot. Mii seems to be using r8169 and is network-monitoring-related//
==== Fixing python on youtube-dl ====
If following error occurs while using ''youtube-dl'' :
/usr/bin/env: ‘python’: No such file or directory
=== If python3 is not installed ===
$sudo apt install python3
=== If python3 is installed ===
$whereis python3
$sudo ln -s /usr/bin/python3 /usr/bin/python
Change first argument according to where python3 is installed.
===== Linux Screencast tools =====
***Kazam :** only one tried at the moment, produces OK files and you can select a specific region you want to capture
*gtk-recordmydesktop
*vokoscreen
*simplescreenrecorder
*add-apt-repository ppa:maarten-baert/simplescreenrecorder
===== Open VPN =====
=== Connecting a client to a remote server ===
//This requires a valid .ovpn file//
openvpn --config /path/to/file.ovpn
[[https://www.linux.com/training-tutorials/configure-linux-clients-connect-openvpn-server/|Linux.com OpenVPN connection tutorial]]
=== Connecting to shared folders through openvpn ===
//This requires the ip of the shared folders location//
===== Samba tips =====
=== List available shares on a given host ===
Replace host with the hostname or IP address of the server running samba shares
$ smbclient -L host
Output will be something like this
Sharename Type Comment
--------- ---- -------
home Disk
shares Disk
users Disk
IPC$ IPC IPC Service ()
Reconnecting with SMB1 for workgroup listing.
Server Comment
--------- -------
Workgroup Master
--------- -------
MY_WORK CODE-CA04
[[https://www.tldp.org/HOWTO/SMB-HOWTO-8.html|More ressources here]]
=== Locate mount points ===
Most of the time they are located at ''/run/user/##ID##/gvfs''
===== Alias =====
Create an alias using command
alias name='command'
The alias is only in place while the user session is active. To make it permanent, write it in the ''.bashrc'' file in the home directory of the user. ([[http://www.linfo.org/alias.html|more info]])
You can reload the .bashrc file using :
$ source ~/.bashrc
#or
$ . ~/.bashrc
===== Programming Mouse Buttons =====
$ sudo apt install xbindkeys xvkbd
$ xev | grep ', button' #Find the buttons you need to map
$ touch ~/.xbindkeysrc
$ nano ~/.xbindkeysrc
// Sample File ://
# Send enter on thumb mouse button
"xvkbd -text '\r'"
b:8
// Ccheck xvkbd for more syntax //
===== Useful shell =====
=== Mass renaming files ===
[[https://debian-administration.org/article/150/Easily_renaming_multiple_files.|Debian Admin guide to mass renaming]]
You can use for commands in the shell or use the 'rename' tool (written in perl). For example :
skx@lappy:~$ ls
a.JPG b.JPG c.JPG d.JPG
skx@lappy:~$ for i in *.JPG; do mv "$i" "${i/.JPG}"; done
skx@lappy:~$ ls
a.jpg b.jpg c.jpg d.jpg
----
=== cut ===
Remove sections from input and output them
$ date
Thu 02 Jan 2020 08:20:10 PM CET
$ date | cut -c17-24
08:21:02
----
=== Mount ===
List mounts
$ findmnt
Target disk
$ sudo fdisk -l
Disk /dev/sda
[...]
Disk /dev/sdb
[...]
Create mount point
$ sudo mkdir /media/DRIVE
Mount device
$ sudo mount /dev/sda1 /media/DRIVE
Unmount
$ sudo umount /media/DRIVE
[[https://linuxconfig.org/howto-mount-usb-drive-in-linux|More info]]
----
=== pwd ===
Display Present Working Directory
$ pwd
/home/pi
----
=== tar ===
Pack/Unpack tarball
#All the following commands are verbose (-v) and target a file archive (-f)
$ tar -xvf file.tar #Unpack tar (-x : extract)
$ tar -xvzf file.tar.gz #Unpack compressed (gzip) tar (-z : filter through gzip)
$ tar -cvf file.tar /path/folder #Pack folder into file.tar archive (-c : create)
$ tar -cvzf file.tar /path/folder #Same as above with compression (gzip) (-z : filter through gzip)
[[https://www.cyberciti.biz/faq/tar-extract-linux/|Extensive Guide]]
----
=== Samba ===
sudo service smbd start/stop/restart
----
===== apt and dpkg =====
==== Fixing apt dependency problems ====
This can fix some states in which apt is broken and refuses to update because some libraries fail :
$ dpkg --configure -a
$ apt --fix-broken install
===== List info =====
=== Display all information ===
$ inxi -F
//Read the manual, inxi is a very powerful tool to quickly get an overview of a full hardware setup//
=== Distrib ===
$ lsb_release -d
=== CPU ===
Basic
$ lscpu
Detailed, core-specific information, output /proc/cpuinfo
$ cat /proc/cpuinfo
On Macs :
$ sysctl -n machdep.cpu.brand_string
=== Mounted devices ===
$ df -h
=== Kernel ===
$ uname -snrm
*s : kernel name
*n : network node hostname
*r : kernel relase number
*m : machine hardware name
[[ http://www.tecmint.com/useful-linux-commands-for-system-administrators/]]
=== Kernel modules ===
$ lsmod
=== Bash history ===
$ history
=== D-Bus/system bus history ===
$ gdbus
$ g-feet //gui history
=== Motherboard information ===
$ sudo dmidecode | grep -A3 ‘^System Information’
//dmidecode spurns out a lot of information if you want to query your system//
=== Diagnostics & Tools ===
$ uptime [load Average]
$ dmesg -T | tail [Kernel errors]
$ vmstat 1 [Virtual memory and detailed information]
$ mpstat -P ALL 1 [CPU state]
$ pidstat [processes]
$ free -m [memory]
$ atop [main overview]
===== Debug & Logs =====
''/var/log/syslog''
Check in ''/var/log'' which file was last changed. Use :
$ls -lart //inverted sorted by time. Last entry is latest modified
===== Misc Ressources =====
*[[https://en.wikipedia.org/wiki/Magic_SysRq_key#Configuration|SysRq Keys]] -- Best combo is ''Alt + SysRq + R E I S U B''
*[[https://www.guruadvisor.net/en/software-saas/465-advanced-linux-troubleshooting-methods-and-tools-for-diagnostics-and-problem-identification|Advanced Linux Troubleshooting]]
*[[https://wiki.networksecuritytoolkit.org/nstwiki/index.php?title=HowTo_Create_A_GPT_Disk_With_EFI_System_And_exFAT_Partitions_Using_Parted|Creating GPT/exFAT partitions using CLI]]