My Linux Notes

Table of Contents

My Linux Notes

Linux History

  • 1970 - Unix released by Ken Thompson and Dennis Ritchie at AT&T
  • 1977 - BSD released and got into lawsuit by AT&T since it contains unix code
  • 1983 - GNU project started by Richard Stallman to create Free unix-like os and protect it with GPL License
  • 1991 - A personal/hobby kernel project "Linux" started by Finnish Student named Linus Torvalds

Pros of Linux -

  • Free and Open Source
  • Highly Secure
  • More stable and High Performance
  • Less Vulnerable to Malwares and Viruses
  • Frequently Updated and in Development
  • No drivers problem
  • Present in almost types of devices

Cons of Linux -

  • Can Difficult for beginners to use
  • Need more knowledge seeker mentality than consumeristic to work with it.

Philosophy -

  1. Everything is a File
  2. Small, Single-purpose programs
  3. Ability to chain programs together to perform complex tasks
  4. Avoid captive user interface
  5. Configuration data stored in a text file

Components -

  • Bootloader
  • OS Kernel
  • Daemons
  • OS Shell
  • Graphics Server
  • Window Manager
  • Utilities

Architecture

  • Hardware
  • Kernel
  • Shell
  • System Utility

File System Hierarchy

  • / Root file System directory
  • /bin essential binary files directory
  • /boot files require to boot LinuxOS
  • /dev device files
  • /etc local system configuration files
  • /home users files directory
  • /lib shared library files
  • /media directory for external devices mount points
  • /mnt directory for temporary mount points
  • /opt directory for optional files like third-party tools
  • /root home directory for root user
  • /sbin executable binary files used for system administration
  • /tmp directory to store temporary files by system applications and users
  • /usr contains executables, libraries, man files, documentations, etc
  • /var variable data such as log files, email in boxes, web applications, crons files, etc

Shell and terminals

prompts

getting helps

system Information

  • whoami
  • id
  • hostname
  • uname
  • pwd
  • ifconfig
  • ip
  • netstat
  • ss
  • ps
  • who
  • env
  • lsblk
  • lsusb
  • lsof
  • lspci

User management

  • sudo
  • su
  • useradd
  • userdel
  • usermod
  • addgroup
  • delgroup
  • passwd

Package Management

The features that most package management systems provide are:

  • Package downloading
  • Dependency resolution
  • A standard binary package format
  • Common installation and configuration locations
  • Additional system-related configuration and functionality
  • Quality control
  • dpkg = A tool to manage .deb packages
  • apt = cli package manager for debian or ubuntu based system
  • aptitude = more powerful tool than apt
  • snap = cli tool to manage snap packages
  • gem = front-end to RubyGems, standard package manager for Ruby
  • pip = package manager for python
  • git = git is a versional control system used for storing development files
  • pacman = A powerful package manager for Arch based systems
  • dnf = A powerful package manager for redhat and fedora based systems
  • yay = package manager for Arch user repository

Service and Process Management

Daemons = server services run in background. has suffix with "d" eg. sshd, systemd systemd = init service start at pid 1. It monitors and manage all the other services

PID = all process have assigned pid and can be seen in /proc systemctl = systemd program to manage services by user

using openssh

install openssh-client

Navigation

  • cd

Text Manipulation

echo - send text to stdout cat - read file less - read in a pager head - read from top tail - read from bottom more - file perusal filter for crt viewing sort - sort lines uniq - report or omit repeated lines fmt - reformat lines pr - convert text files for printing tr - translate or delete characters

Advanced Commads

awk - pattern scanning and processing language grep - print lines matching pattern sed - stream editor for filtering and transforming text

Managing Users and Groups

  • Create User `useradd`
  • delete user `userdel`
  • Editing user `usermod`

Rename user in Linux

For renaming user in Linux systems, we will use ‘usermod’ command. Syntax for the command is,

$ usermod -l new_username old_username

For example, if we have a user named ‘dan’ & want to rename it to ‘susan’, execute the following command from terminal;

$ sudo usermod -l susan dan

This will only change the username & everything else, like group, home directory, UID will remain same.

Note:- You should need to logged out from the account you are trying to rename. You can also kill all the processes running for that user, to do so execute the following command,

$ sudo pkill -u dan

$ sudo pkill -9 -u dan

Renaming Home directory For renaming home directory to correspond to the renamed user, we use ‘-d’ option with ‘usermod’ command.,

$ sudo usermod -d /home/susan -m susan

Changing UID for the user To change the UID of the user , execute the following command,

$ sudo usermod -u 2000 susan

where ‘2000’ is the new UID for user.

Renaming the group To rename the group from ‘dan’ to ‘susan‘, we will use ‘groupmod’ command. Use the following command to rename the group,

$ groupmod -n susan dan

To use a name that’s already in use but you want to use it anyway, command would be,

$ groupmod -o -n susan dan

Once we have made the required changes, we can than check the changes made using the ‘id’ command,

$ id susan

St

Managing Files and Folders

Mangaging Permissions and Ownership

Package Mangement

Automation

Emacs 27.2 (Org mode 9.4.4)