Skip to content

0x324 Linux Admin

1. Bash

1.1. Arithmetic


# Addition
sum=$((a + b))
echo "Sum: $sum"

1.2. For

examples to iterate over a given string args

for file in file1.txt file2.txt file3.txt; do
  do_something_with "$file"

FILES="file1.txt file2.txt file3.txt"
for file in $FILES; do
  do_something_with "$file"

for file in /path/to/directory/*.txt; do
  do_something_with "$file"

# if you need to handle filenames with spaces, you would typically use an array in Bash:
files=("file1.txt" "file 2.txt" "file3.txt") # Note: "file 2.txt" has a space
for file in "${files[@]}"; do
  echo "$file"

examples to iterate over numbers

for i in {0..10}; do
  echo "$i"

for i in $(seq 0 10); do
  echo "$i"

1.3. Find

Usage examples

# concat all files matching duration into a single file
# last + instead \; means args are flatten in one line
find . -type f -name 'duration*' -exec cat {} + > combined_file.txt

# delete files less than 10k
find . -type f -size -10k -exec rm {} \;

# find files with html suffix
find . -maxdepth 1 -name "*.html" -print0

1.4. Awk

awk '!seen[$0]++' text: remove duplicates from text

1.5. Others

shuf input.txt > output.txt : shuffle lines of a given file

rename 's/.html/.json/' *.html: rename all files' suffix (probably require installing)

2. Service Management

The initialization daemon is the first process to be started by the kernel on the Linux server (with ppid 0 and pid 1). The original implementation was BSD init and SysVinit. Currently many linux distributions are adopting systemd (e.g: Ubuntu, RHEL, Fedora distributions)

runlevel is a categorization number that determines what services are started and what services are stopped.

3. Network Management

(sudo) netstat -tupln see all listening tcp/udp pid programs

4. Package Management

4.1. Debian

4.2. Redhat

yum list available | grep postgres: search available packages

5. File System Management

/proc/sys/fs/file-max: file limit

/proc/sys/fs/file-nr: currently opened files

6. Credentials

6.1. Users / Groups

File (/etc/passwd) nonsensitive system password file

  • login name: unique user name encrypted password: DES hash of password, x if shadow password enabled
  • User ID (UID): superuser (root) if value 0
  • Group ID (GID): group id of the first group
  • Comment: text about the user
  • home directory: HOME variable
  • login shell: shell

File (/etc/shadow) sensitive password file. password hash is saved here

File (/etc/group) group info (note that part of the info is saved in /etc/passwd) . current login user's group can be checked with group (1)

  • group name: unique group name
  • encrypted password: group password, x if shadow password enabled
  • group ID (GID): group id
  • user list: users

7. Terminal

stty -a: show terminal line settings

8. Reference

[1] Linux Bible