Take some of Linux

Default standard UNIX/Linux utilities

cat – concatenate files to standard output
chgrp – change file group ownership
chmod – change file access permissions
chown – change file owner and group
cp – copy files and directories
date – print or set the system data and time
dd – convert and copy a file
df – report filesystem disk space usage
dmesg – print or control the kernel message buffer
echo – display a line of text
false – do nothing, unsuccessfully
hostname – show or set the system’s host name
kill – send signals to processes
ln – make links between files
login Utility to begin a session on the system
ls – list directory contents
mkdir – make directories
mknod – make block or character special files
more – page through text
mount – mount a filesystem
mv – move/rename files
ps – report process status
pwd – print name of current working directory
rm – remove files or directories
rmdir – remove empty directories
sed – The `sed’ stream editor
sh – POSIX compatible command shell
stty – change and print terminal line settings
su – change user ID
sync – flush filesystem buffers
true – do nothing, successfully
umount – unmount file systems
uname – print system information

Command binaries that are not essential enough to place into /bin must be placed in /usr/bin, instead. Items that are required only by nonroot users (the X Window System, chsh, etc.) are generally not essential enough to be placed into the root partition.

Linux filesystem

Filesystem Hierarchy Standard specification

Navigation

pwd – print current directory
cd ~ or cd – home directory
cd .. – one directory tree level up
cd - – go back to previous working directory
popd pushd – ???
tree (-d) – print the directory subdirectories (and files) structure tree
ls (-l) [-a] {-i} – lists the files in present working directory (including hidden) [with files/directories info] { with files IDs (different links to one file have same ID)}

Aliases

nano ~/.bash_aliases

Lines syntax: alias <command>=’bash command’. Spaces are not allowed.
E.g.: alias update=’sudo dnf upgrade’

source ~/.bash_alias – apply alias’s list

Hard and soft (symbolic, sym-) links

ln <file> <file_sc> – create hard link (shortcut) – alternative reference to the same file, same ID
ln -s <file> <file_sc> – create symbolic link (different object with new ID)

https://wiki.merionet.ru/servernye-resheniya/77/komanda-ln-kak-sozdavat-simvolicheskie-ssylki-v-linux/

Stop laptop from being suspended when lid closed

nano /etc/systemd/logind.conf

Uncomment and bring to the following order the strings:

HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
LidSwitchIgnoreInhibited=no

Restart the system.

Path definition

Dispaly current PATH variable: echo $PATH

Default $PATH set (not user-related): PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

System information

uname -a – info of Linux version, core etc.

lshw [-short] – full hardware configuration tree [brief overview]
lscpu
lsmem
lsblk [-a],
fdisk -l additional info
blkid check UUID
lsusb

top [-i] – CPU utilization [hide idle processes]

Volume blocks management

Display current info: mount
Mount sdb1 block to /mnt/media as ext4 volume: mount /dev/sdb1 /mnt/media -t ext4
Automount on startup: add record to /etc/fstab:
<volume device path>/UUID=<uuid> <mount path> <filesystem> <options> 0 0
example:
UUID=9898b394-874b-46fd-afd7-087c91987bfa /data ocfs2 _netdev,defaults, uid=0, gid=0, umask=0077, shortname=winnt 0 0

Add to File management setuid (chmod u+s), setgid (chmod u+s), Sticky bit (chmod +t)

https://ericdraken.com/useful-linux-commands/

https://ericdraken.com/pfsense-decrypt-ad-traffic/

Files handling

Read

Text file to console
cat <file>
tac <file> – from the last line towards the begin of fine
-n – number the lines

less – scrollable viewing utility:
g ; G- first ; last line
/ ; ?- search forward ; backward;
v – edit with default editor;
q – exit
h – help

head (tail) <file> ; cat <file> | head (tail) – print out first (last) 10 lines of the file
-n <number> – print out <number> of first (last) lines

Write

touch – create empty file / reset timestamp / -t <timestamp> – set timestamp
mkdir – create directory

rm – remove file(s) (-i – confirm for every file)
rm -r – remove directory with all content recursively
rmdir – remove empty directory

mv – move/rename file/directory

Here and further:
> – overwrite file; >> – append to the end of file
' ' may also be used instead of " ".

echo "Some text here." >> myfile.txt

> myfile.txt – erase all data in myfile.txt

Write command output to file (e.g. full directory content with permissions):
ls -la >> myfile.txt

Write to file from console line by line until ‘EOF’ typed in
cat > outfile.txt <<EOF
some text
to save
EOF

Find files by name:
find <path> -name "<name wildcard>"

System and apps search:
which <file> – basic check in $PATCH directories
whereis <file> – more deep search

Find files with string content
grep -Ril "text-to-find-here" /
i stands for ignore case (optional in your case).
R stands for recursive.
l stands for “show the file name, not the result itself”.
/ stands for starting at the root of your machine.

Check services running by <user>
sudo ps -efl | grep '<user>'

I/O streams

File ID’s
0 – stdin – input stream (by default – keyboard)
1 – stdout – output stream (by default – console)
2 – stderr – error messaging stream (by default – console, often redirected to log-file)

< changes the stdin source;
> redirects stout (by default or 1>) or stderr (2>); e.g.: [program/command] > [output_file] 2> [err_log]

2>&1 or shorthand >& – send everything written to stderr to the same destination as stdout

cat [file1] > [file2] – take the content of [file1] to the output stream and redirect it to [file2] – as result the content of [file1] is copied to [file2], replacing its content

Pipeline

command1 | command2 | command 3
The output (stdout) of the previous command is passed to the next one, the last command sends its output to the stdoud destination (console by default).

Prompt line

$PS1 Evironmental variable
\u – username
\h – hostname

List ls color designations

eval $(echo "no:global default;fi:normal file;di:directory;ln:symbolic link;pi:named pipe;so:socket;do:door;bd:block device;cd:character device;or:orphan symlink;mi:missing file;su:set uid;sg:set gid;tw:sticky other writable;ow:other writable;st:sticky;ex:executable;"|sed -e 's/:/="/g; s/\;/"\n/g')           
{      
  IFS=:     
  for i in $LS_COLORS     
  do        
    echo -e "\e[${i#*=}m$( x=${i%=*}; [ "${!x}" ] && echo "${!x}" || echo "$x" )\e[m" 
  done       
} 

Oracle Linux 8 training course:
https://apexapps.oracle.com/pls/apex/f?p=44785:141:16314683441842::NO:RP,141:P141_PAGE_ID,P141_SECTION_ID:557,3806

Oracle Linux 8 Documentation
https://docs.oracle.com/en/operating-systems/oracle-linux/8/index.html#

Time and Date management

timedatectl
status
set-time YYYY-MM-DD hh:mm:ss (ether one or both date and time)
set-date
list-timezones
set-timezone
set-local-rtc 0/1 – set hardware clock to a local TZ (1) or UTC (0)
set-ntp true/false – synchronize time with NTP-server

date – display current day and time in active timezone

display difference between dates in days:

A="2002-10-20"
B="2003-11-22"
echo $(( ($(date -d $B +%s) - $(date -d $A +%s)) / 86400 )) days

curl

-s – run silently

-L – redo the request to a new location automatically if server responses of resource is moved

-f – fail silently

-o <file> – save to file

tar

tar -tf -show archive content

tar -xf -extract

–strip-content=i – ignore i levels of directories tree inside the archive structureip

network

ip link set dev <interface> up/down – enable/disable network interface

ip link show – list network interfaces

ip a[ddress] [show] – list addresses of the interfaces

ip addr add 192.168.1.200/24 dev enp0s25 – set temporary IP configuration

ip route add default via 192.168.1.1 – set temporary gateway configuration

Permanent config: RH/OL/CentOS

/etc/sysconfig/network-scripts/ifcfg-<interface> – network configuration file

Parameter name Description Values Example
DEVICE Interface name eth0
eth1
device=eth0
device=eth1
BOOTPROTO IP designation method dhcp
none
static
(пустое значение)
bootproto=dhcp
bootproto=
bootproto=static
bootproto=none
HWADDR MAC-address   HWADDR=”00:00:00:00:00:00″
NM_CONTROLLED NetworkManager controllable interface “yes”
“no”
NM_CONTROLLED=”yes”
ONBOOT Start on bootup “yes”
“no”
ONBOOT=”yes”
TYPE Interface type “Ethernet” TYPE=”Ethernet”
UUID     UUID=”ffffffff-ffff-ffff-ffff-ffffffffffff”
IPADDR IP-address   IPADDR=192.168.1.3
NETMASK Subnet mask   NETMASK=255.255.255.0
GATEWAY Gateway address   GATEWAY=192.168.1.1
DNS1 1-st DNS server   DNS1=192.168.1.1
DNS2 2-nd DNS server   DNS2=192.168.1.2
DOMAIN Host domain name   DOMAIN=MYDOMAIN.LOCAL
Static:
DEVICE=enp3s0
ONBOOT=yes
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DHCP
DEVICE=enp3s0
ONBOOT=yes
DHCP=yes

Permanent config: Debian/Ubuntu

Config files: /etc/netplan/xx-*.yaml

xx – priority index (99 – top, 00 – lowest).

DHCP

network:
  ethernets:
    enp2s0:
      dhcp4: true
  version: 2

Static IP

network:
  ethernets:
    enp2s0:
      dhcp4: false
      addresses:
        - 192.168.1.128/24
      gateway4: 192.168.1.1
      nameservers:
        search: [mydomain, otherdomain]
        addresses: [192.168.1.1, 8.8.8.8]
  version: 2

Run netplan apply to actualize the settings.

Firewall

firewall-cmd --permanent --add-service=http

firewall-cmd --permanent --add-port=<port#>/tcp<udp etc>

firewall-cmd --permanent --list-all

firewall-cmd --reload

This entry was posted in linux and tagged . Bookmark the permalink.