Recover Your Wi-Fi Password from Windows CLI
In case you misplaced your wi-fi password you can recover it very easily using 2 commands on Windoze:
Open the Terminal or PowerShell
PS C:\Users\user> netsh wlan show profile
The output will be similar to this. You need to obtain the User Profile of the connection that you’re interested in:
Profiles on interface Wi-Fi:Group policy profiles (read only)---------------------------------<None>User profiles-------------All User Profile : ROUTER21All User Profile : 4YWD8-5GAll User Profile : 4YWD8
Prefix The Output of Any Command with a Timestamp
You can prefix the output of every line with a timestamp by piping the command to the following sed command:
$ command | sed "s/^/\[date +"%Y%m%d%H%M%S"]/"
Create a QEMU/KVM Virtual Machine from the Command Line
You can use a combination of command line tools to create and configure a virtual machine. Here we will use few tools from the QEMU and libvirt packages to do this.
Use QEMU to create a 15GB QCOW disk image:
$ qemu-img create -f qcow2 /home/user/KVM/CentOS-Stream-9.qcow2 15GFormatting '/home/user/KVM/CentOS-Stream-9.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=16106127360 lazy_refcounts=off refcount_bits=16
Start the installation:
$ sudo virt-install --name=CentOS-Stream-9 --vcpus=1 --memory=1024 --location=/home/user/Downloads/CentOS-Stream-9-20230704.1-x86_64-boot.iso --os-variant=centos8 --network bridge:virbr0 --disk path=/home/user/KVM/CentOS-Stream-9.qcow2 --disk size=15Password:WARNING Requested memory 1024 MiB is less than the recommended 1536 MiB for OS centos8Starting install...Retrieving 'vmlinuz' | 0 B 00:00:00 ...Retrieving 'initrd.img' | 0 B 00:00:00 ...Allocating 'CentOS-Stream-9.qcow2' | 2.5 MB 00:00:03 ...WARNING Overriding memory to 3072 MiB needed for centos8 network install.Creating domain... | 0 B 00:00:00Running graphical console command: virt-viewer --connect qemu:///system --wait CentOS-Stream-9
Using passwordgen On Slackware
The well known ss64.com site has a lot of useful tips and tricks for *nix users and they also have a script that you can download which will create and maintain passwords for you.
If you go to their command line section you can use the link to their GitHub site and download it for yourself. However, when I followed their installation instructions I ran into difficulty because the script has a dependency on pbcopy or gclip (which wasn’t documented) and since I run Slackware 15.0 the copy to clipboard feature failed.
Rename Files That Start With a Special Character
Suppose you find that you have a file with a special character and you want to delete it:
$ ls-badfile.txt PrintHood reg57.txtFavorites Recent scripts$ rm -badfile.txtrm: invalid option -- 'b'Try 'rm ./-badfile.txt' to remove the file '-badfile.txt'.Try 'rm --help' for more information.$ ls *.txtls: invalid option -- 'e'Try 'ls --help' for more information.
scp'ing Files using a Text File List
If you have a collection of files that you want to transfer to a remote server and they are a subset of files in the current directory or scattered among different directories you can create a list of files and then pipe the list to scp:
$ cat filelist.txt | xargs -i scp {} user@remote:~/backup/
How to recursively find the latest modified file in a directory
find . -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "
Bind to a Remote Port Using SSH
If you are trying to access the web page of an application running on a remote machine and you find that you are blocked, you can bind to it using SSH with similar parameters to this:
$ ssh pi@raspberrypi.local -L 8384:127.0.0.1:8384 -N
Where:
pi@raspberrypi.localis the remote server,8384is the port number on the remote that you wish to connect with,127.0.0.1:8384is the local machine and the port that you want to redirect to, and-Nis a flag tellingsshnot to execute a remote command.
Using Tar with a Text Input File
If you have a lot of files in a directory and you only need to tar a subset of them you can create a list of the files you want in a text file and pass it to the tar command like this:
$ tar -cvf tarball.tar -T filelist.txt
or
$ tar cvf tarball.tar $(cat filelist.txt)
Command Line Redirection
Redirection is very significant in shell scripting. It provides you a means to save the output of a command to a file or multiple files (one for stdout and one for stderr).
Below is a table of simple redirections that are the most useful in shell scripting. Here we are using the following naming conventions:
stdout– The output of the script/commandstderr– The errors generated by the script/commandoutfile– A target filename where you wish to store the outputerrfile– A target filename where you wish to store the errors
Command Description/Purpose command 2>errfile Redirect stderr to errfile command >outfile 2>errfile Redirect stderr to file named errfile and stdout to file named outfile command &> outfile Redirect stderr and stdout to outfile command 2>&- Just suppress error messages. No file created. No error message displayed on screen command 2>&1 Redirect error messages to standard output. Useful in shell script when you need to forcefully display error messages on screen