-
Notifications
You must be signed in to change notification settings - Fork 0
Filesystem
List:
- add to path :
export PATH=$PATH:PATH_TO_ADD - Show (physical) location :
pwd -P - Change owner :
chown OWNER FILE - Soft link :
ln --symbolic TARGET LINK_NAME - Create folder :
mkdir FOLDER_NAME - Delete file :
rm FILE_NAME - Delete folder :
rmdir FOLDER_NAME - Delete folder and contained files :
rm --recursive --force HEAD_FOLDER_NAME - Find file by name :
find STARTING_PATH -name FILTER
Block size
- drive block size is 512 bytes
- OS block size is 4096 bytes (4 kbytes)
To find the count of drive blocks a file use
stat $FILEYou get 707 976 blocks for 362 479 616 bytes, which are roughly 512 bytes blocks.
File: base/16384/16385
Size: 362479616 Blocks: 707976 IO Block: 4096 regular file
You can't use ls to get the block count, unless you pass the block-size parameter which is clumsy.
ls -ls --block-size=4K To find if blocks are contiguous on the filesystem
sudo hdparm --fibmap $FILE
You get a list of blocks spans, eg 16, then 49 136
filesystem blocksize 4096, begins at LBA 0; assuming 512 byte sectors.
byte_offset begin_LBA end_LBA sectors
0 526071904 526071919 16
8192 755184728 755233863 49136
25165824 692322304 692355071 32768
41943040 27770880 27820031 49152
67108864 27869184 27918335 49152
To check if a file is fragmented, this is located in non-continuous block, you need the extent count. A extent is a block-contiguous set.
To get extent count
filefrag -v $FILE
You get 32 here
Filesystem type is: ef53
File size of /var/lib/docker/volumes/sandbox_postgresql_data/_data/base/16384/16401 is 362479616 (88496 blocks of 4096 bytes)
ext: logical_offset: physical_offset: length: expected: flags:
0: 0.. 1023: 105417728.. 105418751: 1024:
1: 1024.. 2047: 105431040.. 105432063: 1024: 105418752:
2: 2048.. 4095: 67688448.. 67690495: 2048: 105432064:
3: 4096.. 6143: 67594240.. 67596287: 2048: 67690496
(..)
31: 88064.. 88495: 87228416.. 87228847: 432: 67880960: last,eof
/var/lib/docker/volumes/sandbox_postgresql_data/_data/base/16384/16401: 32 extents found
Frequent
- /snap : containerized applications
- /home : user-specific data (not programs)
- /media : user-specific mounted data (not programs)
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
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 firstLC_COLLATE=C ls -a - show file type:
-F**/: directory ***: executable **@: symbolic link *** others (IPC) ****|: pipe ****=: socket ****>: door
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'
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
Copy
- recursively
- preserve timestamp
cp --archive --verbose $SOURCE_FOLDER $DESTINATION_FOLDERhttps://unix.stackexchange.com/questions/56047/progress-information-via-pv-for-directory-copy
Copy
- recursively
- preserve timestamp
Display progress for whole transfer, not per-file basis
rsync --archive --info=progress2 $SOURCE_FOLDER $DESTINATION_FOLDERssh $USERNAME@$HOSTNAME -p$PORT
Use SSH key for authentication or password
Will create target folder if not exists
To copy
- from a remote server to another remote server
- folders, recursively
- preserving timestamp
scp -r -p $SOURCE_USERNAME:/$SOURCE_FOLDER $TARGET_USERNAME@TARGET_HOSTNAME:/$TARGET_FOLDERTo copy
- from a local server to another remote server
- folders, recursively
- preserving timestamp
scp -r -p $SOURCE_FOLDER $TARGET_USERNAME@TARGET_HOSTNAME:/$TARGET_FOLDER