Linux

< to add contents from here: https://serverfault.com/questions/951854/do-containers-have-an-os>

Command library reference: https://linuxcommandlibrary.com/

gcc reference:

  • https://linux.die.net/man/1/gcc
  • https://man7.org/linux/man-pages/man1/gcc.1.html

Linux on Windows: WSL

There are multiple Linux distributions (OS) such as Ubuntu and CentOS.

There are two interfaces to use Linux

GRUB (GRand Unified Bootloader) first loads during boot that replaces the BIOS when triggered (by Esc or Shift). It is a menu to select an installed Linux OS (if more than one installed) or an installed kernel.

Swap

Linux sections memory (RAM) to page divisions and configures spaces on the hard disk called swap space (space as file/partition). Swapping is where a page is virtually moved to a swap space.

As partitions are generally difficult to resize, creating it on an LVM makes it much more volatile.

Linux Flavor/Distro

.bashrc is located at the Home directory (i.e. /Home/<profilename>) which runs when the user logs in. The file contains configurations.

  • To add directory to variable: FILE_NAME=”/dirname”
  • To see directory from set variable: echo FILE_NAME

RedHat Linux

Package Management Tool: yum

RHEL (Red Hat Linux)

First RedHat open-source Linux distribution that has been replaced by other derivatives since 2004 due to being discontinued.

CentOS

to view repo list: yum repolist

to install packages (packages to install are in repository): yum install <packagename>

To add user (add when in root): adduser <username>

To install/enable the PowerTools repository:

  • sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
    • sudo dnf config-manager –set-enabled PowerTools
    • # if above fails, try the below
    • sudo dnf config-manager –set-enabled powertools
Package List
Package TypePackage NameUse
web browserlynxlynx <URL>

Debian

Package Management Tool: apt-get

Ubuntu

Kernel

Hold the Shift button when booting to access the kernel GRUB menu.

Check currently active kernel version: $ uname -mrs

To list available kernel versions to get for use: $ apt-cache search linux-generic

To install kernel, choose one from list and run one of the 2 below (e.g. linux-image-4.15.0-187-generic kernel)

  • $ sudo apt install linux-image-4.15.0-187-generic
  • $ sudo apt-get install linux-image-4.15.0-187-generic

To check if Secure Boot is enabled: sudo mokutil –sb-state

Using Linux Bash CLI

Command Line Cheat Sheet

use man <command> to find out about a command in detail

To run a shell script (*.sh): ./filename.sh (as root user, use sudo (Super User DO): sudo filename.sh)

Command
. or ./Current working directory
#
~Home directory (e.g. ~/ for /home/USER)
.filenameThe ‘.’ signifies ‘filename’ is a hidden file
Command
pwdPresent working directory
cd
cd ..
cd /
Change directory
Move one directory up
Move to root
ls
ls -R
ls -a
ls -al
lsblk
List directory contents
List contents of directory and its subcontents
List directory contents including hidden
List directory contents including hidden with details
List block devices (e.g. hard disks)
cat
cat > filename
cat filename1 filename2>filename3
List contents of file (e.g. cat note.txt)
Creates new file
Merges filename1 & filename2 to filename3
cp
mv
Copies(cp)/Moves(mv) file to a chosen directory
e.g. cp abc.txt /home/<username>/Desktop
copies abc.txt to Desktop (moves if mv over cp)
findFind directory/files
find . -name filename.sh
find /opt -name abc.txt


