I’m not sure if there’s any reason to choose one or the other, but the latter example is arguably easier to remember.
All color codes:
Reset color 0 Black 0;30 Blue 0;34 Green 0;32 Cyan 0;36 Red 0;31 Purple 0;35 Brown/Orange 0;33 Light Gray 0;37 Dark Gray 1;30 Light Blue 1;34 Light Green 1;32 Light Cyan 1;36 Light Red 1;31 Light Purple 1;35 Yellow 1;33 White 1;37
You can also do lots of other things in bash, such as blinking text, bold, etc. Take a look at this site for more examples.
If you like to create CLI tools, adding some colors will make it a lot more immersive and easier to read output, like this example:
Today we’ll go over the various methods to kill a process. Can be useful especially if the process is stuck somehow and you’re having trouble closing/killing it.
Kill process with WMI queries
Open cmd.exe and run command:
wmic process where name='myprocessname.exe' delete
Batch kill in command prompt
Open cmd.exe and run command:
taskkill /IM "myprocessname" /T /F
/IM is required to pick process, but the extra parameters /T and /F are optional. They’re quite useful though:
/T = also kills child processes /F = force termination of your process
Kill it the powerful way
Indeed. You can also kill it using Powershell, but you need to find the process ID first. Open Powershell prompt and simply type
Get-Process myprocessname | Select -expand id # use the id returned in the next command: kill -id id
Kill process using graphical user interface
You’re probably familiar with Task Manager. Open it by right-clicking on the taskbar and click on “Task Manager”. If that fails, or if you need to run it as another user, you can browse to %windir%\system32\ and run the executable file, taskmgr.exe.
If you’re lucky you can just kill the process and get on with your life. But, if you want to figure out what’s wrong, then a great tip is to open the Resource Monitor and Filter by process. This will show you all disk I/O file handles related to your process so you might actually see what exactly is hanging.
As an IT tech I often have to open my command prompt as my domain administrator user which has administrator access on remote computers. I always forgets to right-click cmd and choose “Run as …” so I figured out a little shortcut for those times to mimic the su function in Linux.
Please note this won’t turn your currently open command prompt into an elevated one, it will just run a new cmd.exe process as the user you need.
Open an elevated command prompt and change directory to %windir%\system32 and run this command:
echo runas /user:domain\username "cmd" > sudo.bat
Now you can type “sudo” wherever (in your Run window or an existing cmd prompt) and it will prompt you for the password and open a new cmd window with the pre-defined user.
Follow the commands below to setup a new user and open up for remote access to a specific database on your MySQL server.
$ mysql -u root -p Enter your MySQL root password. mysql> CREATE USER 'itdb_admin'; mysql> CREATE DATABASE itdb_db; mysql> GRANT ALL PRIVILEGES ON itdb_db.* to 'itdb_admin'@'%' IDENTIFIED BY 'my-password' WITH GRANT OPTION; mysql> FLUSH PRIVILEGES; mysql> EXIT; $ sudo nano /etc/mysql/my.cnf Comment the following line by setting a # in front (to disable it): bind-address = 127.0.0.1 $ sudo service mysql restart
1) Open the MySQL CLI 2) Create a new database 3) Create a new user 4) Give the user full access to the database. Notice the '%' which means we’re talking about remote access. The same user can have different access levels based on the connection (whether it’s remote or local) 5) Flush/refresh the privileges so they become active 6) Disable bind-address so the MySQL server will listen on any source address 7) Restart the MySQL service to reload the config file