Remember that the command line is really just a launch pad for other programs, with the added state of being “in” a specific directory.
Make yourself a cheat sheet of all the commands you will want to use regularly. For example:
WINDOWS LINUX MEANING
cd .. cd .. change to parent directory
cd quux cd quux change to "quux" subdirectory
cd \Users\FurryGuy cd ~ change to my home directory
dir ls list all files in directory
copy con quux.txt cat > quux.txt copy typed text to a new/overwritten file
^Z Enter ^D stop copying typed text
pushd quux pushd quux save current directory and change to quux
popd popd change back to saved directory
more quux.txt less quux.txt view file
md quux mkdir quux create a subdirectory named "quux"
rd quux rmdir quux delete an (empty) subdirectory named "quux"
del quux.txt rm quux.txt delete the file "quux.txt"
copy quux.txt hello.txt cp quux.txt hello.txt duplicate the file "quux.txt" into a new file "hello.txt"
exit exit end the console/terminal session |
And so on.
BTW, "^C" means Ctrl+C.
Controlling your PATH is paramount to using the console/terminal effectively.
Create a directory under your profile named "bin":
> cd \Users\FurryGuy
C:\Users\FurryGuy> md bin
C:\Users\FurryGuy> cd bin
C:\Users\FurryGuy\bin> dir
[.]
[..]
0 files
C:\Users\FurryGuy\bin> |
Now you want to add some aliases to help you at the command line.
C:\Users\FurryGuy\bin> copy con prompt.bat
@echo off
cls
:: All our utilities in ~/bin come first!
path C:\Users\FurryGuy\bin;%PATH%
:: This modifies how files are displayed to you when you type 'dir'
:: Order by name, grouping directories first
set DIRCMD=/ogn
:: These are your preferred macro aliases.
:: Here are a couple to get you started
doskey deltree=rd/s/q $*
doskey dird=dir/ad $*
doskey dira=dir/ah $*
doskey 7z="C:\Program Files\7-Zip\7z.exe" $*
doskey hxd="C:\Program Files (x86)\HxD\HxD.exe" $*
doskey npp="C:\Program Files (x86)\Notepad++\Notepad++" $*
doskey mcd=@md $* $T @cd $*
doskey mpath=for %A in ("%PATH:;=";"%") do @if not "%~A"=="" @echo %~A
^Z Enter
C:\Users\FurryGuy\bin> |
As displayed, you can make various utilities very useful. I have 7-Zip installed in "Program Files", but HxD and Notepad++ in "Program Files (x86)". You must, obviously, provide the correct path to the programs you intend to have available and useful from the command-line.
Here’s an update to our cheat sheet:
7z a quux.7z quux Zip the "quux" directory into an archive named "quux.7z"
7z x quux.7z Unzip the "quux" archive
7z l quux.7z List the contents of the "quux" archive
hxd quux.dat Use HxD to examine the binary file "quux.dat"
npp quux.cpp Use Notepad++ to edit "quux.cpp"
mcd quux Make a subdirectory named "quux" and change to it
mpath List all the directories in the %PATH%, in order, one directory per line |
Now to add a shortcut to start your prompt.
1. Using Windows Explorer, navigate to your new C:\Users\FurryGuy\bin directory.
2. Right click and choose "New Shortcut"
3. Type "cmd.exe" in the box and click "Next"
4. Name your shortcut something convenient (like "Console") and click "Finish"
5. Right-click on the shortcut icon and click "Properties"
6. Make sure the "Target" reads as: "C:\Windows\System32\cmd.exe /K C:\Users\FurryGuy\bin\prompt.bat"
7. Set the "Start In" directory to "C:\Users\FurryGuy"
8. Click "OK".
9. Right-click the shortcut icon and click "Pin to Taskbar"
Now you can easily start a console session. Do so now.
Click the titlebar icon and choose "Properties".
Play with the options until you get the console to start up the way you like. For mine:
Options:
[x] Quick Edit Mode
[x] Insert Mode
Font:
Size: 16
Font: Consolas (or Lucida Console/Unicode)
Layout:
Set it to where you would like to see it and UNclick "Let System Position Window"
I have mine set to use up most of the display, and aligned so that I can slam my mouse
to the right side of the screen and frob the scrollbar.
Click "OK" and if it asks if you want to apply the changes to all future invocations, choose
yes.
Type "exit" to terminate the console window.
I recommend you get a few GNU programs (like GNU "less" for Win32) and unzip them in your bin directory.
Setting up the MSYS2 is a similar process. Click on your MSYS2 icon (which you should have added to your Quick Launch as well) and it will dump you in your "Linux" home directory (which is on your C: drive as "C:\msys64\home\FurryGuy").
Type the following:
$ cat >> .bashrc
source %HOME/.profile
^D |
That adds the ".profile" file (analogous to our "prompt.bat") to our MSYS2 startup. Now to create it.
First, I want to modify the prompt. I already know who I am and what machine I am using, but I still want pretty colors and to know what directory I am in. The PS1 variable is admittedly a bit scary-looking. You can read more about it at
http://ss64.com/bash/syntax-prompt.html and
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/index.html. Or just use the fancy wizard at
https://www.kirsle.net/wizards/ps1.html.
$ cat > .profile
# prompt
export PS1='\n\[\033]0;\033[33m\]\w \[\033[32m\]\$\[\033[37m\] '
# aliases
alias dir='ls -CF'
alias dira='ls -CFa'
dird () { # Make 'dird' command without
if [ -n "$*" ] # any arguments default to:
then #
ls -Cd "$@" # dird */
else
ls -Cd */
fi
}
alias cls=clear
alias copy=cp
alias del=rm
alias deltree='rm -r -f'
alias md=mkdir
alias move=mv
alias rd=rmdir
alias ren=mv
alias 7z='/c/Program\ Files/7-Zip/7z.exe'
alias hxd='/c/Program\ Files\ \(x86\)/HxD/HxD.exe'
alias npp='/c/Program\ Files\ \(x86\)/Notepad++/Notepad++'
^D |
And so on.
A lot of these aliases are just to add “DOS”-style commands to the *nix prompt. Remember, though, it’s just a façade. If you spend much time with the MSYS console, you will eventually need to learn how to use the actual *nix commands.
You might even be inclined to make a bunch of macro-aliases in ~\bin\prompt.bat that mimic *nix commands. Even so, it is better to get used to using both systems’ native commands.
Notice also how we aliased a number of our non-unix programs, like our favorite editor, so we can start them from the MSYS command-line.
Finally, notice that odd-looking one for dird. That’s a bash shell function — weird magic you can study later.
Heh, well, that gets you started with normal stuff. For a future installment, we’ll get various compilers working for you without cluttering the path...