Thursday, October 24, 2024

GIT - fetch, rebase ...

 


Merging or Rebasing

Here I want to compare both methods. In this example will use few git functions.

Merging

Merge graph that looks below. To incorparate code from "feature branch" new knot on "main" branch is needed.

If I run a merge, git will stuff all of my changes from my feature branch into one large merge commit that contains ALL of my feature branch changes. It will then place this special merge commit onto master. When this happens, the tree will show your feature branch, as well as the master branch. Going further, if you imagine working on a team with other developers, your git tree can become complex: displaying everybody else’s branches and merges.

Rebasing

Now let’s take a look at how rebase would handle this same situation. Instead of doing a git merge, I’ll do a git rebase. What rebase will do is take all of the commits on your feature branch and move them on top of the master commits. Behind the scenes, git is actually blowing away the feature branch commits and duplicating them as new commits on top of the master branch (remember, under the hood, commit objects are immutable and immovable). What you get with this approach is a nice clean tree with all your commits laid out nicely in a row, like a timeline. Easy to trace.

Each method have positive and negative features. Each approach has to be established individually. 

In practice: the actual commands

On the development team I work with, we’ve successfully adopted the workflow I’m about to show you and it works well for us. If you’d like a visual representation of what each of these commands does, check out my video.

When I start development I always make sure the code on my local machine is synced to the latest commit from remote master

# With my local master branch checked out
git fetch origin




Next, I’ll check out a new branch so I can write and commit code to this branch – keeping my work separated from the master branch

git checkout -b FeatureBranch



As I’m developing my feature, I’ll make  commit.

git add .
git commit -m 'This is a new commit'


Since I synced with remote master before doing the rebase, I should be able to push my changes up to remote master without issues.

git push origin main

To save time, use aliases.



More info see Github repo  with history*.txt:
https://github.com/andsidor/Git_test



Tuesday, October 8, 2024

Basic linux commands

 



All Linux commands fall into one of the following four categories:

  • Shell builtins - Commands built directly into the shell with the fastest execution.
  • Shell functions - Shell scripts (grouped commands).
  • Aliases - Custom command shortcuts.
  • Executable programs - Compiled and installed programs or scripts.

Here I  show a list of typical Linux commands examples of how they work. I will present command in groups listed below:
  • File and Directory Operations Commands
  • File Permission Commands
  • File Compression and Archiving Commands
  • Process Management Commands
  • System Information Commands
  • Networking Commands
  • IO Redirection Commands
  • Environment Variable Commands
  • User Management Commands
1. File and Directory Operations Commands

File and directory operations are fundamental in working with the Linux operating system. Here are some commonly used File and Directory Operations commands:


1a. pwd command

The pwd command (print working directory) is a shell builtin command that prints the current location. 

        pwd


1b. ls command

The ls command (list) prints a list of the current directory's content.
    ls


Additional options:
-Show as a list
    ls -l


-Show as list with hidden files
    ls -la


-Show files with filesize
    ls lah



1c. cd command

The cd command (change directory) is a shell builtin command for changing the current working directory:


cd <directory> (relative path)


cd <path> (full path)


1d. mkdir command

The mkdir command (make directory) creates a new directory in the provided location.

    mkdir <Name_new_directory>



1e. rmdir command

Use the rmdir command (remove directory) to delete an empty directory.
    rmdir <Name_direktory_to_delete>



1f. touch command

The primary purpose of the touch command is to modify an existing file's timestamp. To use the command, run:

    touch <filename>


The command creates an empty file if it does not exist. Due to this effect, touch is also a quick way to make a new file (or a batch of files).

1g. cat command

The cat command (concatenate) displays the contents of a file in the terminal (standard output or stdout). To use the command, provide a file name from the current directory:

    cat <file 1> <file 2>



! - To display with line number
     cat -n <file 1> <file 2>


1h. cp command

The main way to copy files and directories in Linux is through the cp command (copy).
    cp [Source_file] [Destination_file] 



! - To prevent overide file

cp -i [Source_file] [Destination_file] 




! - To copy directory recursively

