Post

Linux Commands I Often Need to Google

Common Commands

find

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# find [path] [expression]

# find file in the current directory with name sample.txt and ignore error
find . -name sample.txt 2>/dev/null

find . -name "*.txt"

# find file by size
# c (for bytes) or k (for kilobytes) or M (for megabytes) or G (for gigabytes) suffix
find . -size +5G -size -10G

find ./ -type f -size 1033c ! -executable

find / -size 33c -user bandit7 -group bandit6 2>/dev/null

file

1
2
3
4
file readme.md

# list file type in a directory
file ./-file*

systemctl

1
2
3
4
5
6
7
8
9
10
11
12
# check status
systemctl list-units
systemctl status application.service

# check service config
systemctl cat application.service

# manage service
sudo systemctl start application.service
sudo systemctl stop application.service
sudo systemctl restart application.service
sudo systemctl reload application.service

ref

journalctl

1
2
3
4
journalctl -u <service-name> 

# -f: follow log
# -n 20: show 20 lines

ref

ln

1
ln -s my_file.txt my_link.txt

ps

Get process information

1
ps -aux

screen

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# start a new screen
screen 

# start a new screen with name
screen -S netcat

# list screen
screen -ls

# detach from a screen
# or Ctrl+C then d
screen -d netcat

# attach to a screen
screen -r netcat

mount/unmount

1
2
sudo umount /media/external
sudo mount -t vfat /dev/sda1 /media/external -o uid=1000

uniq

remove duplicate from a file

1
2
# output unique line
sort data.txt | uniq -u

strings

output human readable character from a file (remove binary character)

1
strings data.txt | grep keyword
This post is licensed under CC BY 4.0 by the author.