Linux

commands
  • Find duplicates: fdupes (fdupes . -r > ~/duplicates.dat)
tar
  • create archive:
       tar -cvf name-of-archive.tar /path/to/directory-or-file
  • create archive with compression:
       tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
  • create archive and delete files after archive would be created
       tar -cvf name-of-archive.tar.gz --remove-files /path/to/directory-or-file
rsync
  • rsync by default uses ssh to transfer files between machines
  • --remove-source-files - To MOVE files from one machine to another (delete source after moving file) use:
       rsync --remove-source-files <source> <destination >
    where destination is another directory or another directory on another machine
  • --partial This is another switch that is particularly useful when transferring large files over the internet. If rsync gets interrupted for any reason in the middle of a file transfer, the partially transferred file is kept in the destination directory and the transfer is resumed where it left off once the rsync command is executed again. When transferring large files over the internet (say, a couple of gigabytes), theres nothing worse than having a few second internet outage, blue screen, or human error trip up your file transfer and having to start all over again.
  • -P this switch combines --progress and --partial, so use it instead and it will make your rsync command a little neater.
  • -z or --compress This switch will make rsync compress file data as its being transferred, reducing the amount of data that has to be sent to the destination. Its actually a fairly common switch but is far from essential, only really benefiting you on transfers between slow connections, and it does nothing for the following types of files: 7z, avi, bz2, deb, g,z iso, jpeg, jpg, mov, mp3, mp4, ogg, rpm, tbz, tgz, z, zip.
  • -h or --human-readable - If youre using the --progress switch, youll definitely want to use this one as well. That is, unless you like to convert bytes to megabytes on the fly. The -h switch converts all outputted numbers to human-readable format, so you can actually make sense of the amount of data being transferred.
vi
  • Join two lines: J ([shift] J)
  • Display status line: ^g
  • Undo: u
  • Write part of the file: :12,15w NewFileName
  • Forward search: /string
  • Backward search: ?string
date
  • date +"%Y-%m-%d %T"
    The result:
       2017-06-27 14:30:18
aria2c
autossh
Autossh is a program to start a copy of ssh and monitor it, restarting it as necessary should it die or stop passing traffic.
Typical use:
   autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" pi@hampton.ddns.net -L 4000:localhost:3389
Details
crontab
  • crontab file location: /var/spool/cron/crontabs. Each user has separate file
  • timing syntax: <minute> <hour> <day of month> <month> <day of week>
    Example:
       10 * * * * /usr/bin/php /www/virtual/username/cron.php > /dev/null 2>&1
  • You can use multiple numbers separated by commas. E.g.: to run three times every hour, at minutes 0, 10 and 20:
       0,10,20 * * * * [command]
  • Division operator is also used. This will run 12 times per hour, i.e. every 5 minutes:
       */5 * * * * [command]
  • Dash can be used to specify a range. This will run once every hour between 5:00am and 10:00am:
       0 5-10 * * * [command]
  • Also there is a special keyword that will let you run a cron job every time the server is rebooted:
       @reboot [command]
Details
ntfs-3g
To enaable read/write access to NTFS device, install ntfs-3g package:
sudo apt-get update
sudo apt-get install ntfs-3g
Then you will need to power cycle the Raspberry Pi. I'm not yet sure why there is a difference between a reboot and a power cycle, but you must power cycle the Raspberry Pi. That means turn it off, wait 5+ seconds, then turn it back on. Since my drive was powered by the same USB hub-thingey as my Pi, I used the switch to turn off the Pi and the drive, waited 5 seconds, and then turned both of them back on.
Details
NFS

Windows

Linux
Virtual Linux on Windows
diskpart
Youtube instructions
  1. Start diskpart as administrator
       start cmd ad administrator and type diskpart
  2. type list disk
       progran will diskpay list of physical disks attached to the computer
  3. Select disk which you are going to mess
        in my case it is "Disk 1"
    type: select disk 1
  4. CHECK THAT YOU SELECTED correct disk
       detail disk
       program will display information about selected disk - check it
  5. Delete all partitions:
       clean
  6. create partition primary
  7. active
  8. format fs=ntfs quick (instead of ntfs can be another format)
  9. exit

HTML

Python

Video Processing

ffmpeg/avconv
  • How to rotate mp4 movie using ffmpeg
    ffmpeg -i original.mp4 -vf "transpose=1" -codec:v libx264 -preset slow -crf 25 -codec:a copy flipped.mp4
    options for transpose:
    • 0 = 90CounterCLockwise and Vertical Flip (default)
    • 1 = 90Clockwise
    • 2 = 90CounterClockwise
    • 3 = 90Clockwise and Vertical Flip
  • How to remove one sound track (e.g. Russian) from mp4 file
    First run ffmpeg -i file.mp4 to see which streams exists in your file. You should see something like this:
    Stream #0.0: Video: mpeg4, yuv420p, 720x304 [PAR 1:1 DAR 45:19], 23.98 tbr, 23.98 tbn, 23.98 tbc
    Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 384 kb/s
    Stream #0.2: Audio: ac3, 48000 Hz, 5.1, s16, 384 kb/s
    Then run:
       ffmpeg -i file.mp4 -map 0:0 -map 0:2 -acodec copy -vcodec copy new_file.mp4
    to copy video stream and 2nd audio stream to new_file.mp4
  • Concatenate two mp4 file
    #!/bin/sh
    avconv -i $1 -c copy -bsf:v h264_mp4toannexb -f mpegts temp1.ts
    avconv -i $2 -c copy -bsf:v h264_mp4toannexb -f mpegts temp2.ts
    avconv -f mpegts -i "concat:temp1.ts|temp2.ts" -c copy -bsf:a aac_adtstoasc output.mp4
  • Converting h.264 to h.265 without quality loss
    Details - For now I do not need it: h.265 files with the same quality are smaller but on RPi3 they are a bit choppy. May be with next generation of RPi or new RPi competetors (which have h.265 decoders on board) I'll start conversion.
  • Converting MKV to MP4 with the same quality
    Details:
    ffmpeg -i LostInTranslation.mkv -codec copy LostInTranslation.mp4

    Here, you are copying the video codec and audio codec so nothing is being encoded.

    for i in *.mkv; do
       ffmpeg -i "$i" -codec copy "${i%.*}.mp4"
    done
  • avconv with h.265 installation (apt-get installes version of avconv without h.265 support). To install full version:
    1. Install latest version of yasm
    2. Install pkg-config
    3. Install Kvazaar
    4. Install x265 (https://bitbucket.org/multicoreware/x265/wiki/Home)
    5. Install avconv (https://wiki.libav.org/Encoding/hevc):
      ./configure --enable-libx265 --enable-gpl --enable-libkvazaar
      make
      make check
      sudo make install
    6. Add to .bashrc: # export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH #
Handbrake
VirtualDub
The same operations can be done using AviDemux (which works not only with avi, but with mp4 files)
  • Splitting avi file (Cut avi with VirtualDub)
    1. Set Video: Direct Stream Copy
    2. Set Audio: Direct Stream Copy
    3. Set start and end of the clip
    4. File -> Save Avi as
  • Join avi files (Join avi files with VirtualDub)
    1. pen first avi file: File -> Open Avi
    2. Scroll to the end of the Video File
    3. Append second avi file: File -> Append Avi Segment
    4. Save Avi as