Unix Command Cheatsheet - kdaisho/Blog GitHub Wiki
fold
# wrap 20 characters width while respecting word
git log | fold -sw 20
# output
924e30fe88f002e57b20
252e774d217d0dc58e32
Author: Daisho
Komiyama
<daishokomiyama@gmai
l.com>
Date: Sat Nov 23
11:51:41 2024 -0500
...
# wrap 20 characters width
git log | fold -w 20
# output
commit 924e30fe88f00
2e57b20252e774d217d0
dc58e32
Author: Daisho Komiy
ama <daishokomiyama@
gmail.com>
Date: Sat Nov 23 1
1:51:41 2024 -0500
Disable msal
...
head
Print the first 10 characters of git log
git log | head -c 10
# output
commit 924%
# Add a newline at the end of output
git log | head -c 10; echo
# output
commit 924
Print the first three lines of git log
git log | head -n 3
# output
commit 924e30fe88f002e57b20252e774d217d0dc58e32
Author: Daisho Komiyama <[email protected]>
Date: Sat Nov 23 11:51:41 2024 -0500
List all files
find ./
Count number of files under the current directory
find ./ -type f | wc -l
Count number of directories under the current directory
find ./ -type d | wc -l
List active ports
lsof -i -P -n | grep LISTEN
-i = internet files or sockets
Print processes on port 3000
lsof -i tcp:3000
-i = internet files or sockets
Kill a process running on a particular port (e.g., 8080)
kill -9 $(sudo lsof -t -i:8080)
Grep
grep -ir "console" .
-i = case insensitive
-r = search recursively)\
zgrep FILE
(search inside gzip file)
Find running node process
ps aux | grep node
(a = show processes for all users, u = display the process's user/owner, x = also show processes not attached to a terminal)