I’ve been learning hacking on and off for a few years without any kind of structure, so I would pick up some stuff here and there without really understanding how it all worked. This all changed during lockdown. Now, mind you, I still consider myself a beginner but I started using a hacking platform called Try Hack Me during lockdown to get back into hacking. I decided that this time I would do it correctly and take notes for each room I go through. The first room was Learn Linux and here is below a cheatsheet with all the important information that you can find in this room. This cheatsheet is useful after you completed the room as a way to review everything you learned and ccheck if you haven’t forgotten anything. I really hope you find some use in it!
https://tryhackme.com/room/zthlinux
Basic Commands
Basic Commands
ls
Lists all files in a directory
cat
Command that lets you “read” a given file
touch
Creates a new file
./
Runs an executable
>
Output Redirection -> writes to file
»
Output redirection -> appends to file
&&, and
Executes a 2nd command after the first one ran successfully
&
Background operator, the command will run in the background
$
Environment variable
Example: (prints current variable)
echo $USER
To set this kind of variable use:
export varname=value
locate
Locates a file
(Note: use updatedb before to make sure that it looks through every folder available even the newest ones)
passwd
Changes password
man
Manual for commands
** | ** |
Pipe, takes the output of a command and uses it as input for a second command
;
It’s like && however it does not require the first command to run successfully
(Used with tr, sed, vi and grep and others)
Note: it’s known as either ‘regexp’, ‘regex’
.
Replaces any character
^
Matches start of the string
$
Matches end of the string
*
Matches up zero or more times the preceding character
**
Represents special characters
()
Groups regular expressions
?
Matches up exactly one character
{n}
Matches the preceding character appearing ‘n’ times exactly
{n,m}
Matches the preceding character appearing ‘n’ times
{n,}
Matches the preceding character only if it appears ‘n’ times or more
Note: You need to use -E with the last three regexps
\+
Matches one or more occurence of the previous character
cat sample | grep "a\+t"
Filters lines where character ‘a’ precedes ‘t’
\?
Matches zero or one occurence of the previous character
whoami
Command that states your current user
sudo
Administrator you can also run as another user with -u
adduser/addgroup
Adds users and groups
usermod -a -G <groups separated by a comma> <user>
Adds user to group with the syntax above
id
Command that allows to view basic info about a user
nano
Terminal based text editor
nano <file>
ctrl x → exit
which
Command that shows you where an executable is in any of the PATH directories
apt
Installs packages needs root cause we’re making changes to the /usr directory
apt install <package>
ps
Shows list of user created processes
-ef lists all of the system processes
PID
Process id
kill
Kills processes
kill <PID>
top
Shows what processes are taking up the most system resources, which allows you to manage the resource allocation on your system by killing unneeded processes
chmod
Sets the different permissions for a file
1 → x
2 → w
4 → r
chown
Edits who owns the file for user and group (user: group)
mv
Moves smth or renames it
mv <file> <destination>
cp
Copies file to a directory same syntax as mv
mkdir
Creates a directory
mkdir <directoryname>
Hardlinking
Duplicates the file and links the duplicate to the original . What is done to the created link is done to the original too.
Symbolic linking(symlink)
Reference to the original copy. Symbolic Link has no data in it at all, it’s just a reference.
Syntax
Symlink is the same as hardlink but with an -s flag
ln -s <file> <destination>
ls shows that a file is a symbolic link with an arrow pointing to the original file
The symlink has the same perms as the original file
find
Allows the user to find files but only shows files that the user has access to
grep
Allows the user to find data inside of data, helps narrow down the input to what we’re looking for
Files are optional if we are the piping
grep <regular expressions> <files>
The syntax for a brace expansion is either a sequence or a comma separated list of items inside curly braces ‘{}’. The starting and ending items in a sequence are separated by two periods “..”
echoa{0..2}b
a0b a1b a2b
Store command in a file with a .sh extension if we want to run bash script but if we add a shebang (#!/bin/bash)(which is the path to shell) at the top of the script and then to run we use ./<file>
/etc/passwd
Stores user information often used to see all the users on a system
/etc/shadow
Has all the passwords of these users
/tmp
Every file inside it gets deleted upon shutdown, it’s used for temporary files
/etc/sudoers
Used to control the sudo permissions of every user on the system
/home
The directory where all your downloads, documents, etc. are like C:\Users\<user>
/root
The root user’s home directory like C:\Administrator
/usr
Where all your software is installed
/bin and /sbin
Used for system critical files - DO NOT DELETE
/var
The linux miscellaneous directory, a myriad of processes store data in /var
$PATH
Stores all the binaries you’re able to run same as $PATH on Windows
If you have any questions or remarks don’t hesitate to reach out on discord to therokdaba#9872.
Go back to the homepage of this website.