cp -r [dir 1]  [dir 2] 

1i. mv command

Use the mv command (move) to move files or directories from one location to another.

    mv <filename> ~/Documents/<filename>


    mv <filename> <renamed_filename>
    
1j. rmdir/rm command

   rm <filename> (path local or full path)

The rm command (remove) deletes files or directories. To use the command for non-empty directories, add the -r tag.

1.k head command
Use the head command to truncate long outputs.
    head <file>
shows the first 10 lines of the <file>.


    head -n 5 <filee> 
displays the first 5 lines of the <file>.


1.l tail command
The Linux tail command does the opposite of head. Use the command to show the last ten lines of a file
    tail <file>


    tail -n 5 <file>
displays the last 5 lines of the <file>.

2. File Permission Commands
    File permissions on Linux and Unix systems control access to files and directories. There are three basic permissions: read, write, and execute. Each permission can be granted or denied to three different categories of users: the owner of the file, the members of the file’s group, and everyone else.

2.a chmod command

Use the chmod (change mode) command to change file and directory permissions. The command requires setting the permission code and the file or directory to which the permissions apply.
    chmod <permission> <file or directory>

Who

The “who” is a list of letters that specifies whom you’re going to be giving permissions to. These may be specified in any order.

u The user who owns the file (this means “you.”)
g The group the file belongs to.
o The other users
a all of the above (an abbreviation for ugo)

Permissions

Of course, the permissions are the same letters that you see in the directory listing:

r Permission to read the file.
w Permission to write (or delete) the file.
x Permission to execute the file, or, in the case of a directory, search it.


Example 1: Give read, write and execute permissions to the owner, read and execute permissions to the group and read and execute permissions to others

        chmod 755 file.txt
        chmod u=rwx,g=rx,o=rx file.txt

Example 2: Give read, write and execute permissions to the owner, read and execute permissions to the group and read and execute permissions to others

        chmod 755 directory
        chmod u=rwx,g=rx,o=rx directory

Example 3: Give read, write and execute permissions to the owner, read and execute permissions to the group and read and execute permissions to others

        chmod -R 755 directory
        chmod -R u=rwx,g=rx,o=rx directory

2.b chown  command

The chown command (change ownership) changes the ownership of a file or directory. To transfer ownership, use the following command as sudo:

    sudo chown <new owner name or UID> <file or directory>
