lwc:programming:bash

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
lwc:programming:bash [2020/11/26 22:25] – created John Harrisonlwc:programming:bash [2024/09/27 12:48] (current) – [Superuser] John Harrison
Line 1: Line 1:
-**Comments:** +==== Comments: ====
- +
-<HTML><blockquote> +
-Put: : <'COMMENTBLOCK_ORWHATEVERYOUWANTTOCALLME' +
- +
  
 +Put: : ''<'COMMENTBLOCK_ORWHATEVERYOUWANTTOCALLME'''
  
 before the block and put: before the block and put:
  
- +''COMMENTBLOCK_ORWHATEVERYOUWANTTOCALLME''
-COMMENTBLOCK_ORWHATEVERYOUWANTTOCALLME+
  
  
 after the block after the block
  
- +==== DISPLAY SETTINGS: ====
-\\ +
- +
-</blockquote></HTML> +
-**DISPLAY SETTINGS:** +
   * xrandr example: xrandr --output HDMI1 --mode 1280x1024 --right-of eDP1   * xrandr example: xrandr --output HDMI1 --mode 1280x1024 --right-of eDP1
   * change 1280x1024 display to 1600x1280:xrandr --output DP-1 --scale 1.25x1.25 --panning 1600x1280   * change 1280x1024 display to 1600x1280:xrandr --output DP-1 --scale 1.25x1.25 --panning 1600x1280
   * shift display down 1280 pixels: xrandr --output eDP-1 --mode 1920x1080 --pos 0x1280   * shift display down 1280 pixels: xrandr --output eDP-1 --mode 1920x1080 --pos 0x1280
  
-**FILE MANAGEMENT** +==== FILE MANAGEMENT ====
- +
-\\ +
  
 Count # of files in a directory (recursively): Count # of files in a directory (recursively):
  
-<HTML><blockquote>+<code>
 ll -R | grep -v "\(total \)" | grep -v "\.\?[/]$" | grep -v "^$" | wc -l ll -R | grep -v "\(total \)" | grep -v "\.\?[/]$" | grep -v "^$" | wc -l
-</blockquote></HTML> +</code>
-\\ +
  
 List files recursively by date: List files recursively by date:
  
-<HTML><blockquote>+<code>
 find . -printf "%T@ %Tc %p\n" | sort -n find . -printf "%T@ %Tc %p\n" | sort -n
- 
  
 printf arguments from man find: printf arguments from man find:
- 
     %Tk: File's last modification time in the format specified by k.     %Tk: File's last modification time in the format specified by k.
- 
     @: seconds since Jan. 1, 1970, 00:00 GMT, with fractional part.     @: 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).     c: locale's date and time (Sat Nov 04 12:02:33 EST 1989).
- 
     %p: File's name.     %p: File's name.
- +</code>
- +
-\\ +
- +
-</blockquote></HTML>+
  
 Add symbolic link to file (~/www/elgg1.5/php.ini in example) to current directory and subdirectories: Add symbolic link to file (~/www/elgg1.5/php.ini in example) to current directory and subdirectories:
  
-<HTML><blockquote>+<code>
 for ELE in `find . -type d -print| awk 'NR > 1 {print}'`; do ln -s ~/www/elgg1.5/php.ini ${ELE}/php.ini ; done for ELE in `find . -type d -print| awk 'NR > 1 {print}'`; do ln -s ~/www/elgg1.5/php.ini ${ELE}/php.ini ; done
 +</code>
  
-\\ 
- 
-</blockquote></HTML> 
 change permissions of files recursively so group permissions match owner permissions: change permissions of files recursively so group permissions match owner permissions:
  
-<HTML><blockquote>+<code>
 chmod -R g=u name-of-folder chmod -R g=u name-of-folder
-</blockquote></HTML> +</code>
-\\ +
  
 change permissions of directories or files only: change permissions of directories or files only:
  
-<HTML><blockquote>+<code>
 find -type d -exec chmod 775 {} \; find -type d -exec chmod 775 {} \;
- 
- 
 find -type f -exec chmod 664 {} \; find -type f -exec chmod 664 {} \;
