We are going to learn Linux Operating system. It will helps you to become Power user of Linux Operating system in your workplace. Let's get started.
First lesson is divided into two parts:
Basic Operating system navigation.
1. navigating from one directory to another
2. getting file information
3. removing files and directories.
File and text manipulation
1. searching through your directories
2. find a specific file
3. copying and pasting
4. chaining commands
Linux terminal has an interpreter who interpretes linux commands. This interprete is called Shell. and the language of shell is named Bash.
bin, etc, dev, home, proc, usr, var these are directories located at Root directory. All have specific meaning.
bin: keeps essential binnaries and program like system application or program.
etc: store system configuration files.
dev: whenever a device, it might be virtual device, is connected to system. A device file is created in /dev location. Device type could be character or block type and many more. character type device could be recognized by 'c' and 'b' for block device. Important notes on disk device are 1. sometimes you might see sda,sdb etc. All of these are disk devices. Here, sda has special meaning. sda device is detected by computer first.
history
Copy command: cp from to
-r flag used for recursive action
*: wildcard is used for pattern
mv: mv from to
used for move or rename file or folder
remove comamnd, it remove file permanently unlike windows
rm [file name]
display file content: cat, less, head, tail [filename]
modify file content
nano or other file editor
linux searching within files:
grep [searched_word] filename
Input, output and stderr 2>
sudo = super user do
--------$ sudo su -
this command substitue current user to another. If you doesn't specify any user, then by default root user willl be here.
--------$ cat /etc/group
See group information
--------$ cat /etc/passwd
See user information
passwd [username]
sudo passwd -e [username]
sudo useradd [new username]
sudo userdel [new username]
Permission
u - file owner
g - stands for group
o - for other
chmod u+x [filename]
chmod u-x [filename]
chmod ugo+x [filename]
chmod 754 [filename/dirname]
sudo chown [username] [filename]
sudo chgrp [groupname] [filename]
Special permission
setuid, setgroupid, sticky bit
symbolic sign is s, s, and t. where numeric sign are 4,2,1
setuid: is a special permission level. where user can use file without direct permission of owner.
setgroupid: can use file belonging to group.
sticky bit: anyone can add and write file, except deletion.
software distribution:
ubuntu
.deb or debian package
install and removing standalone debian package
sudo dpkg -i [filename]
sudo dpkg -r [applicationname]
7z e [archive filename]
# package manager
1. apt, advanced package tool, is a package manager of ubuntu linux distribution.
-----------$ sudo apt install [soft name]
-----------$ sudo apt remove [softname]
2. snap
Reference: https://www.baeldung.com/linux/snaps-intro
# what command can you use to see the version of the kernel on your Linux system?
---------- $ uname -r
You can upgrade linux version. You need to use these commands:
--------- $ sudo apt update
--------- $ sudo apt full-upgrade
then after rebooting you are able to use new kernel.
# File systems:
Major file systems are NTFS, ext4, FAT32.
Remarkable notes:
FAT32, is an excellent file system that compatible with windows, linux and MacOS.
NTFS, file system that is compatible to both windows and linux. NTFS is recommanded file system for windows.
ext4, is only work with linux distro. recommanded for linux.
FAT32 has some shortcomings though.
It doesn't support files larger than 4 gigabytes
It doesn't support file system larger than 32 gigabytes. It's great choose for small USB device.
Network file system is compatible for all OS and overcome shortcomings of FAT32.
Disk anatomy:
Some terminalogy are associated with Disk. They are partition, volume, partition table.
Parition: The piece of a disk that you can manage. To add a file system to a disk first you need to create a partition. It's possible to have different file system on different partition, but same disk.
Volume: Without file system on partition is called volume. When you format a file system on a partition, it becomes a volume.
Partition table: is a scheme that tell how the disk is partitioned. This scheme helps to make partition on same disk. Major two partition table scheme: Master Boot Record (MBR); GUID Partition Table (GPT).
MBR and GPT have mentionable districtions. MBR is traditional partition scheme and old standard and mostly used for windows OS. It has limitation to size of max 2TB. It uses primary partition. There can have 4 primary partition.
GPT is new standard which overcomes limitions of size and number of partition. It can use 2TB or greater volume size and one type of partition and unlimited partitions. new BIOS standard UEFI is compatible with GPT partition.
# Disk partition:
------------$ sudo parted -l
It will show all disk with their partition table and number of partition in details.
-----------$ sudo parted [disk name, e.g. /dev/sda]
it prompts another terminal, give control on disk. We can run specific command for disk.
------------- (parted) print
it shows details info of it.
--------------- (parted) mklabel [gpt|mbr]
it sets partition table value.
--------------- (parted) mkpart primary ext4 1MiB 5GiB
it makes partition into disk with these given info.
------------$ mkfs -t ext4 /dev/sdb[partition number]
it makes file system on it, and make ready for use. But remember, without mounting OS can't use it.
# Mount and Unmount
-----------------$ sudo mount [storage] [specific_dir] e.g. sudo mount /dev/sdb1 /my_usb/
it mounts secondary storage devices to specific directory. In this example, storage /dev/sdb1 and specific directory is /my_usb/
Sometimes, we don't mount explicitly, OS do for users.
--------------$ sudo umount /my_usb
it unmounts the storage.
-----------------$ cat /etc/fstab
fstab stands for file system table, stores mounting info
# swap memory
In linux, swap memory is a dedicated space of memory.
Steps which are followed to make a swap memory:
1. make a partition with "linux-swap" file system via parted tool.
2. sudo mkswap [partition_name, e.g. /dev/sdb2]
3. sudo swapon [partition_name, e.g. /dev/sdb2]
4. if we want this swap space active automatically with boot up, then need an entry in /etc/fstab configuration file.
# disk usage
--------------$ df -h
find how much free of Disk. here -h flag is for human readable format.