CLI - Linux
Command Line Interface
Shell
Shell list
cat /etc/shells
Change shell
chsh -s <shell> [<user>]
or
usermod -s <shell> <user>
Open file manager from CLI
xdg-open <path>
Indicate command type
Type: function
, builtin
, or file
# -a: display all locations
type [-a] <command>
Preserve file timestamp after edit (bash
)
vi-preserve-time () {
for file in "$@"; do
local mtime=$(stat -c %y "$file")
vi "$file"
touch -d "$mtime" "$file"
done
}
Hardware
Command | Description |
---|---|
lsusb | List USB devices |
lspci | List PCI devices |
lspci -nn | List PCI devices and devices code |
lspci -k | List PCI devices and kernel driver |
cat /proc/cpuinfo | Show CPU info |
cat /proc/meminfo | Show memory info |
Mount image
mount -o loop <image.iso> <directory>
File system
ACL
File permission
Only change directory permission
chmod <permission> $(find -type d)
Only change file permission
chmod <permission> $(find -type f)
Change file owner and group
chown { <owner>[:<group>] | --reference <file> } <file>
Change file permission to 644
, directory to 755
Option | Description |
---|---|
-R | Recursive |
-h | --no-dereference | Change symbolic links instead of referenced file |
chmod [-R] u=rw,go=r,a+X <path>
or
chmod [-R] a=r+X,u+w <path>
File attribute
Ref: chattr manual
Attribute | Description |
---|---|
a | Append only |
A | No atime updates |
c | Compressed |
i | Immutable |
s | Secure deletion |
S | Synchronous updates |
u | Undeletable |
List attribute
lsattr
Change attribute
chattr {+|-}<attribute> <file>
List open files
lsof <path>
Manual / Help
Show manual
man [<page>]
Search manual
man -k <keyword>
apropos <keyword>
DNS
vi /etc/resolv.conf
Sharing desktop
Disable sharing desktop encryption (Ubuntu)
Ref: Ask Ubuntu
dconf-editor
# org > gnome > desktop > remote-accessand > require-encryption
gsettings set org.gnome.Vino require-encryption false
File
Copy
cp [<option>] <source> <destination>
Option | Description |
---|---|
-a | --archive | Archive, same as -dR --preserve=all |
-p | --preserve[=<attributes>] | Preserve mode , ownership , timestamps (Default: mode,ownership,timestamps ) |
-R | -r | --recursive | Copy directories recursively |
OpenJDK (Java)
List installed JVM
update-java-alternatives --list
Switch JVM
update-java-alternatives --set <JVM name>
Show Linux distribution / version
cat /etc/*-release
cat /proc/version
uname -a
# For systemd
hostnamectl
# For Debian
lsb_release -a
Last login
Suppress Last Login
message
touch ~/.hushlogin
Clear last login log
> /var/log/lastlog
Disable logging last login
chattr +i /var/log/lastlog
Identify processes using files or sockets
fuser <option> <file>
Option | Description |
---|---|
-v , --verbose | Verbose |
-k , --kill | Kill processes accessing the file |
{ -c | -m | --mount } { <mount point> | <device> } | Mount point or device |
Watch
Execute command periodically
# Default: 2 seconds
watch [-n <seconds>] <command>
FHS (File system Hierarchy Standard) / File system Structure
man hier
Using dash "-
" as path argument
使用 "-
" 做為檔案路徑參數時,一般有以下用途
- Redirection from
stdin
/ tostdout
cd -
change to previous working directory
true
:
is equivalent to
true