WELCOME TO THE OLDFOLIO GOPHER SERVER! ================== COMMAND LINE NOTES ================== 7-ZIP ----- 7za a -mhe=on -p archive-name.7z original-file a = add to archive -mhe=on = encrypt headers as well as data -p = prompt for password You can also add the switch -mx0 if you do not wish to do any compressing. For maximum compression, use: 7za -mx9 -mhe -p a archive-name.7z original-file 7z FILE SPLITTING You can use 7zip to split large files: 7z a -mx0 -v10m Archive-Name.7z Original-File-Name where a = add to archive -mx0 = do not do any compression v10m = split the original file into 10MB chunks This will create new files named Archive-Name.7z.001 Archive-Name.7z.002 Archive-Name.7z.003 etc. In order to recover the original file, type 7z e Archive-Name.7z.001 Specify ONLY the first file of the split archive. 7zip will correctly identify the other files in the collection. Note: You cannot specify decimal sizes ( -v2.5m ). So, if you wanted to create chunks that were 2.5MB in size, you would need to specify 2560k as the size ( -v2560k ). Thus, if you wish to create archives that are smaller than the 2G limit on file sizes in older versions of ext2, then you would use: 7z a -mx0 -v1842m Archive-Name.7z Original-File-Name This creates 1.8G files that should be supported by older ext2 implementations. APT --- apt-get --no-install-recommends install package-name AUTOSSH ------- Autossh is a tool for keeping SSH tunnels alive. Instead of starting a standard SSH tunnel ssh -D 5222 balsa -N you would start autossh, which will start an SSH session and then re-start it if the connection drops. autossh -f -M 5000 -D localhost:5222 -N balsa If you want to route Firefox over your tunnel, you should go to Firefox's Settings -> General -> Network Settings: SOCKS Host 127.0.0.1 Port 5222 SOCKSv5 No proxy for: localhost, 127.0.0.1, 192.168.0.0/24, 10.0.0.0/24 AUTOSSH REVERSE TUNNELS You can use autossh to start a reverse tunnel from a machine behind CGNAT with autossh -M 0 -N -f -R 20004:localhost:22 mm@216.189.157.58 -p 60 autossh -M 0 -N -f -R 20004:localhost:22 balsa Then, from any remote machine you can reach the machine with ssh -p 20004 mm@216.189.157.58 CD -- To return to the directory that you just left: cd - CHMOD ----- Recursively remove executable bit from files, while omitting directories: chmod -R -x+X target/ The capital "X" sets the executable bit on directories only. DATE ---- FreeBSD: Set the date to 5:05 pm, January 21, 2018 date 201801211705 yyyymmddhhmm If you only need to change the hours and minutes date 1705 will change the time to 5:05 pm and leave the date unchanged. DD -- Overwrite with zeroes a 133 byte file: dd if=/dev/zero of=filename count=1 bs=133 Overwrite with zeroes a 1 MB byte file: dd if=/dev/zero of=storage-bin count=1K bs=1024 Overwrite with zeroes a 1 GB byte file: dd status=progress if=/dev/zero of=storage-bin count=1024K bs=1024 dd status=progress if=/dev/zero of=storage-bin count=1M bs=1024 On my home system, /dev/zero can be used to generate a 10G file in about 45 seconds. By contrast, /dev/urandom will take about three minutes. Do not even bother with /dev/random. DIG --- Check the mx record for yandex.com at the name server dns1.yandex.net: dig mx yandex.com @dns1.yandex.net On Debian-based systems, dig is supplied by the package dnsutils. On FreeBSD, dig is supplied by the package bind-utils. DMIDECODE --------- Displays hardware information. Must be run as root. See this guide: https://www.howtoforge.com/dmidecode-finding-out-hardware-details-without-opening-the-computer-case Display memory information: dmidecode -t memory DPKG ---- List installed packages: dpkg --get-selections Show the status of package, PACKAGE: dpkg-query --status PACKAGE DU du -h --max-depth=1 DUPLICITY --------- Backup files in directory "source" to a remote server. The first time duplicity runs it will do a full backup. Subsequently, it will do an incremental backup of changes. duplicity --encrypt-key gpg-key /home/user/source sftp://host//home/user/target duplicity --encrypt-key gpg-key /home/user/source file:///home/user/local-target duplicity restore sftp://host//home/user/backup /home/user/local-restore-directory On incremental backups, some versions of duplicity will return the following error message related to GnuPG: Error processing remote manifest This is a known and benign error message that does not indicate any failures in the backup. ELINKS ------ If you enable one of the color modes, then [shift]-5 will cycle through the color schemes for that mode. You can toggle the numbering of hyperlinks with the period "." EMACS ----- My Emacs notes have their own page, or they will have once I set it up. GNUPG Encrypt to a specific user/recipient: gpg -e -r USER file.txt Create a detached, ascii-enarmored signature specifying which key to use: gpg -u key-to-use -a --output file.sig --detach-sig file.txt Create a non-detached, ascii-enarmored signature specifying which key to use: gpg -u key-to-use --clearsign file.txt Verify detached signature: gpg --verify signature.sig signed-file.txt Export public key: gpg -a --export {key-identifier} > public-key.asc Export secret/private key: gpg -a --export-secret-keys {key-identifier} > secret-key.asc If you should ever need to edit your ~/.gnupg/gpg-agent.conf file, you will need to reload the gpg-agent once you are finished editing. $ gpg-connect-agent reloadagent /bye Use extreme caution if you change the gpg-agent to pinentry-curses. Doing so breaks the graphical version of Emacs, and I have not yet found a work-around. If you will be working remotely with GnuPG encrypted files, you may need to set the agent to pinentry-curses. Otherwise, the gpg-agent will expect a graphical environment -- and fail when one is not present. HTML ESCAPE SEQUENCES & will display & < will display < > will display > You might also find this useful;

