Skip to content

Instantly share code, notes, and snippets.

@photonxp
photonxp / exrc
Last active August 9, 2020 13:55
~/.exrc file for vi
set showmode
set laststatus=2
set statusline+=%F
map ^H :!more ~/.vi_help^M
map #2 :set number^M
map #3 :set nonumber^M
map #4 :set autoindent^M
map #5 :set noautoindent^M
map #6 :set list^M
map #7 :set nolist^M
@photonxp
photonxp / backup.sh
Last active November 21, 2017 12:02
backup and restore linux os with tar
#!/bin/sh
echo "Make sure update_note.txt is ready."
echo
./wait_confirm.sh
datef=`date '+%Y%m%d.%H%M'`
echo "date is: " $datef
backup_home=/mnt/whale/ubuntu16.04.2.of.1_archive/$datef
@photonxp
photonxp / check_tar_gz.sh
Last active November 18, 2017 04:45
check and list the top folders of a give tar file
#!/bin/sh
# check and list the top folders of a give tar file
# Or simply use archivemount
# https://linuxaria.com/howto/how-to-mounts-an-archive-for-access-as-a-file-system
# tar_archive_path as /path/to/archive.tar.gz
tar_archive_path=$1
mkdir -p /tmp/tartest
@photonxp
photonxp / tar_example.txt
Last active November 17, 2017 04:19
explain some part of tar command
compress:
tar -zcvf tar-archive-name.tar.gz source/folder/name
decompress:
tar -zxvf tar-archive-name.tar.gz
tar -zxvf tar-archive-name.tar.gz -C /tmp
mkdir -p /tmp/tartest && rm -r /tmp/tartest/* && tar -zxvf tar-archive-name.tar.gz -C /tmp/tartest && ls -a /tmp/tartest
Both tar -c and tar -x don't affect the user permissions of the folders in the tar.gz file
============
@photonxp
photonxp / list_shared_library_path.sh
Created November 14, 2017 12:47
list paths of shared library in linux
#!/bin/sh
# list part of the paths of shared library in linux
ldconfig -p | grep "/usr/lib"
ldconfig -p | grep "/usr/local"
sudo printenv LD_LIBRARY_PATH
@photonxp
photonxp / restore_guid_partition_table.sh
Last active November 13, 2017 12:09
Risky way to backup and restore guid partition tables
#!/bin/sh
# The number of partition tables could be varied and uncertain.
# So is the length of backup file.
# Only works in limited situations
# Won't work if any new partition is added to the partition table later
# Require sudo privilege
# Use the code only after you know what you're doing. Use at your own risk.
# Change the variables in the script if necessary
@photonxp
photonxp / backup_guid_partition_table.sh
Last active November 16, 2017 13:59
Risky way to backup and restore guid partition tables (GPT)
#!/bin/sh
# The number of partitions in the partition table could be varied and uncertain.
# So is the length of backup file.
# Only works in limited situations
# Won't work if any new partition table is added to the partition table later
# Require sudo privilege
# Use the code only after you know what you're doing. Use at your own risk.
# Change the variables in the script if necessary
@photonxp
photonxp / rcgroup_add_files.sh
Last active November 15, 2017 10:50
add files to rcN.d folders for an init file
#!/bin/sh
# add files to rcN.d folders for a given name of existed init file
# ./rcgroup_add_files.sh init_file_name
ln -s /etc/init.d/"$1" /etc/rc0.d/K20"$1"
ln -s /etc/init.d/"$1" /etc/rc1.d/K20"$1"
ln -s /etc/init.d/"$1" /etc/rc2.d/S20"$1"
ln -s /etc/init.d/"$1" /etc/rc3.d/S20"$1"
ln -s /etc/init.d/"$1" /etc/rc4.d/S20"$1"
@photonxp
photonxp / initfile.sh
Created May 27, 2017 03:26
common init file for apps that support starting/stopping with pid file by command internally
#!/bin/sh
### BEGIN INIT INFO
# Provides: $app_name
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: lightweight
# Description: app is a lightweight
# for embedded devices and low end boxes.
@photonxp
photonxp / add_links_in_folders.sh
Last active May 27, 2017 01:27
create multiple links to the rc folders, using for loops