(adduser - https://www.geeksforgeeks.org/adduser-command-in-linux-with-examples/)


! - https://phoenixnap.com/kb/linux-chown-command-with-examples
! - https://www.geeksforgeeks.org/addgroup-command-in-linux-with-examples/

Permission groups can be:

blank to signify the owner
g for group
o for others
a for all
Add or remove is

+ to add the permission
- to remove the permission
Permission type can be

r for read, copy and so forth
w for write, edit, delete and move
x to make it executable

Example 1: Change the ownership of a file. Txommand gives the ownership of the file to the root user and the root group.

        chown root:root file.txt


Example 2: Change the ownership of a directory. The command gives the ownership of the directory to the root user and the root group.

        chown root:root directory

Example 3: Change the ownership of a directory and all its subdirectories. The command gives the ownership of the directory and all its subdirectories to the root user and the root group.

        chown -R root:root directory

The Chown and Chmod commands are very similar. The only difference is that the Chown command is used to change the ownership of a file or directory and the Chmod command is used to change the permissions of a file or directory.

2.c 
chgrp

There is a third command called Chgrp that is used to change the group of a file or directory. The Chgrp command is used to change the group of a file or directory by using the following syntax:

chgrp [OPTIONS] GROUP FILE(s)


Example 1: Change the group of a file. Command gives the group of the file to the root group.

        chgrp root file.txt

Example 2: Change the group of a directory. Command gives the group of the directory to the root group.

        chgrp root directory

Example 3: Change the group of a directory and all its subdirectories. Command gives the group of the directory and all its subdirectories to the root group.

        chgrp -R root directory

chgrp marketing file.txt – to change the group specified to a certain document

chgrp oracle /usr/database – to change the group specified to a certain directory

chgrp -R marketing /sales/2008 – to change the group specified to a certain directory recursively

2.d chown command
chown: This command changes file owner and group.


chmod 600 some_file

Here is a table of numbers that covers all the common settings. The ones beginning with “7” are used with programs (since they enable execution) and the rest are for other kinds of files.

Value
777 (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.

755 (rwxr-xr-x) The file’s owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.

700 (rwx——) The file’s owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.

666 (rw-rw-rw-) All users may read and write the file.

644 (rw-r–r–) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.

600 (rw——-) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.

Here are some useful settings for directories:

Value Meaning
777 (rwxrwxrwx) No restrictions on permissions. Anybody may list files, create new files in the directory and delete files in the directory. Generally not a good setting.

755 (rwxr-xr-x) The directory owner has full access. All others may list the directory, but cannot create files nor delete them. This setting is common for directories that you wish to share with other users.

700 (rwx——) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.


chmod 755 file.txt

The above command is equivalent to the following command:

chmod u=rwx,g=rx,o=rx file.txt





2.4 umask command

The umask command in Linux is used to set default permissions for files or directories the user creates.
TBD

3. File Compression and Archiving Commands
Here are some file compression and archiving commands in Linux:



4. Process Management Commands
In Linux, process management commands allow you to monitor and control running processes on the system. Here are some commonly used process management commands:



5. System Information Commands
In Linux, there are several commands available to gather system information. Here are some commonly used system information commands:

uname - Print effective user name
whoami - Print effective user name
df - Report file system space usage
du - Estimate file space usage
free - Total usable memory
uptime - Utility for removing user
lscpu - Display CPU information
lspci - List PCI devices.
lsusb - List USB devices
exit - List USB devices
clear - List USB devices
passwd - Change user password
useradd - Create a new user or update default new user information
userdel - Utility for removing user

6. Networking CommandsDisplay network socket information.
In Linux, there are several networking commands available to manage and troubleshoot network connections. Here are some commonly used networking commands:

ss - Display network socket information.

7. IO Redirection Commands 
In Linux, IO (Input/Output) redirection commands are used to redirect the standard input, output, and error streams of commands and processes. Here are some commonly used IO redirection commands:

Command

Description

cmd < fileInput of cmd is taken from file.
cmd > fileStandard output (stdout) of cmd is redirected to file.
cmd 2> fileError output (stderr) of cmd is redirected to file.
cmd 2>&1stderr is redirected to the same place as stdout.
cmd1 <(cmd2)Output of cmd2 is used as the input file for cmd1.
cmd > /dev/null Discards the stdout of cmd by sending it to the null device.
cmd &> fileEvery output of cmd is redirected to file.
cmd 1>&2stdout is redirected to the same place as stderr.
cmd >> fileAppends the stdout of cmd to file.


8. Environment Variable Commands
In Linux, environment variables are used to store configuration settings, system information, and other variables that can be accessed by processes and shell scripts. Here are some commonly used environment variable commands:

Command

Description

export VARIABLE_NAME=valueSets the value of an environment variable.
echo $VARIABLE_NAMEDisplays the value of a specific environment variable.
envLists all environment variables currently set in the system.
unset VARIABLE_NAMEUnsets or removes an environment variable.
export -pShows a list of all currently exported environment variables.
env VAR1=value COMMANDSets the value of an environment variable for a specific command.
printenvDisplays the values of all environment variables.
9. User Management Commands
In Linux, user management commands allow you to create, modify, and manage user accounts on the system. Here are some commonly used user management commands:


Command 

Description

whoShow who is currently logged in.
sudo adduser username Create a new user account on the system with the specified username.
fingerDisplay information about all the users currently logged into the system, including their usernames, login time, and terminal.
sudo deluser USER GROUPNAMERemove the specified user from the specified group.
lastShow the recent login history of users.
finger usernameProvide information about the specified user, including their username, real name, terminal, idle time, and login time.
sudo userdel -r usernameDelete the specified user account from the system, including their home directory and associated files. The -r option ensures the removal of the user’s files.
sudo passwd -l usernameLock the password of the specified user account, preventing the user from logging in.
su – usernameSwitch to another user account with the user’s environment.
sudo usermod -a -G GROUPNAME USERNAME Add an existing user to the specified group. The user is added to the group without removing them from their current groups.


10. Shortcuts Commands
There are many shortcuts commands in Linux that can help you be more productive. Here are a few of the most common ones:



10.1: Bash Shortcuts Commands:

NavigationDescriptionEditingDescriptionHistoryDescription
Ctrl + AMove to the beginning of the line.Ctrl + UCut/delete from the cursor position to the beginning of the line.Ctrl + RSearch command history (reverse search).
Ctrl + EMove to the end of the line.Ctrl + KCut/delete from the cursor position to the end of the line.Ctrl + GEscape from history search mode.
Ctrl + BMove back one character.Ctrl + WCut/delete the word before the cursor.Ctrl + P Go to the previous command in history.
Ctrl + FMove forward one character.Ctrl + YPaste the last cut text.Ctrl + NGo to the next command in history.
Alt + BMove back one wordCtrl + LClear the screen.Ctrl + CTerminate the current command.
Alt + FMove forward one word.    

10.2: Nano Shortcuts Commands:

File OperationsDescriptionNavigationDescriptionEditingDescriptionSearch and ReplaceDescription
Ctrl + O Save the file.Ctrl + YScroll up one page.Ctrl + KCut/delete from the cursor position to the end of the line.Ctrl + WSearch for a string in the text.
Ctrl + XExit Nano (prompt to save if modified).Ctrl + VScroll down one page.Ctrl + UUncut/restore the last cut text.Alt + WSearch and replace a string in the text.
Ctrl + RRead a file into the current buffer.Alt + \Go to a specific line number.Ctrl + 6Mark a block of text for copying or cutting.Alt + RRepeat the last search.
Ctrl + JJustify the current paragraph.Alt + , Go to the beginning of the current line.Ctrl + KCut/delete the marked block of text.  
  Alt + .Go to the end of the current line.Alt + 6Copy the marked block of text.  

10.3: VI Shortcuts Commands:

CommandDescription
cwChange the current word. Deletes from the cursor position to the end of the current word and switches to insert mode.
ddDelete the current line.
xDelete the character under the cursor.
REnter replace mode. Overwrites characters starting from the cursor position until you press the Escape key.
oInsert a new line below the current line and switch to insert mode.
uUndo the last change.
sSubstitute the character under the cursor and switch to insert mode.
dwDelete from the cursor position to the beginning of the next word.
DDelete from the cursor position to the end of the line.
4dwDelete the next four words from the cursor position.
ASwitch to insert mode at the end of the current line.
SDelete the current line and switch to insert mode.
rReplace the character under the cursor with a new character entered from the keyboard.
iSwitch to insert mode before the cursor.
3ddDelete the current line and the two lines below it.
ESCExit from insert or command-line mode and return to command mode.
URestore the current line to its original state before any changes were made.
~Switch the case of the character under the cursor.
aSwitch to insert mode after the cursor.
CDelete from the cursor position to the end of the line and switch to insert mode.

10.4: Vim Shortcuts Commands:


Normal ModeDescriptionCommand ModeDescriptionVisual ModeDescription
iEnter insert mode at the current cursor position.:wSave the file.vEnter visual mode to select text.
xDelete the character under the cursor.:qQuit Vim.yCopy the selected text.
ddDelete the current line.:q!Quit Vim without saving changes.dDelete the selected text.
yyCopy the current line.

:wq

or

:x

 Save and quit Vim.pPaste the copied or deleted text.
pPaste the copied or deleted text below the current line.:s/old/new/gReplace all occurrences of “old” with “new” in the file.  
uUndo the last change.

:set nu

or

:set number

Display line numbers.  
Ctrl + RRedo the last undo.   

































































K8s cluster - bash install

     In my homelab, I testes another method of installation of Kubernetes. Average time of installation of Kubernetes via Ansible was 15 min...