Linux Commands

Table of Contents

Misc. Linux commands.


Current directory

1
echo ${PWD##*/}

Find x-days before and action

In actuality, it should be (x-1).

1
/bin/find <path> -maxdepth 1 -mtime +<x> -type f -name "<pattern>" -exec rm -f {} \;

Find x-minutes before and action

1
/bin/find <path> -maxdepth 1 -mmin +<x> -type f -name "<pattern>" -exec rm -f {} \;

Change password last modify

1
chage -d YYYY-MM-DD <user>

Change password never expire

1
chage -I -1 -m 0 -M 99999 -E -1 <user>

Lock/Unlock Account

1
2
3
4
5
6
7
passwd -l <user>  # Lock
passwd -u <user>  # Unlock

usermod -L <user> # Lock
usermod -U <user> # Unlock

pam_tally2 -r -u <user> # Reset fail login count

iptable ban ip

1
2
iptable -A INPUT -s <IP> -j DROP
ip6table -A INPUT -s <IP> -j DROP

Fail2ban ban ip manually

1
2
fail2ban-client status # show jail list
fail2ban-client -vvv set <jail from list> banip <ip>

zsh range for loop

1
for i in {1..10};do .....

bash string comparison

1
if [ "$str" = "string" ]; then ...

bash/zsh numeric comparison

1
if [[ ${A} = 3 ]]; then echo yes; fi

Disable journal on ext4

1
tune2fs -O ^has_journal /dev/<disk>

Rotate frame buffer

Number can be 1, 2, 3

1
2
echo 1 > /sys/class/graphics/fbcon/rotate_all
echo 1 > /sys/class/graphics/fbcon/rotate

Show all mDNS/Bonjour entries

1
2
avahi-browse -a
avahi-browse -a -d <domain> # specify domain other than .local

Create sparse file

truncate -s <size> <filename>

1
2
3
4
5
6
7
$ truncate -s 10G 10G.txt

$ ls -lah 10G.txt
-rw-r--r--    1 user user   10.0G Apr  1 00:00 10G.txt

$ du -sh 10G.txt
0       10G.txt

Ref: Sparse file wikipedia

Rsync

1
rsync -vahpt --size-only --stats --del <source> <target>

<source> is put/sync INTO <target> directory, not replacing <target>.

Curl skip certificate checking

1
curl -k ... # Use -k to skip certificate check.

Resize Filesystem

Usually use after a partition / image resize

1
2
resize2fs <device>
resize2fs /dev/sda1

avahi/mdns lookup

Get IPv4 mdns

1
avahi-resolve -n4 door.local

Get IPv6 mdns

1
avahi-resolve -n6 door.local

Check NIC status

1
ethtool <nic>

Enable BBR

Create file /etc/sysctl.d/10-network-bbr.conf with following content and reboot:

1
2
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
John Siu
Minimize the Effort, Maximize the Effect!
comments powered by Disqus