Gerardo Marx Chávez-Campos 03a7967a48 | 2 years ago | |
---|---|---|
Readme.md | 2 years ago |
First we will introduce some of the most used Bash commands. By using this command we will learn how to manage files, directories, and modify the contents of files. Later, the terminal is introduced. The terminal will be our most used front-end frame to work in mobile devices or servers. Thus, few improvements are going to be make, to support our daily task in the Bash terminal. Finally, we will work with the package manger tool. We are going to install some useful packages that will be used later, and we will make some data science in terminal by creating our first on-liner task.
The most used commands at the terminal are listed below. These are know as File System Commands, because they mainly handle file in our system
Name | Command | options | example |
---|---|---|---|
List files | ls | -a shows all | ls -la |
-l long format | |||
-R recursive | |||
------------------- | --------- | --------------------------------------- | ---------------------------------- |
Current directory | pwd | -P prints the physical location | pwd |
------------------- | --------- | --------------------------------------- | ---------------------------------- |
Change | cd | .. takes you up a level | cd /home/gmarx |
directory | ~ takes you to home directory | cd ~ | |
------------------- | --------- | --------------------------------------- | ---------------------------------- |
Make | mkdir | -p make parent directories as needed | mkdir -p test/example |
directory | -v print a message for each directory | mkdir -p /test/example | |
*first example creates | |||
folders inside the | |||
current folder, other one | |||
creates folder in root directory | |||
------------------- | --------- | --------------------------------------- | ---------------------------------- |
Delete a | rm | -r recursive (use for directories) | rm sample.txt |
file or directory | -d remove empty directory | rm -r test | |
------------------- | --------- | --------------------------------------- | ---------------------------------- |
Copy a file | cp | -r recursivec copy | cp a.txt b.txt |
or directory | -u copy only if the source is newer | cp test-a test-b | |
-v verbose (show output) | |||
------------------- | --------- | --------------------------------------- | ---------------------------------- |
Move a file or | mv | -i prompts before overwrite | mv a.txt c.txt |
directory | No -r; Moving into the same directory | mv test example | |
performs a renaming | |||
------------------- | --------- | --------------------------------------- | ---------------------------------- |
touch | |||
------------------- | --------- | --------------------------------------- | ---------------------------------- |
more | |||
------------------- | --------- | --------------------------------------- | ---------------------------------- |
cal | |||
------------------- | --------- | --------------------------------------- | ---------------------------------- |
There are several Terminal emulators that will help to visualize and work better during a connection to our local or remote system.
I have tested some of them and I can recommend some of they:
Once you have decided and installed a terminal emulator, we can start typing commands and improving the Bash. Below, there are some terminal commands to move around in the daily typing task.
Command | Description |
---|---|
CTRL-c | Stop current command |
CTRL-z | Sleep program |
CTRL-a | Go to start of line |
CTRL-e | Go to end of line |
CTRL-u | Cut from start of line |
CTRL-k | Cut to end of line |
CTRL-r | Search history |
!! | Repeat last command |
Tab key | Autocompletes |
--------- | ------------------------ |
Remember that the terminal is the front-end window of the back-end shell system. The system can be Shell, Bash, Fish, Z-Shell, or any other. The most standard used or pre-installed one is the Bash (Bourne-again Shell), Bash is a command processor that typically runs in a text window where the user types commands that cause actions. Bash can also read and execute commands from a file, called a shell script. Like most Unix shells, it supports filename globbing (wildcard matching), piping, here documents, command substitution, variables, and control structures for condition-testing and iteration. The keywords, syntax, dynamically scoped variables and other basic features of the language are all copied from sh. Other features, e.g., history, are copied from csh and ksh. Bash is a POSIX-compliant shell, but with a number of extensions.
By following the tutorial from 1, the echo
command/printf
command to display current Bash prompt settings:
$ echo "$PS1"
## OR ##
$ printf "%s\n" "$PS1"
Here is what I see %(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)
Here is another output from my Debian based system:
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$
By default the command prompt is set to [\u@\h \W]\$
. The backslash-escaped special characters are decoded as follows:
\u
: Display the current username\h
: Display the hostname\W
: Print the base of current working directory\$
: Display #
(indicates root user) if the effective UID is 0, otherwise display a $
.Before you modify settings save your old prompt using the following command:
oldps1="$PS1"
So if you messed up, you can switch back easily using the following syntax:
PS1="$oldps1"
Use the export command to setup a new shell prompt:
$ export PS1="[\\u@\\H \\W \\@]\\$ "
Where:
\H
: Display FQDN (fully qualified domain name) hostname.\@
: Display current time in 12-hour am/pm format.To add colors to the shell prompt use the following export command syntax:
'\e[x;ym $PS1 \e[m'
Here:
Change the color of shell prompt by setting the PS1 To set a red color prompt, type the following export command: $ export PS1="\e[0;31m[\u@\h \W]$ \e[m "
A list of color codes
Color | Code |
---|---|
Black | 0;30 |
Blue | 0;34 |
Green | 0;32 |
Cyan | 0;36 |
Red | 0;31 |
Purple | 0;35 |
Brown | 0;33 |
Blue | 0;34 |
Green | 0;32 |
Cyan | 0;36 |
Red | 0;31 |
Purple | 0;35 |
Brown | 0;33 |
-------- | ------ |
Note: You need to replace digit 0 with 1 to get light color version.
A good and useful prompt extracted from2:
PS1="\n \[\033[0;34m\]┌─────(\[\033[1;35m\]\u\[\033[0;34m\])─────(\[\033[1;32m\]\w\[\033[0;34m\]) \n └> \[\033[1;36m\]\$ \[\033[0m\]"
Your new shell prompt setting set by $PS1
is temporary i.e. when you logout setting will be lost. To have it set every time you login to your workstation add above export command to your $HOME/.bash_profile
file or $HOME/.bashrc
file.
$ vi .bash_profile
Append the following line:
export PS1="\e[0;31m[\u@\h \W]\$ \e[m"
Pending
$ mkdir -p .local/share/fonts
$
Command | Debian |
---|---|
Install a package | sudo apt install vim |
Upgrade the package in your system | sudo apt upgrade |
------------------------------------ | ---------------------- |