Articles in the Solutions category

  1. Clear a Line in Bash

    In Windows, I'm used to being able to clear a line simply by hitting Esc, but it's not quite as easy from Bash.

    • You can use Ctrl+U to clear up to the beginning.
    • You can use Ctrl+W to delete just a word.
    • You can also use Ctrl+C …
  2. Using `wget` and `zip` to Archive a Website

    The command is long but easy enough:

    wget --recursive --page-requisites --html-extension --convert-links --restrict-file-names=windows --domains calculusmadeeasy.org --no-parent http://calculusmadeeasy.org/
    
    • --recursive: download the entire Web site.
    • --domains website.org: don't follow links outside website.org.
    • --no-parent: don't follow links outside the directory tutorials/html/.
    • --page-requisites: get all the elements …
  3. Linux SSH Key Permissions Error

    When moving an SSH key to my cloud dev server, I ran in to this error:

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    Permissions 0644 for '~/.ssh/id_rsa' are too open.
    It is required that your private key files are NOT accessible by others.
    This private key will be ignored.
    Load key …
  4. Zero Padding Filenames

    I always hate when filename ordering gets screwed up because numbers aren't handled properly (1.txt, 10.txt, 2.txt, etc.), so the easy solution is to zero-pad the numbers. Renaming a bunch of files to add some zeros is no fun though, so here's some solutions.

    On Ubuntu, there's …

  5. Quickly Add Permanent Bash Alias

    To make my life easier on my development box, I used this super simple bash oneliner to set up permanent aliases: echo 'alias python='python3'' >> ~/.bashrc. This writes a new line, containing the text within the quotes, to the bottom of the .bashrc file. This is loaded everytime bash is …

  6. Multiple Subprocess Calls Made Easy

    This is a very neat solution I figured out to calling subprocess on a bunch of commands easily with a loop.

    The key here is the split(), this will break down the command in to a list, which is the format subprocess needs, without manually formatting it. I use shlex …

  7. Generating Secure Strings (Passwords) on Linux

    Recently, I was separated from my usual password manager (KeePass w/ a synchronized database) and needed to generate a random password to add to my database later. Luckily, I had sudo access to a Linux command line, so this was as easy as running sudo apt-get install pwgen and pwgen …

  8. ipconfig /all in PowerShell

    Quick and dirty one, I was looking for an alternative to ipconfig /all that worked with invoke-command. This works on IPv4 and IPv6 and includes both tunnel and cluster adapters. This does not work on Server 2008 R2 even with WMF 5+.

    Get-NetIPAddress
    

    More Info:

  9. Rebuild the PowerShell Virtual Directory in Exchange

    If you're a dumb-ass like me who tends to make changes faster than he thinks them through, you may have screwed up the PowerShell virtual directory in Exchange and want (or need) to rebuild it and set things back to default. You should absolutely, under no circumstances, do this from …

  10. PowerShell Cleanup Subfolders

    Want to delete a bunch of empty subfolders? Or maybe move all the files first? In PowerShell it's super easy.

    # Move all files in subfolders of source to destination
    Get-ChildItem -Path source -Recurse -File | Move-Item -Destination destination
    # Delete all empty folders in source
    Get-ChildItem -Path source -Recurse -Directory | Remove-Item
    

    Note …

  11. Download Files With PowerShell

    This blog post on the topic is phenomenal, but I'll briefly summarize it. Theres three method to download a file with PowerShell: Invoke-WebRequest, System.Net.WebClient, and Start-BitsTransfer. All have pros and cons; Invoke-WebRequest is built-in and very simple but requires Internet Explorer and is very slow, System.Net.WebClient …

  12. Get Installed Programs in PowerShell

    This is something is something that can be done multiple ways, none of which are straightforward and all with their own drawbacks. This leads me to believe it must be some sort of legacy issue. In my experience the easiest way to do it while also ensuring you get all …

  13. touch Command in PowerShell

    Unix/Linux has a very convenient command for making an empty file at the specified path called touch. PowerShell can imitate this by using New-Item.

    New-Item -ItemType file <filename>
    
    # Example: creating the PowerShell profile. -Force is required to make the full path.
    New-Item -ItemType file $profile -Force
    

    New-Item can also …

  14. System Image Backup from Command Line

    wbAdmin start backup -backupTarget:<drive to save backup to> -include:<drive to save backup of> -allCritical -quiet
    

    -allCritical will make sure all system state and system drives is captured if you back up the OS drive. -quiet just ensures there is no user prompt.

    More Info:

  15. Check Disk in PowerShell

    I use check disk as one of my basic troubleshooting tools. Here's the new PowerShell commands that serve the same purpose with the advantage of all PowerShell features. My favorite part of this command is that it's much faster than the original.

    # chkdsk /f
    Repair-Volume -DriveLetter H -Scan
    
    # chkdsk /scan …
  16. DISM Image Repair in PowerShell

    DISM has saved many an online image (i.e the one running on my PC) the past few years. Here's those commands in a much easier to remember PowerShell format.

    # Dism.exe /Image:<...> /Cleanup-Image /ScanHealth
    Repair-WindowsImage -ScanHealth
    
    # Dism.exe /Image:<...> /Cleanup-Image /RestoreHealth
    Repair-WindowsImage -RestoreHealth
    

    More Info: