Bash
Processes
List processes
List all processes
ps aux
List all processes running as root
ps aux | grep ^root
List the processes tree
ps auxf
Command explanation
alists processes from all usersudisplays the process's user/ownerxlists processes without a controlling terminalfdisplays a tree of processes
Trace processes system calls
Run and trace a process
strace <command>
Trace a process
strace -p <pid>
Trace a process and its children
strace -p <pid> -f
strace
You'll need to install strace on the target machine to use it. Also, you'll need to be root to trace processes you don't own.
Containers
If you're tracing a process inside a container, you'll need SYS_PTRACE capabilities.
File System
Find files by name
Simple find
# Find flag.txt recursively from root
find / -name flag.txt 2>/dev/null
tip
You can change -name to -iname to make the search case-insensitive.
Find every executable file with SUID permissions
find / -perm -u=s -type f 2>/dev/null
Find every executable file with SUID permissions owned by root
find / -uid 0 -perm -u=s -type f 2>/dev/null
Command explanation
-uid 0specifies the user ID to search for (in this case, root)-perm -u=sspecifies the permissions to search for (in this case, SUID)-type fspecifies the file type to search for (in this case, a file)2> /dev/nullredirects errors to/dev/null
Find files by content
Find every file which contains the word 'password'
grep -irn / -e password 2>/dev/null
Command explanation
-imakes the search case-insensitive-rmakes the search recursive-nprints the line number of the match-especifies the regex pattern to search for2> /dev/nullredirects errors to/dev/null
Create a .tar archive
Create a .tar archive
tar -czvf archive.tar <file>
Command explanation
-ccreates a new archive-zcompresses the archive with gzip-vprints the files being archived-fspecifies the archive file
Extract a .tar archive
Extract a .tar archive
tar -xzvf archive.tar
Extract to another directory
You can use the command tar -xf archite.tar -C target/ to extract all files to the target/ directory.
Command explanation
-xextracts the archive-zspecifies the archive is compressed with gzip-vprints the files being extracted-fspecifies the archive file