Skip to content

Filesystem

GradedJestRisk edited this page Nov 21, 2022 · 16 revisions

Table of Contents

Overview

List:

  • add to path export PATH=$PATH:PATH_TO_ADD
Need Syntax
Show (physical) location pwd -P
Change owner chown OWNER FILE
Soft link ln -s TARGET LINK_NAME (--symbolic)
Create folder mkdir FOLDER_NAME
Delete file rm FILE_NAME
Delete folder rmdir FOLDER_NAME
Delete folder and contained files rm -rf HEAD_FOLDER_NAME
Find file by name find STARTING_PATH -name FILTER

Structure

Full

Structure
Path Content
/snap containerized applications
/home user-specific data (not programs)
/media user-specific mounted data (not programs)

Mount

View mount points

# df or # mount

Mount

Step 1: Get UUID

Input sudo blkid /dev/sda1

Output /dev/md127: LABEL="data" UUID="13f99b52-(..)-a6a47f400303" TYPE="ext4"

Step 2: Mount

# sudo mount --uuid DEVICE_UUID -t TYPE -o OPTIONS DESTINATION_DIR

Unmount

Grateful # sudo umount DESTINATION_DIR -l

Forceful # sudo umount -f DESTINATION_DIR

List (ls)

General:

  • list: -l (l for list)
  • sort
    • default is alphanumeric, ignoring hidden file dot prefix
    • reverse order: -r (r for reverse)
    • by modification time, newest first : -t
  • include hidden files:
    • include: -a (a for all)
    • sort them first LC_COLLATE=C ls -a
  • show file type: -F
    • / : directory
    • * : executable
    • @ : symbolic link
      • others (IPC)
        • | : pipe
        • = : socket
        • > : door

enhance output

List

  • in list
  • directories blue and DIRECTORY_NAME/
  • readable size
  • print only file modification date and file name
  • aligned
Gives alias ls='ls -lFh --color=always | awk '\''{print $5,$6,$7,$8,$9}'\'' | column -t'

Backup

https://phoenixnap.com/kb/linux-create-partition

List:

  • identity your device, eg. sdd
  • create partition table on device
    • "sudo parted"
    • select device: "select /dev/sdd"
    • check for existing partition: "print"
    • if any partition, remove it using its number: "rm 1"
    • create partition table: "mklabel gpt"
    • check: print should display "Partition Table: gpt"
  • create partition
    • "mkpart primary ext4 1MB 1000GB"
    • check with "print": ext4 partiton shall exist
    • save with "quit"
  • create file system
    • sudo mkfs.ext4 /dev/sdd1
    • check message is "Writing superblocks and filesystem accounting information: done"
  • mount
    • create mountpoint: mkdir $HOME/mountpoint
    • mount read/write for ?: "sudo mount --types auto --options rw /dev/sdd1 $HOME/backup"
    • try writing a file: "touch $HOME/backup/test"
  • copy files
    • cp
      • create folder: "sudo mkdir $HOME/backup/2022-11-21"
      • copy directory tree: "sudo cp --recursive $HOME/data $HOME/backup/2022-11-21"
      • monitor with glances
    • give user access to files (current owner is root)
      • easy: "chown username $HOME/backup"
      • read/write for everyone: "chmod --recursive a=rw $HOME/backup/2022-11-21"
      • read/write for specific user: "setfacl --recursive -m u:username:rwx $HOME/backup/2022-11-21"
    • tar https://docstore.mik.ua/orelly/unix3/upt/ch10_13.htm
    • rsync
Clone this wiki locally