To find filename starting with ‘do’ (use -iname argument for case insensitive):
find . -name do\*
vi
nano
Text editors
vi abc.sh
nano abc.sh
Find out about machine and OS
hostnamectl
untarExtract contents of a tar.gz file
tar -xvf tarfilename.tar.gz
tar -xvf tarfilename.tar.gz -C /<dir>
lnSymbolic link (command creates link; any one changes the other)
ln -s <dir/filename> <NEW dir/filename>
Command Prompt Dissection
rootThe home directory of root , the system administrator
home Home directories of regular users
binShells and command-line utilities, some of which are required to run the system
sbinCommand-line system administration utilities, several of which are required to run the
system
libReusable system libraries needed by programs
usrPrograms, configuration settings, libraries, and help files that can be shared with
multiple systems
usr/binMany utilities and applications
usr/sbinMany system administration utilities
usr/libMany reusable system libraries that are used and dependent on by programs
varVariable data such as logs, database, web files, spool directories for mail, and so on
bootThe kernel, initial RAM disk, and boot loader, which are responsible for booting up the
system
etcSystem-wide configuration files
lost+foundFiles recovered by the file system checker after improper shutdowns such as a system
crash or power failure
mediaDirectories used for automatically mounting removable drives such as CD-ROM, DVD,
and USB storage devices
miscDirectories typically used for mounting NFS directories
srvData served by your system through services such as web, ftp, or cvs
mntFolders used for temporarily mounting remote directories (NFS, SMB) and removable drives(CD-ROM, DVD, and USB devices)
optthird-party software applications
procA virtual filesystem that contains special files used for changing or displaying kernel
settings
devFiles that represent the hardware devices in your system and virtual devices supplied by
the kernel
selinuxA virtual filesystem containing special files used for changing or displaying SELinux
settings
sysA virtual filesystem that contains special files used for changing or displaying devices
that are hot-pluggable
tmpTemporary files and folders that are deleted periodically by the system
Subdirectories in the Root Directory

Command List

whoamicurrent working user
su – rootswitch user to admin/root
pwdDisplays the present working directory.
cd
cd <directory>
Changes the working directory.
mkdir
mkdir <directory>
Creates a new directory.
mv
mv <source> <target>
Renames or moves files or directories
ls
ls <directory>
ls -a <dir>
Lists the contents of a directory
root directory contents: ls /
The -a shows all hidden files and folders
rm
rm <file> [<file2>[<file..>]]
Deletes files.
rmdir
rmdir <directory>
Deletes an empty directory.
shutdown -h now
shutdown -h +5
shutdown -h +5 “See you!”
-h halts all CPU functions
+5 is to shutdown CPU in 5 minutes
For more information: man <command name>

<directory>

/root directory

ls -l /

Files such as text, image, database, binary, and so on
d (directory)A special file that can contain other files
l
(symbolic link)
A shortcut or reference to another file
b
(block device)
Devices that can send and receive buffered or random data such as CD, DVD, and hard disks
c
(char. device)
Devices that can send and receive data in a sequence of characters, such as modems and virtual terminals
s
(sockets)
Files used for communication within processes in the local system without using network protocols
p
(named pipe)
Pipes represented in the filesystem

vi <filename.txt>

press ‘i’ to enter text; press escape button, then immediately type ‘:q’ (‘:q!’ to quit without saving) then press ‘Enter’ to save and quit

to view contents of a file: cat <filename>

GUI

Launch applications . . .

  1. Press Activites @ top left >
    • OR
  2. Press Win/Command button on keyboard > select app and press Enter key

Switch tasks: Win/Command key + Tab


Reference

  1. Sicam, C., Baclit, R., Membrey, P., & Newbigin, J. (2009). Foundations of CentOS Linux Enterprise Linux On the Cheap. Berkeley, CA: Apress.
  2. Dave_Child. “Linux Command Line Cheat Sheet.” Cheatography, Cheatography Https://Cheatography.com, 28 Oct. 2011, cheatography.com/davechild/cheat-sheets/linux-command-line/.
  3. “35 Linux Basic Commands Every User Should Know (Cheat Sheet).” Hostinger Tutorials, 13 May 2021, www.hostinger.my/tutorials/linux-commands.
  4. https://wiki.archlinux.org/title/swap

--- :: Skyferia Tech's Related Posts :: ---