lwc:programming:bash

This is an old revision of the document!


Comments:

Put: : <'COMMENTBLOCK_ORWHATEVERYOUWANTTOCALLME'

before the block and put:

COMMENTBLOCK_ORWHATEVERYOUWANTTOCALLME

after the block

DISPLAY SETTINGS:

  • xrandr example: xrandr –output HDMI1 –mode 1280×1024 –right-of eDP1
  • change 1280×1024 display to 1600×1280:xrandr –output DP-1 –scale 1.25×1.25 –panning 1600×1280
  • shift display down 1280 pixels: xrandr –output eDP-1 –mode 1920×1080 –pos 0x1280

FILE MANAGEMENT

Count # of files in a directory (recursively):

ll -R | grep -v "\(total \)" | grep -v "\.\?[/]$" | grep -v "^$" | wc -l

List files recursively by date:

find . -printf "%T@ %Tc %p\n" | sort -n

printf arguments from man find:
    %Tk: File's last modification time in the format specified by k.
    @: seconds since Jan. 1, 1970, 00:00 GMT, with fractional part.
    c: locale's date and time (Sat Nov 04 12:02:33 EST 1989).
    %p: File's name.

Add symbolic link to file (~/www/elgg1.5/php.ini in example) to current directory and subdirectories:

for ELE in `find . -type d -print| awk 'NR > 1 {print}'`; do ln -s ~/www/elgg1.5/php.ini ${ELE}/php.ini ; done

change permissions of files recursively so group permissions match owner permissions:

chmod -R g=u name-of-folder

change permissions of directories or files only:

find -type d -exec chmod 775 {} \;
find -type f -exec chmod 664 {} \;

copy files recursively, keeping permissions:

cd /source
tar cf - * | ( cd /target; tar xfp -)

Rip Audio from application using Pulseaudio (no Jack):

get index number of application audio:

  • pacmd
  • list-sink-inputs

assuming index is $INDEX:

  • pactl load-module module-null-sink sink_name=steam
  • pactl move-sink-input $INDEX steam
  • parec -d steam.monitor | sox -t raw -r 44k -sLb 16 -c 2 - /tmp/testme.wav 

VIDEO

transcode a video file so it is playable through Windows Media Player (Windows) and Quicktime (MacOS):

ffmpeg -i INPUT_FILE -b 1500 -ab 384k -cropleft 20 -cropright 20 OUTPUT.mpg

Record Desktop as Video:

The easy way is to use gtk-RecordMyDesktop,but functionality with gtk-RecordMyDesktopusing jackappears to be broken. So another way if you need jackis ffmpegwith x11grab:

ffmpeg -f jack -ac 2 -ab 128k -i ffmpeg -acodec pcm_s16le -f x11grab -r 30 -s 320x240 -i :0.0+0,76 -vcodec libx264 -vpre lossless_ultrafast -threads 0 /tmp/test.mkv

Notes:

  • -f jack tells ffmpeg to use jack. You could also do -f alsa
  • -i ffmpeg tells ffmpeg to name it's ports for jack ffmpeg
  • -i :0.0+0,76 tells ffmpeg to use screen :0.0 with offset X=0 Y=76
  • if the output file exists, ffmpeg will ask you if you want to overwrite the old file. That's nice, but somehow this throws off the synchronization between the audio and the video. So if you want to overwrite an existing file, delete it first.

Position of Mouse Cursor:

mousepos.py (linux only)

PRINTING

add PDF printer to ubuntu intrepid or jaunty (source):

  • sudo apt-get install cups-pdf
  • sudo chmod +s /usr/lib/cups/backend/cups-pdf
  • mkdir ~/PDF/

bmeps seems to be the only way to make a transparent PDF from a PNG file. Directions for building here.

PDF

convert a grayscale PDF to B&W with Imagemagick:

convert -threshold 75% input.pdf output.pdf

INTERNET

ssh no password: follow these instructions

vpn on Linux 64 bit: follow these instructions

Remote Desktop (VNC through SSH tunnel)

  • ssh -L 5901:localhost:5900 UserName@host.com
  • (in a separate terminal): xtightvncviewer -encodings tight localhost:1

DHCP Server and Firestarter (on 12.04)

  • sudo apt-get install dhcp3-server
  • sudo ln -s /etc/dhcp/dhcpd.conf /etc/dhcpd.conf
  • and one or more of:
  • sudo ln -s /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf
  • sudo ln -s /usr/sbin/dhcpd3 /usr/sbin/dhcpd
  • set wired (eth0 or whatever) to a manual IP address

Assign card a specific name:

Example:
udevinfo -a -p /sys/class/sound/controlC1
udevinfo -p /sys/class/tty/ttyUSB2 -a
ATTRS{modalias}=="usb:v067Bp2303d0300dc00dsc00dp00icFFisc00ip00", NAME="logochip", MODE="0666"

Backup (tar) directory and subdirectories:

tar -cvzf mytarfile.tgz mydir/

Backup database:

 
mysqldump --skip-lock-tables -h <hostname> -u <username> -p<password> <databaseName> > <filename>.sql

FONTS:

  • add ttf fonts in xubuntu by copying them into ~/.fonts (add the directory if it doesn't exist) then running sudo fc-cache -f
  • install Monaco: curl -kL https://raw.github.com/cstrap/monaco-font/master/install-font-ubuntu.sh | bash

SWAPPINESS:

  • find current value: cat /proc/sys/vm/swappiness
  • set on the fly: sudo sysctl vm.swappiness=10
  • to change permanently edit /etc/sysctl.conf as root. Then, change or add this line to the file: vm.swappiness = 10
  • The above content references this page

Convert File Ascii –> Hex: hexdump -e '16/1 “0x%02x, ” “\n”' <filename>

Unattended upgrades, security only, for 16.04

check if port is in use

sudo lsof -i:8078
  • write to dmesg: echo Some message > /dev/kmsg
  • lwc/programming/bash.1612622073.txt.gz
  • Last modified: 2021/02/06 08:34
  • by John Harrison