LN ln -s target-file link-name LOSETUP # losetup -a # List the status of all loop devices # losetup /dev/loop0 filename # Associate loop device 0 with file filename # losetup -d /dev/loop0 # Detach loop device NAMEBENCH Send 128 queries to only the nameservers specified: namebench -q 128 -O 208.67.222.222, 1.1.1.1, 8.8.8.8 NETHACK Some nethack commands: @ = toggle autopickup d = drop i = open inventory r = read (as in read a spellbook) t = throw (as in throw a dagger) w = wield weapon f = fire arrows in quiver using wielded bow Q = place arrows in quiver S = save your game and exit P = put on (as in put on a ring) R = remove (as in remove a ring) W = wear armor or shield T = take off armor or shield Z = cast a spell ^d = bash (as in bash a door) #chat = talk to another character #loot = open a container #force = attempt to open a locked container #untrap = rescue pet from pit Possible ~/.nethackrc OPTIONS=color,time,hilite_pet,menucolors,!autopickup,role=valkyrie,race=human #OPTIONS=color,time,role=wizard,race=elf,gender=female RSYNC rsync -avuP --delete source-directory/ host:/destination-directory Notice that the source directory HAS a trailing slash, but that the destination directory does NOT have a trailing slash. Hetzner storage boxes only recognize relative paths. So, your rsync command will need to look something like: rsync -avuP --delete local-directory/ hetzner:./directory ^ notice the dot Synchronize a single file: rsync -avuP source-directory/filename host:/destination-directory/ Notice that when synchronizing a single file a trailing slash *DOES* follow the destination directory. SECURE_DELETE (FreeBSD) / SECURE-DELETE (Debian) Overwrite and delete all files and subdirectories of DIRECTORY srm -llr DIRECTORY SMEM Report chrome or chromium total memory usage: smem -t -k -c pss -P chrom | tail -n 1 Report opera total memory usage: smem -t -k -c pss -P opera | tail -n 1 Report yandex browser total memory usage: smem -t -k -c pss -P yandex_b | tail -n 1 Report yandex disk total memory usage: smem -t -k -c pss -P yandex-d | tail -n 1 Report vivaldi total memory usage: smem -t -k -c pss -P vivaldi | tail -n 1 SSHFS If you install sshfs, you can mount your remote servers as an ordinary user. $ sshfs server-nickname:/home/username /local/mountpoint -o uid=1000,gid=1000 To unmount: $ fusermount -u /local/mountpoint SYSCTL Report hardware information on FreeBSD systems: # sysctl hw.model hw.machine hw.ncpu TAR To archive your /etc and /home directories: # tar cvf /root/etc-home.tar /etc /home To create an archive that excludes some files in the target: tar cvf ~/archive.tar --exclude='excluded-directory/*' * To list the files in an archive: tar tvf archive.tar Compression: bzip2 = j gzip = z xz = J Create an archive with a time stamp in the archive name: suffix=`date +%F-%H.%M` tar cvf /home/user/archive-$suffix.tar /path/to/target-directory/ TMUX Ctrl-b to enter commands Detach the current session: Ctrl-b d Re-attach a previous session: tmux attach -t 0 where "0" is the name of the previous session. USERMOD To change a user's primary login group: usermod -g primarygroupname username To add a user to a secondary group: usermod -a -G secondarygroupname username Using the -G switch without the -a switch will remove a user from all secondary groups except those specified by the current instance of the -G switch. VIM Find each occurrence of 'foo' and replace it with 'bar': :%s/foo/bar/g Edit a remote file: vim scp://user@server.com:22//home/user/filename or :e scp://user@server.com:22//home/user/filename Prompt for an encryption key: :X Center text [based on a 75 character-wide line]: :ce [75] Set the maximum number of characters on a line to 75 set tw=75 Various editing tasks: dd delete current line ~ switch case of characters (from CAPITALS to lower case or vice VERSA) U MAKE ALL SELECTED CHARACTERS CAPITALS/UPPER CASE u make all selected characters lower case J join next line to the current one > indent selected lines gq apply text formatting to selected region " specify a register "+ specify the clipboard "+y copy to clipboard "+d cut to clipboard "+P paste from clipboard before cursor "+p paste from clipbaord after cursor Miscellaneous echo 3 > /proc/sys/vm/drop_caches Do a searchon "drop_caches" for additional information, including the differences between echo 1, echo 2, and echo 3. File Size Comparison I keep all of my notes in a very large text file. Here is a size comparison of the notes in different formats (October 2018): RAW TEXT 2708583 bytes (100.00%) DOCX 1254433 bytes ( 46.31%) ODT 1103976 bytes ( 40.76%) GZ TEXT 1040337 bytes ( 38.41%) XZ TEXT 796340 bytes ( 29.40%) BZ2 TEXT 763485 bytes ( 28.19%) ============================ The End ============================