← Home

Everyday

Paste in Terminal

ctrl-shift-v

ctrl-shift-v

List, move, copy, delete

ls lists. cd D then double-tab shows options starting with D. pwd is present working directory. cd / goes to root. cd .. goes up.

ls
pwd
cd /
cd ..
echo "Hi!" > text.txt
cp text.txt Downloads
mv test.txt Downloads/
rm Downloads/test.txt

Help and locate

man is the manual. locate needs an updated database first.

man ls
ls --help
updatedb
locate bash

Run several commands

&& runs the next command only if the previous succeeded. ; runs the next even if the previous failed. You can also write a shell script.

command1 && command2
command1; command2

Password and timezones

passwd
timedatectl list-timezones

Become root

sudo -i
sudo su

usr does not mean user. It means universal system repository (or something).

Install

Install a .deb

Open Terminal in the folder.

sudo apt install ./bitwig-studio-5.2.7.deb

Upgrade one package only

apt-get install --only-upgrade packagename

Install a .sh script

chmod +x /path/to/yourscript.sh
sh install.sh
./myscript.sh

Check if an app is installed

applicationname -v, for example:

pdftoppm -v

HandBrake

sudo add-apt-repository ppa:stebbins/handbrake-git-snapshots
sudo apt-get update
sudo apt-get install handbrake

System info

What computer / distro

uname -a
lsb_release -a
echo $XDG_CURRENT_DESKTOP
echo $XDG_SESSION_TYPE

CPU, RAM, disk

top shows RAM usage. lsmem shows how much RAM you have. sblk / lsblk shows disks. df -h is disk space.

top
lsmem
lscpu
cat /proc/cpuinfo
free -m
cat /proc/meminfo
lsblk
df -h

BIOS and hardware IDs

sudo dmidecode -t system
sudo dmidecode -t bios
sudo dmidecode -t processor
sudo dmidecode -q

Connected devices

lsusb
lsblk

Users & processes

Kill a program

Kills that process (which you might have seen using lots of resources).

killall programName

chmod

chmod +rwx hello.txt
chmod +x hello.txt
chmod 777 hello.txt
chmod +x myscript.sh

Users

su is switch user. userdel deletes the user. john will not be able to sudo passwd root unless they are in the sudoers file.

adduser john
cat /etc/passwd
cat /etc/shadow
su john
passwd root
sudo passwd root
userdel john

Network

Interfaces, ping, arp, ports, route

ifconfig shows interface types and IP addresses. iwconfig you usually see on a laptop. arp -a shows IPs and MAC addresses. netstat -ano shows what is talking on a port. route prints the routing table (where traffic exits).

ifconfig
iwconfig
ping 1.1.1.1
arp -a
netstat -ano
route

Display

Rotate the screen

xrandr -o left
xrandr -o normal

Disable the touch screen

Install xinput, type xinput, find the screen/finger/digitizer id, then disable that id (9 is only an example).

xinput
xinput disable 9

Clear thumbnail cache

