lwc:programming:bash

Put: : <'COMMENTBLOCK_ORWHATEVERYOUWANTTOCALLME'

before the block and put:

COMMENTBLOCK_ORWHATEVERYOUWANTTOCALLME

after the block

  • 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

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 -)

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

Alternative: With ffmpeg

  • pactl list short sources and copy the one that has the word monitor in it
    • example: alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
  • example cmd: ffmpeg -f pulse -i alsa_output.pci-0000_00_1f.3.analog-stereo.monitor -ac 2 recording.m4a

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

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.
mousepos.py (linux only)

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.

convert a grayscale PDF to B&W with Imagemagick:

convert -threshold 75% input.pdf output.pdf

determine resolution of images inside a pdf: pdfimages -list EXAMPLE.pdf

  • 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
  • ssh to a host through another (jump) host
    • use -J i.e. ssh -J user@jumphost user@host
    • also works for scp i.e. scp -J user@jumphost file user@host

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

Execute sudo cmd without needing to type password

Staying Safe
  1. backup /etc/sudoers file i.e. copy to somewhere safe
  2. leave at least one terminal window open as root
  3. edit /etc/sudoers with visudo not sudo. It's a wrapper for your already configured editor (not necessarily vi)
The Magic
  • create a wrapper script that does all your magic for you. Don't add sudo to the cmds in the wrapper script
  • using visudo add to the end of your /etc/sudoers file USERNAME ALL=(ALL:ALL) NOPASSWD: FULL_PATH_TO_SCRIPT substituting in USERNAME and FULL_PATH_TO_SCRIPT as necessary
  • to execute the cmd without password type sudo FULL_PATH_TO_THE_SCRIPT
  • write to dmesg: echo Some message > /dev/kmsg
  • add timestamp to log entries that are piped. Add to pipe: gawk '{ print strftime(), $0; fflush() }'
    • awk is supposed to do this but at least when then piping to grep only gawk worked.
  • remove package with all its dependencies. As root: apt-get purge `apt-get -s purge <PKG> | grep '^ ' | tr -d '*'`
  • traverse through to see what is using disk space: du -cha --max-depth=1 /var | grep -E "M|G"
  • find out what app is on a particular port: netstat -anpe | grep "1234" | grep "LISTEN"
  • lwc/programming/bash.txt
  • Last modified: 2024/09/27 12:48
  • by John Harrison