This section shows a few handy terminal commands.
This step can be skipped if you are using MacOS or Linux. However, if you are using Windows, you need to have a terminal that supports the execution of basic Linux commands. Such programs are Git Bash or MinGW, for example. You can find below a few helper steps to get MinGW running on your system.
-
Get the MinGW installer from here
-
Install it to wherever you like, the default installation folder is C:\MinGW
-
Once the setup finishes, open the MinGW Installation Manager
-
Select the two packages for installation as shown in the figure below
-
Click on Installation/Apply Changes. This will take a few moments to fetch and install the required packages.
-
You can open a terminal window by running the executable C:\MinGW\msys\1.0\bin\bash.exe
-
Open a terminal, and try the following commands:
-
pwd
: prints the present working directory
Example:$ pwd /home/ecse321
-
ls
: lists the content of a given folder
Example:$ ls /home ecse321 guest-user admin
-
cd
: navigates the file system
Example:$ cd .. $ pwd /home $ cd ecse321 $ pwd /home/ecse321
NoteThe following steps will include images that illustrate the commands and their output to prevent easy copy-paste. Sorry! :)
-
-
Creating files and reading/writing their contents
The versatile find
command allows us to find files based on given criteria. Take look at its manual page with man find
!
Example:
-
sed
: stream editor; changes a given string to a replacement
Combining find
with an additional command (e.g., sed
) can greatly speed up your repetitive tasks.
Example:
Note
|
The file helloworld.txt in the example is initially a copy of greeting.txt. |
-
rm
: removes a file -
cp -r
: copies a directory recursively with its contents -
rmdir
: remove an empty directory -
rm -rf
: force to recursively delete a directory (or file) and all its contents -
nano
: an easy-to-use text editor (not available by default in MinGW) -
grep
: finds matches for a string in a given stream of characters -
ag
: takes a string as argument and searches through the contents of files recursively to find matches of the given string (this tool is included in the silversearcher-ag package)