mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-05-14 15:16:27 +00:00
Fix typos
This commit is contained in:
parent
76550dfa3c
commit
5c0799df7f
118 changed files with 1150 additions and 1602 deletions
|
@ -4,20 +4,20 @@
|
|||
|
||||
## Basic Commands
|
||||
|
||||
### Elevated Priviledges and Users
|
||||
### Elevated Privileges and Users
|
||||
|
||||
[sudo vs su](https://unix.stackexchange.com/questions/35338/su-vs-sudo-s-vs-sudo-i-vs-sudo-bash/35342)
|
||||
|
||||
```bash
|
||||
sudo su # login as root (user must be sudoer, root password not required) DANGEROUS
|
||||
sudo -s # act as root and inherit current user enviroment (env as is now, along current dir and env vars) SAFE (can modify user enviroment)
|
||||
sudo -i # act as root and and use a clean enviroment (goes to user's home, runs .bashrc) SAFEST
|
||||
sudo su # login as root (user must be sudoers, root password not required) DANGEROUS
|
||||
sudo -s # act as root and inherit current user environment (env as is now, along current dir and env vars) SAFE (can modify user environment)
|
||||
sudo -i # act as root and and use a clean environment (goes to user's home, runs .bashrc) SAFEST
|
||||
sudo COMMAND # run a command w\ root permissions
|
||||
sudo -u USER COMMAND # run command as user
|
||||
|
||||
su # become root (must know root password) DANGEROUS
|
||||
su - USER # change user and load it's home folder
|
||||
su USER # change user but dont load it's home folder
|
||||
su USER # change user but don't load it's home folder
|
||||
```
|
||||
|
||||
### Getting Info
|
||||
|
@ -51,7 +51,7 @@ popd # return to previous directory (before pushd)
|
|||
|
||||
```sh
|
||||
touch FILE # change FILE timestamp fi exists, create file otherwise
|
||||
cat [FILE] # concatenate files and print on statndard output (FD 1)
|
||||
cat [FILE] # concatenate files and print on standard output (FD 1)
|
||||
cat >> FILE # append following content ot file (Ctrl+D to stop)
|
||||
file FILE # discover file extension and format
|
||||
stat FILE # display file or file system status
|
||||
|
@ -60,7 +60,7 @@ tail # output the last part of a file
|
|||
tail [-nNUM] # output the last NUM lines
|
||||
|
||||
more # filter for paging through text one screenful at a time
|
||||
less # opposite of more (display big file in pages), navigate with arrow keys or spacebar
|
||||
less # opposite of more (display big file in pages), navigate with arrow keys or space bar
|
||||
|
||||
cut # remove sections from each line of files
|
||||
cut -[d --delimiter=DELIM] # use DELIM instead of TAB for field delimiter
|
||||
|
@ -74,10 +74,10 @@ rmdir DIRECTORY # remove directory only if is empty
|
|||
|
||||
mkdir DIRECTORY # make directories
|
||||
|
||||
mv SOURCE DESTINATION # move or raneme files
|
||||
mv SOURCE DESTINATION # move or rename files
|
||||
mv SOURCE DIRECTORY # move FILE to DIRECTORY
|
||||
|
||||
cp SOURCE DESTINATION # copy SOURCE to DESTIANTION
|
||||
cp SOURCE DESTINATION # copy SOURCE to DESTINATION
|
||||
```
|
||||
|
||||
### Files Permissions & Ownership
|
||||
|
@ -125,7 +125,7 @@ chgrp [OPTION]... GROUP FILE... # change group ownership
|
|||
find [path] [expression] # search file in directory hierarchy
|
||||
find [start-position] -type f -name FILENAME # search for a file named "filename"
|
||||
find [start-position] -type d -name DIRNAME # search for a directory named "dirname"
|
||||
find [path] -exec <command> {} \; # ececute command on found items (identified by {})
|
||||
find [path] -exec <command> {} \; # execute command on found items (identified by {})
|
||||
|
||||
[ -f "path" ] # test if a file exists
|
||||
[ -d "path" ] # test if a folder exists
|
||||
|
@ -140,11 +140,11 @@ command | sudo tee FILE # operate on file w/o using shell as su
|
|||
|
||||
echo # display a line of text
|
||||
echo "string" > FILE # write lin of text to file
|
||||
echo "string" >> FILE # append line o ftext to end of file (EOF)
|
||||
echo "string" >> FILE # append line of text to end of file (EOF)
|
||||
|
||||
wget URL # download repositories to linux machine
|
||||
|
||||
curl # dovnlaod the contents of a URL
|
||||
curl # download the contents of a URL
|
||||
curl [-I --head] # Fetch the headers only
|
||||
|
||||
ps [-ax] # display processes
|
||||
|
@ -161,8 +161,8 @@ diff FILES # compare files line by line
|
|||
shellcheck FILE # shell linter
|
||||
|
||||
xargs [COMMAND] # build and execute command lines from standard input
|
||||
# xargs reads items form the standard input, delimites by blanks or newlines, and executes the COMMAND one or more times with the items as argumests
|
||||
watch [OPTIONS] COMMAND # execute a program periodically, showing output fullscreen
|
||||
# xargs reads items form the standard input, delimited by blanks or newlines, and executes the COMMAND one or more times with the items as arguments
|
||||
watch [OPTIONS] COMMAND # execute a program periodically, showing output full-screen
|
||||
watch -n SECONDS COMMAND # execute command every SECONDS seconds (no less than 0.1 seconds)
|
||||
```
|
||||
|
||||
|
@ -172,10 +172,10 @@ watch -n SECONDS COMMAND # execute command every SECONDS seconds (no less than
|
|||
|
||||
```bash
|
||||
sed # stream editor for filtering and transforming text
|
||||
sed -E "s/REGEX/replacement/" # subsitute text ONCE (-E uses modern REGEX)
|
||||
sed -E "s/REGEX/replacement/g" # subsitute text multiple times (every match)
|
||||
sed -E "s/REGEX/replacement/" # substitute text ONCE (-E uses modern REGEX)
|
||||
sed -E "s/REGEX/replacement/g" # substitute text multiple times (every match)
|
||||
|
||||
wc [FILE] # print newline, word and byte countd for each file
|
||||
wc [FILE] # print newline, word and byte count for each file
|
||||
wc [-m --chars] FILE # print character count
|
||||
wc [-c --bytes] FILE # print bytes count
|
||||
wc [-l --lines] FILE # print lines count
|
||||
|
@ -185,8 +185,8 @@ sort [FILE] # sort lines of a text file
|
|||
|
||||
uniq [INPUT [OUTPUT]] # report or omit repeated lines (from INPUT to OUTPUT)
|
||||
uniq [-c --count] # prefix lines w/ number of occurrences
|
||||
uniq [-d --repeated] # plrint only duplicare lines, one for each group
|
||||
uniq [-D] # plrint only duplicare lines
|
||||
uniq [-d --repeated] # print only duplicare lines, one for each group
|
||||
uniq [-D] # print only duplicare lines
|
||||
|
||||
paste [FILE] # merge lines of files
|
||||
paste [-d --delimiters=LIST] # use delimiters from LIST
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
Interactive mode --> shell waits for user's commands
|
||||
Non-interactive mode --> shell runs scripts
|
||||
|
||||
## File & Directories Permissons
|
||||
## File & Directories Permissions
|
||||
|
||||
File:
|
||||
|
||||
|
@ -35,12 +35,12 @@ Bash gets commands by reading lines.
|
|||
As soon as it's read enough lines to compose a complete command, bash begins running that command.
|
||||
Usually, commands are just a single line long. An interactive bash session reads lines from you at the prompt.
|
||||
Non-interactive bash processes read their commands from a file or stream.
|
||||
Files with a hashbang as their first line (and the executable permission) can be started by your system's kernel like any other program.
|
||||
Files with a shebang as their first line (and the executable permission) can be started by your system's kernel like any other program.
|
||||
|
||||
### First Line Of Bash
|
||||
|
||||
`#!/bin/env bash`
|
||||
Hashbang indicating whitch interpreter to use
|
||||
shebang indicating which interpreter to use
|
||||
|
||||
### Simple Command
|
||||
|
||||
|
@ -73,7 +73,7 @@ command_1 || command_2 || ... # execute successive commands only if preceding o
|
|||
{command_1; command_2; ...} # sequence of commands executed as one
|
||||
```
|
||||
|
||||
### Functions (blocks of easely reusable code)
|
||||
### Functions (blocks of easily reusable code)
|
||||
|
||||
`function_name () {compound_command}`
|
||||
Bash does not accept func arguments, parentheses must be empty
|
||||
|
@ -125,7 +125,7 @@ x>&-, x<&- # close FD x (stream disconnected from FD x)
|
|||
|
||||
`*` matches any kind of text (even no text).
|
||||
`?` matches any single character.
|
||||
`[characters]` mathces any single character in the given set.
|
||||
`[characters]` matches any single character in the given set.
|
||||
`[[:classname:]]` specify class of characters to match.
|
||||
`{}` expand list of arguments (applies command to each one)
|
||||
|
||||
|
@ -137,7 +137,7 @@ x>&-, x<&- # close FD x (stream disconnected from FD x)
|
|||
`@(pattern [| pattern ...])` matches when any of the patterns in the list appears just once. ("one of ...").
|
||||
`!(pattern [| pattern ...])` matches only when none of the patterns in the list appear. ("none of ...").
|
||||
|
||||
## Command Substituition
|
||||
## Command Substitution
|
||||
|
||||
With Command Substitution, we effectively write a command within a command, and we ask bash to expand the inner command into its output and use that output as argument data for the main command.
|
||||
|
||||
|
@ -148,9 +148,9 @@ $(inner_command) # $ --> value-expansion prefix
|
|||
## Shell Variables
|
||||
|
||||
```bash
|
||||
varname=value # variable assignement
|
||||
varname="$(command)" # command sobstituition, MUST be double-quoted
|
||||
"$varname", "${varname}" # variable expansion, MUST be double-quoted (name substituited w/ varaible content)
|
||||
varname=value # variable assignment
|
||||
varname="$(command)" # command substitution, MUST be double-quoted
|
||||
"$varname", "${varname}" # variable expansion, MUST be double-quoted (name substituted w/ variable content)
|
||||
|
||||
$$ # pid
|
||||
$# # number of arguments passed
|
||||
|
@ -158,7 +158,7 @@ $@ # all arguments passed
|
|||
${n} # n-th argument passed to the command
|
||||
$0 # name of the script
|
||||
$_ # last argument passed to the command
|
||||
$? # error message of the last (previous) comman
|
||||
$? # error message of the last (previous) command
|
||||
!! # executes last command used (echo !! prints the last command)
|
||||
```
|
||||
|
||||
|
@ -173,7 +173,7 @@ $? # error message of the last (previous) comman
|
|||
`${parameter/#pattern/replacement}` replaces the string that matches the pattern at the beginning of the value with the replacement.
|
||||
`${parameter/%pattern/replacement}` replaces the string that matches the pattern at the end of the value with the replacement.
|
||||
`${#parameter}` expands the length of the value (in bytes).
|
||||
`${parametr:start[:length]}` expands a part of the value, starting at start, length bytes long.
|
||||
`${parameter:start[:length]}` expands a part of the value, starting at start, length bytes long.
|
||||
Counts from the end rather than the beginning by using a (space followed by a) negative value.
|
||||
`${parameter[^|^^|,|,,][pattern]}` expands the transformed value, either upper-casing or lower-casing the first or all characters that match the pattern.
|
||||
Omit the pattern to match any character.
|
||||
|
@ -195,7 +195,7 @@ fi
|
|||
|
||||
### Test Command
|
||||
|
||||
`[[ arggument_1 <operator> argument_2 ]]`
|
||||
`[[ argument_1 <operator> argument_2 ]]`
|
||||
|
||||
### Arithmetic expansion and evaluation
|
||||
|
||||
|
@ -212,7 +212,7 @@ fi
|
|||
[[ "$a" -le "$b" ]] # less than or equal to
|
||||
```
|
||||
|
||||
### Arithmetic Comperison Operators
|
||||
### Arithmetic Comparison Operators
|
||||
|
||||
```bash
|
||||
(("$a" > "$b")) # greater than
|
||||
|
@ -221,10 +221,10 @@ fi
|
|||
(("$a" <= "$b")) # less than or equal to
|
||||
```
|
||||
|
||||
### String Compatison Operators
|
||||
### String Comparison Operators
|
||||
|
||||
```bash
|
||||
[ "$a" = "$b" ] # is equal to (whitespace atoun operator)
|
||||
[ "$a" = "$b" ] # is equal to (whitespace around operator)
|
||||
|
||||
[[ $a == z* ]] # True if $a starts with an "z" (pattern matching)
|
||||
[[ $a == "z*" ]] # True if $a is equal to z* (literal matching)
|
||||
|
@ -244,7 +244,7 @@ fi
|
|||
|
||||
```bash
|
||||
command_1 || command_2 # if command_1 fails executes command_2
|
||||
command_1 && command_2 # executes command_2 only if command_1 succedes
|
||||
command_1 && command_2 # executes command_2 only if command_1 succeeds
|
||||
```
|
||||
|
||||
## Loops
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue