common
-
strings
: print the printable characters in file mv
: seems to only remove after copy is done- be aware of shell expansion which might cause mv to be run on individual files instead
- which cause remove to happen after each file
- be aware of shell expansion which might cause mv to be run on individual files instead
rm
: fail if file not writablerm -f
: no warning if file does not existunlink
: rm
tree
: directory stucturedd bs=4M if=.img of=/dev/sdX status=progress oflag=sync
-
scripts
: record current session free
: view memory usage-
vmtouch
: pin file in cache & etc -
findmnt | grep "\["
: look for bind mount git submodule sync --recursive
: sync.gitmodules
with submodules
apt
alien
: convert package between distro--scripts
: also try to convert script
tasksel
: package group--list-task
--task-packages
apt-cache
show
: dump of various infodepends, rdepends
policy
: to see which source a package is installed from
apt-mark
hold
,unhold
: stop automatic updateauto
,manual
: mark dependency
/etc/apt/preferences
Pin: origin ""
Pin: release *
Pin-Priority
< 0 : prevent installation
- use mirror list:
deb mirror://mirrors.ubuntu.com/mirrors.txt
- non interactive: https://stackoverflow.com/questions/33370297/apt-get-update-non-interactive
backport is not enabled even after apt source update
-t bionic-backports
install-recommends https://askubuntu.com/questions/351085/how-to-remove-recommended-and-suggested-dependencies-of-uninstalled-packages
show obsolete package
aptitude search '~o'
apt-show-versions | grep 'No available version'
clean residual config
Reference
dpkg -l | grep '^rc' | awk '{print $2}' | xargs sudo apt-get purge
list installed packages by size
Reference
dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' | sort -k1,1n
bash
login
vsnon-login
:$0
contains-
iflogin
interactive
vsnon-interactive
.$-
containsi
ifinteractive
- reference: shell
- reference: scp fail if shell prints
- a shell running a script is always a non-interactive shell
- used to change it via
set -i
. Not anymore becauseinteractive
only affect startup process.
- used to change it via
echo $0
: display current shell name reliablycat /etc/shells
: list valid login shellsgrep "^$USER" /etc/passwd
: print default shell name for userchsh -s /bin/bash
: change login shell
time related
- cron
- cron guru
crontab
: command-e
: edit-l
: list
- format:
MAILTO=email@example.com
for following cron job@reboot
minute hour dayofmonth month dayofweek command
* * * * *
: means that this command will run at all times- system cron also contains user name
- cron file
/var/spool/cron/crontab
: users’ cron setting/etc/crontab
,/etc/cron.*
: system cron
timeout
: run a command with time limitat
: run a command at specified time
git
- to print git log, set
GIT_TRACE=1 GIT_CURL_VERBOSE=1
before git command - git object
rsync
- A trailing slash on a source path means “copy the contents of this directory”.
- Without a trailing slash it means “copy the directory”.
-
later arguments will override previous one?
- -a: copy recursively, with permission
- -X: include extended permision
--perms
: copy over original permission--no-perms
: original permission + umask--no-perms --chmod=ugo=rwX
: override original permission. i.e. umask only- acl is not kept
owner
,group
: keep originalusermap
,groupmap
-u
: means update only. skip file if the reciveing end is newer-
--delele
: delete file if source does not exist - -S: sparse file optimization
- -z: compress on transfer
-e 'ssh -p <port-number>'
: use sepecified remote shell- -P: print progress
- –exclude: exclude file pattern
- –backup –backup-dir: do extra backup
-
-n: dry run
- check:
- size is always checked, you cannot skip on that
-I
to not check mtime-c
to also checksum
rsync -aXSP
# for synology
rsync -aSP --no-perms --no-owner --no-group --no-links --exclude '#recycle' --exclude '@eaDir' --delete
# copy directory only
rsync --include '*/' --exclude '*'
# same command but with filter syntax
rsync -f'+ */' -f '- *'
user management
/etc/passwd
: user and group-
/etc/group
: supplementary groups useradd
-m
: create home dir
usermod -aG
mkhomedir_helper
passwd -e <user_name>
chage -l <user_name>
usermod -l new old
usermod -d /newdir -m new
groupmod -n new old
login msg
make executable to enable the message.
/etc/update-motd.d
name service switch
- specify how different services are resolved
/etc/nsswitch.conf
getent
: read database through nss
xxd
- every option start with its own
-
-i
: dump c header- revert the change via header2bin.py
-p
: plain dump style-r
: revert from hex
nc
-v
: verbose-w 2
: timeout-z
: scanning mode-p
: specify a port-l
: listen
file path
/home/$user might not exist due to network mounted system /tmp is writable by all users /run/user/$uid created by pam_systemd store files used by running process for that user wiped when no active session remain
$XDG_RUNTIME_DIR
https://doc.qt.io/qt-5/qstandardpaths.html
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
code page
encoding set https://www.iana.org/assignments/character-sets/character-sets.xhtml
gnome
- alt f2: run command
- r : restrart gnome
- lg: gnome diagnostic terminal?
ssh
ssh-keygen -b 4096 -t rsa
4096 bit rsa keyssh-keygen -a 100 -t ed25519
ssh -A
agent forwarding:- remote machine can use local ssh-agent to authenticate
- no need to setup key everywhere
- port-forward enable access to another service which is otherwise inaccessible
-L 123:remote:456
bind local port 123 toremote:456
-R 123:local:456
bind remote port 123 tolocal:456
-f -N -T
-f
: make ssh a background process after authentication-N
: make a connection without running any commmand-T
: disable pseudo-tty allocation
ssh -J Jumphost
jump host- for older version,
-o ProxyCommand="ssh -W %h:%p Jumphost"
-tt
allocate pseudo-tty
- for older version,
Host betajump
HostName jumphost1.example.org
User test
Port 233
IdentityFile ~/.ssh/rsa
# same as -A
ForwardAgent yes
Host behindbeta
HostName behindbeta.example.org
# same as -J
ProxyJump betajump
udev
- respond to hotplug event, and assign dev name based on dev property
udevadm monitor
: print all hotplut eventudevadm info --attribute-walk --name <dev>
: print device propertyudevadm control --reload-rules
grub
# whether to boot from saved entry
GRUB_DEFAULT=saved
# whether to update saved entry
# GRUB_SAVEDEFAULT=true
# then run following command
grub-set-default
update-grub
vscode
note on china network
- go_url: https://golang.google.cn/dl
- GOPROXY: https://goproxy.cn/
- docker: https://yeasy.gitbook.io/docker_practice/install/mirror
- ngc:
ngc registry image pull
https://toroid.org/sudoers-syntax