rm -rf ~/.cache/thumbnails/*

Bulk rename in Thunar

Use Numbering and do Text - Number, and add your text there too.

Audio

Boost volume of all audio in the folder

I think 3X. Install ffmpeg first. Skips missing extensions if they are not in the folder.

for file in *.mp3 *.wav *.WAV *.ogg *.flac *.m4a; do
    [ -f "$file" ] || continue
    ffmpeg -i "$file" -filter:a "volume=3.0" -c:v copy -c:a libmp3lame -q:a 2 "louder_${file}"
done

Convert all WAVs to mp3s

for file in *.[wW][aA][vV]; do [ -f "$file" ] || continue; ffmpeg -i "$file" -q:a 2 "${file%.*}.mp3"; done
for i in Silver0709.wav; do ffmpeg -i "$i" "${i%.*}.mp3"; done

Convert all mp4s to mp3s

for file in *.[mM][pP]4; do [ -f "$file" ] || continue; ffmpeg -i "$file" -vn -q:a 2 "${file%.*}.mp3"; done

Convert mp3 to wav

Install mpg321 (not 123). Put the to-be-created wav title first.

mpg321 -w newFile.wav "old file.mp3"
mpg321 -w ZOOM0061.WAV ZOOM0061.mp3

Get mono sound out of speakers

Then if you click on your sound icon, you should have an option for Remapped Built-in etc. Use the sink name from the first command, without the angle brackets.

pacmd list-sinks | grep name:
pacmd load-module module-remap-sink sink_name=mono master=NAME_OF_AUDIO_SINK_GIVEN_BY_PREVIOUS_COMMAND_BUT_WITHOUT_ARROW_BRACKETS channels=2 channel_map=mono,mono

Images

Invert colors of all jpgs in the folder

Install imagemagick first.

find . -maxdepth 1 -type f -name "*.jpg" -exec mogrify -negate {} \;

Rotate all images in the current folder

mogrify -rotate 90 *.JPG

Print a word on a picture

Kerning is spacing between the letters. The color is offwhite/yellow. The numbers indicate how far off center.

convert theimage.JPG -font DejaVu-Sans -pointsize 72 -kerning 10 -fill "#D3CBA8" -gravity center -annotate +260+220 "the words" output.jpg

Batch crop

mogrify -crop 300x300+150+150 -path ./cropped *.png
convert *.png -crop 350x300+150+200 cropped.jpg

An example line which is just to illustrate:

convert -crop x_sizexy_size+x_offset+y_offset inputfile outputfile

Image metadata

identify -verbose filename.png

Clean metadata

exiftool. jexiftool has an AppImage. exifcleaner also.

exiftool filename.jpg

Change date modified

On Linux it seems there is no ability to modify creation date, even with filesystems that allow it. Put the files in a folder and open Terminal there.

touch *

Video

Convert mp4 into gif

ffmpeg -i kpop.mp4 -vf "fps=10,scale=480:-1:flags=lanczos" output.gif
ffmpeg -i output.gif -vf "crop=in_w-3:in_h:3:0" outputs.gif

Make an mp4 music video from png and wav

Use 1600x1600 if you want, because it is divisible by 2 and 4. ffmpeg does a better job of combining audio with a single image than Kdenlive, which makes big files.

ffmpeg -loop 1 -i *.png -i *.wav -c:v libx264 -tune stillimage -pix_fmt yuv420p -c:a aac -b:a 324k -shortest output.mp4
ffmpeg -loop 1 -i theimage.jpg -i Song.wav -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest outputVideo.mp4
ffmpeg -loop 1 -i easywords1.jpg -i easywords1.wav -vf "crop=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -t 1480 out-image.mp4
ffmpeg -loop 1 -i easywords2.png -i easywords2.wav -vf "crop=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -t 1840 easywords2.mp4

Download

youtube-dl (outdated)

Download mp3:

youtube-dl -x --audio-format mp3 http:address

Download a playlist as mp3s:

youtube-dl --ignore-errors --format bestaudio --extract-audio --audio-format mp3 --audio-quality 160K --output "%(title)s.%(ext)s" --yes-playlist https:address

Files & text

Make a txt file

Nano: Ctrl-O saves. Ctrl-shift-V pastes. cat > file then type, then Ctrl-D to save.

touch filename.txt
ls -l
cat filename.txt
nano filename.txt
cat > filename.txt

Scan & clean

Clamscan recursively

Recursive is all the subdirectories, which is not its default. Open terminal in the folder.

clamscan -r
clamscan -r /path/to/directory

PDF

PDF to text (slice, OCR, extract)

qpdf orig.pdf --pages . 420-511 -- just-the-chapters.pdf && convert -density 288 just-the-chapters.pdf output-%02d.jpg && convert output.jpg -level 25% final-%02d.jpg && convert final.jpg vr.pdf && ocrmypdf -l spa vr.pdf bookonech11-12.pdf && pdftotext -layout bookonech11-12.pdf bookonech11-12.txt && rm output* && rm final* && rm vr.pdf && rm just-the-chapters.pdf