Will be jotting down commonly used cli commands to get by most of the tasks at hand. Linux ui may be friendly but when it comes to unleashing the real power, cli is ones best friend.
Installing/Removing softwares
sudo apt-get install
sudo apt-get remove
sudo dpkg -i filename.deb
sudo dpkg -i *.deb (for bulk installation of all debs in the folder)
Managing mount points
sudo mount -o loop
sudo umount
e.g. sudo mount -o loop /dev/sda5 /data
sudo umount /data
This works well for iso files too
e.g. sudo mount -o loop filename.iso /data
sudo umount /data
Creating USB installer from distro iso
Identify the usb drive from list of available drives using command lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 74.5G 0 disk
├─sda1 8:1 0 11.5G 0 part /
├─sda2 8:2 0 1K 0 part
├─sda5 8:5 0 2.4G 0 part [SWAP]
└─sda6 8:6 0 60.7G 0 part /home
sr0 11:0 1 1024M 0 rom
sdb 8:16 1 1.9G 0 disk
├─sdb1 8:17 1 910.2M 0 part
└─sdb2 8:18 1 1013M 0 part
Here we can see two usb drives. /dev/sdb1 and /dev/sdb2
To copy contents of iso file onto usb drive use commandsudo dd if=distro-name.iso of=/dev/sdb
Do not append the number to device.
The usual stuffps -ef
ps -ef | grep vlc
– to find running instances of VLC. subtitute it for any other program you want to find.sudo kill -9
– send terminate signal to program identified by pid.nano
– cli text editor
Clearing list of recent videos
History of recently used files is stored in an xml(recently-used.xbel) which keeps tab on the file opened, its mime type, the default application which opens it etc.
For most, the concern is to erase/remove list of recently watched videos in the video player. The trick is to erase contents of the xml file at logon, so every time you start with a clean slate.
In linux, on logon there is a .profile script that gets executed for every user. It is located in the home folder. To see its contents type this in the terminal
cat ~/.profile
Its a hidden file, notice the dot before the file name. You need to edit this file
nano ~/.profile
and add this line at the end of it
echo > ~/.local/share/recently-used.xbel
The command simply writes an empty recently-used.xbel file. So now on, every time a user logs in, his file usage history is cleaned. But this goes for all files, so applciation like office suites where recent file list would be useful, will have to do without it.
Dropbox for Elementary files
Install dropbox deb file from their site. To fully integrate Dropbox into pantheon-files to allow you to right click files, you must download a small plugin.
sudo apt-get install pantheon-files-plugin-dropbox
Disk Analysis Tool
ncdu is a very handy tool for analyzing current disk usage. Install it via apt
sudo apt-get install ncdu
Run it by passing the dir location as parameter.
For analyzing current dir run
ncdu .
For any specific directory pass its path to ncdu
ncdu /
ncdu /home
This gives a details view of subfolders and its size. Hit enter on a particular folder to analyzer its contents. Hit /.. to move up. Hit ‘q’ to quit program.
For analysis of free space use linux command ‘df’
koolksp@koolksp-3000-N100:~$ df .
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda6 62650316 58223176 1244652 98% /home
koolksp@koolksp-3000-N100:~$ df /
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 11810736 3617896 7592880 33% /
This shows % usage and Used/Available blocks. For a more readable output pass the -h parameter.
koolksp@koolksp-3000-N100:~$ df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 60G 56G 1.2G 98% /home
koolksp@koolksp-3000-N100:~$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 12G 3.5G 7.3G 33% /
This will list file sizes in GB which is more easy to read and understand.
Password feedback with ‘*’ while entering password for sudo
While running a command as sudo, the command prompt will wait for the user to enter the password. While the default behavior is not to show up any activity at the prompt, it sometime helps to see if actually entered the letters as you type your password. This allows the prompt to show an asterix every time you hit the keypad. To add this behavior, follow these simple steps –
- Run
sudo visudo
- Add line
Defaults pwfeedback
after the lineDefaults env_reset
- Save and exit the editor. For nano it is ctrl-O followed by ctrl-X. If you are using vi editor use :wq!
Open a new terminal window and try some sudo command. This time the password being typed will show up on screen masked as ‘*’ for eg.
~$ sudo apt-get install g++
[sudo] password for koolksp: ******
Quick Hack for converting m4a to mp3
Install youtube-mp3 and add an alias in the ~/.profile for the most common setting to download as m4a
alias youtube-mp3="youtube-dl -f 140 -o '%(title)s.%(ext)s'"
This should work at login. If not, run command source ~/.profile to get it working.
Alias usage :
youtube-mp3 [youtube-url-you-want-to-copy]
This will save the audio in m4a format.
To convert m4a to mp3 create an sh file with following contents
#!/bin/sh
if [ ! -d newfiles ]
then
mkdir newfiles
fi
for f in *.m4a; do ffmpeg -i "$f" -codec:v copy -codec:a libmp3lame -q:a 2 newfiles/"${f%.m4a}.mp3"; done
This creates a new directory for saving the mp3 files, if it doesn’t already exist, and convert all m4a files to mp3 using the ffmpeg command and parameters. Make sure to have an updated ffmpeg version installed.
Run the script at the location where bunch of m4a are saved and let it work its magic. Converted mp3 files will be under “newfiles”
Another trick is to use the avconv to same effect. In case avconv is not already installed run sudo apt-get install libav-tools
to have avconv installed. Then run the following command to convert m4a to mp3 files. This version deletes original files. This can be setup as an alias in the ~/.profile as discussed before.
alias m4a2mp3='for i in *.m4a; do avconv -i "$i" "${i/.m4a/.mp3}"; rm "$i"; done'
Getting scanner working in BunsenLabs
Scanning software and related drivers are not installed by default in BunsenLabs. This can be quickly fixed by installing stuff from the repo. For HP scanners, the hplip library installs all the required drivers for printing and scanning. I installed this for my HP Deskjet printer/scanner. Use following to install both, driver and scanning software.
sudo apt-get install hplip simple-scan
Installing sublime text on Fedora
sudo rpm -v --import https://download.sublimetext.com/sublimehq-rpm-pub.gpg
sudo dnf config-manager --add-repo https://download.sublimetext.com/rpm/stable/x86_64/sublime-text.repo
sudo dnf install sublime-text
This will install the latest version of sublime text on Fedora. (Build 3211 at the time of this writing)
Adding Git Bash Support on Fedora
Handy little feature to add support to display the current git branch on linux prompt.
https://corlewsolutions.com/articles/article-118-enhance-your-git-prompt
https://eshlox.net/2017/08/10/how-to-install-powerline-for-bash-on-fedora-with-git-branch-support
Follow either approach to have a better git support. For the first one I have tinkered around for the value of PS1 and finally settle for this-
export PS1='[\u@\h \W\[\033[01;33m\]$(__git_ps1)\[\033[00m\]]\$ '
Quick script to organize files by type and move them to respective folder
#! /usr/bin/sh
for i in 'find -maxdepth 1 -type f -printf '%s %f\n' | cut -d '.' -f 2 | sort | uniq'; do
if [ ! -d "$i" ]
then
mkdir $i
fi
mv *.$i $i/
done
echo Files segregated into folders by extension
Change the characters to backtick for executing the find command.
Script to create desktop shortcuts for AppImages
#! /usr/bin/sh
if [ $# -lt 3 ]
then
echo "Usage : sh gen-shortcut.sh <name> <appimage> <icon>"
exit
fi
if [ ! -f "$2" ]; then
echo AppImage \'$2\' not found
exit
fi
if [ ! -f "$3" ]; then
echo Icon \'$3\' not found
exit
fi
echo Creating Desktop file $1.desktop
newfile="/home/koolksp/.local/share/applications/"$1.desktop
echo "[Desktop Entry]" > $newfile
echo "Type=Application\nEncoding=UTF-8" >> $newfile
echo "Name="$1 >> $newfile
echo "Comment="$1" Appimage" >> $newfile
echo "Exec=/home/koolksp/Apps/"$2 >> $newfile
echo "Icon=/home/koolksp/Apps/"$3 >> $newfile
echo "Terminal=false" >> $newfile
echo Done
Place script within the ~/Apps folder. Whenever a new AppImage is added, save its icon in the /icons directory and execute the above script with three parameters
- Name of the app
- Name of AppImage file
- Name of icon file
This generates a .desktop file under ~/.local/share/applications and the AppImage is accessible via gnome menu.
Script to shrink video files
#! /usr/bin/sh
if [ $# -lt 2 ];then
echo Usage : shrinkvid [resolution] [file]
echo Eg. shrinkvid 720 video.mp4
echo "================================="
echo resolution can have values like 1080, 720, 480, 320 etc
echo if the value provide is more than current resolution of the input file
echo then the video will be scaled up
exit
fi
newH=$1
if [ ! -f $2 ];then
echo File $2 not found.
exit
fi
input_file=$2
file_res=`ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 $2`
origW=`echo $file_res | cut -d "," -f 1`
origH=`echo $file_res | cut -d "," -f 2`
scale=`echo "scale=2;$origH/$newH" | bc`
newW=`echo "$origW/$scale" | bc`
if [ `expr $newW % 2` = 1 ];then
newW=`expr $newW + 1`
fi
output_file="${input_file%.*}"-$1"p.${input_file##*.}"
echo Converting $input_file to $output_file
ffmpeg -loglevel quiet -i $input_file -vf scale=$newW:$newH $output_file
echo DONE
Works on ffmpeg and ffprobe. Make sure these are installed. Place script inside ~/.local/bin, change permissions to 755 and enjoy!
Manage Photo And Video slideshows from command line
To quickly to start playing all video files in current directory add following alias to ~/.profile. Run “sudo apt-get install mpv” if it is not already installed. Add more file extensions to egrep as required.
alias playvideos='ls -1 | egrep "*.mp4|*.MP4|*.mkv" | xargs mpv -fs'
To start slide show of all image files in current directory add following alias to ~/.profile. Run “sudo apt-get install feh” if it is not already installed. Add more file extensions to egrep as required. Tweak slideshow delay as required.
alias slideshow='ls -1 | egrep "*.jpg|*.JPG|*.jpeg|*.JPEG" | xargs feh --fullscreen --slideshow-delay 5'
Fixing Raspberry Pi issue with “No HDMI Signal”
Raspberry Pi sometimes refuses to detect the external monitor and after booting the display shows “No HDMI signal”. This can be fixed by editing the /boot/config.txt as root and adding the following lines
hdmi_force_hotplug=1
Setting hdmi_force_hotplug to 1 makes sure the Pi believes the external HDMI display is available and does not try to negotiate the device.
Refer to Raspberry documentation for usage of hdmi_group and hdmi_mode.
hdmi_group
The hdmi_group
command defines the HDMI output group to be either CEA (Consumer Electronics Association, the standard typically used by TVs) or DMT (Display Monitor Timings, the standard typically used by monitors). This setting should be used in conjunction with hdmi_mode
.
hdmi_group | result |
---|---|
0 | Auto-detect from EDID |
1 | CEA |
2 | DMT |
hdmi_mode
Together with hdmi_group
, hdmi_mode
defines the HDMI output format.
For hdmi_group=2
hdmi_mode | Resolution | Frequency | Screen Aspect | Notes |
---|---|---|---|---|
82 | 1920×1080 | 60Hz | 16:9 | 1080p |
Add this to /boot/config.txt
hdmi_group=2
hdmi_mode=82
Finding the process responsible for generating a window
xprop allows to select any window currently rendered on the desktop eg terminal window, firefox or even a notification pop-up, and gives the pid of the process.
Eg. run the following command and select the terminal window
[koolksp@koolksp-rpi ~]$ xprop _NET_WM_PID
_NET_WM_PID(CARDINAL) = 1593
Use the PID to find the process using
ps -ef | grep $(xprop _NET_WM_PID | awk '{print $3}')
This gives following output and helps identify the process
[koolksp@koolksp-rpi ~]$ ps -ef | grep $(xprop _NET_WM_PID | awk '{print $3}')
koolksp 1593 1 1 17:09 ? 00:00:34 mate-terminal
koolksp 1620 1593 0 17:09 pts/0 00:00:00 bash