[BASH] Windows Integrated Ubuntu Terminal Cheat Sheet

A Software › Vim cheat sheet in English by jigoubigoulai

Some small tips on the basic of WSL 2 (Windows' Ubuntu). Try to create your very first PowerShell (bash).

7,250 views 2,144 downloads 3 Dec 2022 History

Script

This cheatsheet uses these norms :
separation in parts Header, Declar­ation, Input parameter, Process, Cleaning

variables uppercase

Example of a script

**#!/bin/bash**
**#MoveFiles**
**#param 1: Directory of the file**
**#param 2: Final directory**

**#Author : Jigoubigoulai**
**#Date   : 11.01.2019**

shopt -s -o nounset

**#Part 2: Declaration**
declare FILEDIRECTORY
declare FINALDIRECTORY



**#Part 3: Input Parameters**

if test $# -ne 2; then
        echo "$0 is the name of the script"
        echo "$1 is the directory of the file"
        echo "$2 is the directory where you want to move your file."
        echo "The directories must be absolut."
        echo "This script only uses two parameters (excluding $0)"
        echo "Example : ./MoveFiles.sh /mnt/c/Users/"
fi


FILEDIRECTORY = $1
FINALDIRECTORY = $2

**#Part 4: Process**
mv $1 $2

**#Part 5: Cleaning**
unset FILEDIRECTORY
unset FINALDIRECTORY

Useful commands

Command
Explan­ation
Example
cd
Moves to a directory
cd /mnt/c­/Users/
pwd
Shows current directory
-
chmod
Change permis­sions
chmod 755 script.sh
vim
Opens VIM editor
vim script.sh

Direct­ories in bash

Desktop
/mtn/c­/Us­ers­/<U­ser­Nam­e>/­Desktop

Check parameters

Check if the number of parameters is correct

if test $# -ne 1; then
 ­ ­ echo "­Usage: $0 value"
 ­ ­ exit -1
fi

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.