- +</code>
-</blockquote></HTML> +
-\\ +
  
 copy files recursively, keeping permissions: copy files recursively, keeping permissions:
  
-<HTML><blockquote>+<code>
 cd /source cd /source
- 
 tar cf - * | ( cd /target; tar xfp -) tar cf - * | ( cd /target; tar xfp -)
 +</code>
  
-\\ +==== Rip Audio from application using Pulseaudio (no Jack): ====
- +
-</blockquote></HTML> +
-**Rip Audio from application using Pulseaudio (no Jack):** +
- +
-\\ +
- +
 get index number of application audio: get index number of application audio:
- 
   * pacmd   * pacmd
   * list-sink-inputs   * list-sink-inputs
- 
  
 assuming index is $INDEX: assuming index is $INDEX:
  
-  * pactl load-module module-null-sink sink_name=steam +  * ''pactl load-module module-null-sink sink_name=steam'' 
-  * pactl move-sink-input $INDEX steam +  * ''pactl move-sink-input $INDEX steam'' 
-  * parec -d steam.monitor | sox -t raw -r 44k -sLb 16 -c 2 - /tmp/testme.wav +  * ''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'' 
-**VIDEO** +==== VIDEO ====
- +
-\\ +
  
 **transcode a video file so it is playable through Windows Media Player (Windows) and Quicktime (MacOS):** **transcode a video file so it is playable through Windows Media Player (Windows) and Quicktime (MacOS):**
  
-\\ +<code>
- +
- +
-<HTML><blockquote>+
 ffmpeg -i INPUT_FILE -b 1500 -ab 384k -cropleft 20 -cropright 20 OUTPUT.mpg ffmpeg -i INPUT_FILE -b 1500 -ab 384k -cropleft 20 -cropright 20 OUTPUT.mpg
-</blockquote></HTML> +</code>
-**\\ +
-**+
  
-**Record Desktop as Video:**+==== 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: 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:
  
-\\ +<code>
- +
- +
-<HTML><blockquote>+
 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 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
-</blockquote></HTML> +</code>
-\\ +
  
 Notes: Notes:
Line 153: Line 98:
   * 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.   * 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:**+==== Position of Mouse Cursor: ====
  
- +<code>
- +
-<HTML><blockquote>+
 mousepos.py (linux only) mousepos.py (linux only)
 +</code>
  
- +==== PRINTING ====
-</blockquote></HTML> +
-\\ +
- +
- +
-**PRINTING** +
- +
-\\ +
  
 add PDF printer to ubuntu intrepid or jaunty (source): add PDF printer to ubuntu intrepid or jaunty (source):
Line 175: Line 111:
   * sudo chmod +s /usr/lib/cups/backend/cups-pdf   * sudo chmod +s /usr/lib/cups/backend/cups-pdf
   * mkdir ~/PDF/   * mkdir ~/PDF/
- 
  
 bmeps seems to be the only way to make a transparent PDF from a PNG file. Directions for building here. bmeps seems to be the only way to make a transparent PDF from a PNG file. Directions for building here.
  
-\\ +==== PDF ====
- +
- +
-**PDF** +
- +
-\\ +
  
 convert a grayscale PDF to B&W with Imagemagick: convert a grayscale PDF to B&W with Imagemagick:
  
- +<code>
- +
-<HTML><blockquote>+
 convert -threshold 75% input.pdf output.pdf convert -threshold 75% input.pdf output.pdf
 +</code>
  
 +determine resolution of images inside a pdf: ''pdfimages -list EXAMPLE.pdf''
 +==== INTERNET ====
  
