Wednesday, 26 April 2023

Linux

Linux principles:

  • everything in Linux is a file
  • small a single purpose programs
  • chain programs together to perform a complex purpose
  • avoid user interface
  • configuration in a text file

Terms:

Shell =>Kernel=> Hardware

Bash is a sort of Shell, other shells, fx: Fish, Zsh, Ksh

A Terminal, also called a shell, is a GUI to interact with the kernel.

Linux folder

/(forward slash): Root 

/home/username: each user has a personal folder

/bin: command binaries. 

/etc: local system configuration files

/lib: shared libs shared for system boot

/opt: the third-party tools

/var: variable files, fx: log files


Linux commands

ls -a: list all files including hidden ones.

ls -l: list files in a long format.

ls -l *.txt

 

cd: change the current directory

.. indicates the parent folder


mkdir: make a new folder

mkdir folder1 folder2: creating several folders

mkdir -p folder/nested-folder: creating m-nested folders

rmdir: remove a folder

rm: remove one file or multiple files

rm blue red yellow

rm -v blue red yellow 

-v: verbose.  -r: recursive -i: interactive -f: force

rm -rf folder-name


touch: if the file is not existed, create one, else update to a new timestamp. 

touch new-file-name


open: open a file or directory just like double-clicked file icon. 

open. open the current folder in a graphic presentation

open file-name: open the file in OS default text editor


> : redirect output console

date > newFile.text: output current date to designated file, and overwrite the file entirely.

>>: redirect out the console and appending

date>> newFile.text: out current date to designated file, and appending. 


cp: copy file or folder

less: a UI showing the entire file, scrolling down and up.

less file-name

WC: word count

wc -l file-name: shows line number in a file

wc -w file-name: shows how many words are in a file


piping |: taking one command output as input of another command. 


Env var

expending dollar sign or tilde


dollar sign path

echo * all path names

echo *.txt

? matching each single character


cry0l1t3@htb[/htb]$ ls -l /etc/passwd

- rwx rw- r--   1 root root 1641 May  4 23:42 /etc/passwd
- --- --- ---   |  |    |    |   |__________|
|  |   |   |    |  |    |    |        |_ Date
|  |   |   |    |  |    |    |__________ File Size
|  |   |   |    |  |    |_______________ Group
|  |   |   |    |  |____________________ User
|  |   |   |    |_______________________ Number of hard links
|  |   |   |_ Permission of others (read)
|  |   |_____ Permissions of the group (read, write)
|  |_________ Permissions of the owner (read, write, execute)
|____________ File type (- = File, d = Directory, l = Link, ... )

chmod 777 file-name : change file read-write-executable

find . -name fileName: find the current folder by name 

which: shows the path to a file

which file-name: locate a file


ps: shows all processes

ps -ef: extended format 

ps -ef | grep bash

kill PID: kill by its process ID

top: show statistics of system usage

wget URI: download resources


su: switch user to log in as someone else

exit: log out a user account

sudo: super user do, run a command as a root user


sudo apt update:  update the APT package index in line with the repository.

sudo apt upgrade: update the installed packages to the latest version.

sudo apt upgrade specific-package: update an installed package to the newest version.

sudo apt install package-name: install package 

source file-name [argument]: shell built-in command that can execute a file containing a list of shell commands. 

export: built-in shell command to mark env variable to export the child processes(change visibilities). 

sh xxx.sh: execute a script file


Vi/Vim Editor

vi target_file_name

entry mode| edit mode | command mode

press esc, and then press key i, then seeing bottom showing 'Insert'; now in an edit mode
press esc, then quit from insert model, then in an entry mode
press esc, then press :, then enter command mode.

press esc, bottom right input commands
:w save current file
:q quit from file without saving
:wq  write and quit from current file
:q! force to quit without saving
:set nu showing line number
:set nonu turning off line number

Network

ping domain_name or ip_address


Check Remote Ports are Reachable Using ‘nc’ Command

Using netcat, you can check if a single or multiple or a range of open ports as follows. The command below will help us see if the port 22 is open on the host 192.168.56.10:

nc -zv 192.168.1.15 22
-z – sets nc to simply scan for listening daemons, without actually sending any data to them.
-v – enables verbose mode.

The next command will check if ports 80, 22 and 21 are open on the remote host 192.168.5.10 (we can use the hostname as well):
nc -zv 192.168.56.10 80 22 21

and it is also possible to check a range of ports.
nc -zv 192.168.56.10 20-80


how to install JDK from Linux 

No comments:

Can Jackson Deserialize Java Time ZonedDateTime

Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...