- +  * **ssh no password:** follow [[http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/|these]] instructions 
-\\ +  **vpn on Linux 64 bit**: follow [[http://kb.mit.edu/confluence/display/istcontrib/Cisco+AnyConnect+Certificate+Error+on+Linux|these]] instructions 
- +  **Remote Desktop (VNC through SSH tunnel)** 
-</blockquote></HTML> +    * ssh -L 5901:localhost:5900 UserName@host.com 
-**INTERNET** +    * (in a separate terminal): xtightvncviewer -encodings tight localhost:
- +  * 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'' 
- +
-**ssh no password:** follow [[http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/|these]] instructions +
- +
-\\ +
- +
- +
-**vpn on Linux 64 bit**: follow [[http://kb.mit.edu/confluence/display/istcontrib/Cisco+AnyConnect+Certificate+Error+on+Linux|these]] instructions +
- +
-\\ +
- +
- +
-**Remote Desktop (VNC through SSH tunnel)** +
- +
-  * ssh -L 5901:localhost:5900 UserName@host.com +
-  * (in a separate terminal): xtightvncviewer -encodings tight localhost:+
  
 **DHCP Server and Firestarter (on 12.04)** **DHCP Server and Firestarter (on 12.04)**
- 
   * sudo apt-get install dhcp3-server   * sudo apt-get install dhcp3-server
   * sudo ln -s /etc/dhcp/dhcpd.conf /etc/dhcpd.conf   * sudo ln -s /etc/dhcp/dhcpd.conf /etc/dhcpd.conf
Line 232: Line 145:
 **Assign card a specific name:** **Assign card a specific name:**
  
- +<code>
-<HTML><blockquote>+
 Example: Example:
- 
- 
 udevinfo -a -p /sys/class/sound/controlC1 udevinfo -a -p /sys/class/sound/controlC1
- 
- 
 udevinfo -p /sys/class/tty/ttyUSB2 -a udevinfo -p /sys/class/tty/ttyUSB2 -a
- 
- 
 ATTRS{modalias}=="usb:v067Bp2303d0300dc00dsc00dp00icFFisc00ip00", NAME="logochip", MODE="0666" ATTRS{modalias}=="usb:v067Bp2303d0300dc00dsc00dp00icFFisc00ip00", NAME="logochip", MODE="0666"
 +</code>
  
 +**Backup (tar) directory and subdirectories:**
  
-\\ +<code>
- +
-</blockquote></HTML> +
-**Backup (tar) directory and subdirectories:** +
-<HTML><blockquote>+
 tar -cvzf mytarfile.tgz mydir/ tar -cvzf mytarfile.tgz mydir/
 +</code>
  
-\\ 
- 
-</blockquote></HTML> 
 Backup database: Backup database:
  
-<HTML><blockquote> +<code
- +
 mysqldump --skip-lock-tables -h <hostname> -u <username> -p<password> <databaseName> > <filename>.sql mysqldump --skip-lock-tables -h <hostname> -u <username> -p<password> <databaseName> > <filename>.sql
 +</code>
  
-</blockquote></HTML> +FONTS:
-\\ +
- +
- +
-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   * 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   * install Monaco: curl -kL https:%%//%%raw.github.com/cstrap/monaco-font/master/install-font-ubuntu.sh | bash
  
 **SWAPPINESS**: **SWAPPINESS**:
- 
- 
   * find current value: cat /proc/sys/vm/swappiness   * find current value: cat /proc/sys/vm/swappiness
   * set on the fly: sudo sysctl vm.swappiness=10   * set on the fly: sudo sysctl vm.swappiness=10
Line 281: Line 176:
 Convert File Ascii --> Hex: hexdump -e '16/1 "0x%02x, " "\n"' <filename> Convert File Ascii --> Hex: hexdump -e '16/1 "0x%02x, " "\n"' <filename>
  
 +[[https://www.howtoforge.com/tutorial/how-to-setup-automatic-security-updates-on-ubuntu-1604/|Unattended upgrades, security only, for 16.04]]
  
-\\ +=== check if port is in use ===
- +
- +
-[[https://www.howtoforge.com/tutorial/how-to-setup-automatic-security-updates-on-ubuntu-1604/|Unattended upgrades, security only, for 16.04]]+
  
 +<code>sudo lsof -i:8078</code>
 +==== Superuser ====
 +=== Execute sudo cmd without needing to type password ===
 +== Staying Safe ==
 +  - backup ''/etc/sudoers'' file i.e. copy to somewhere safe
 +  - leave at least one terminal window open as root
 +  - 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''
 +===== Misc =====
 +   * 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 '*'`''
 +   * [[https://tldp.org/LDP/abs/html/tabexpansion.html|autocomplete parameters in bash script]]
 +   * 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.1606451155.txt.gz
  • Last modified: 2020/11/26 22:25
  • by John Harrison