whoami: Display current usernameid: Return User identityhostname: Sets or print name of current hostuname: print basic information about system name and hardwarepwd: present working dirifconfig: utility tool for networkingip: ip is utility to show or manipulate the routing , network devices , interface and tunnelsnetstat: show network statusss: utility to investigate socketsps: show process statuswho: display who is loginenv: Prints environment variableslsblk: list block deviceslsusb: list usb deviceslsof: list opened fileslspci: list pci devices
touch <name>to create new filemkdir <name>to create new foldermkdir -p /path/to/dirthis will create the nested dirtree .to see whole structuretouch ./apple/ball.txtto create the file inside the foldermv <file/directory> <renamed file/directory>use to move and rename the file and dirmv information.txt readme.txt Storage/move information and readme to storage folder
cp <file/directory> <renamed file/directory>use to copy file and folder
which pythonThis allows us to determine if specific programs, likecURL, netcat, wget, python, gcc,are available on the operating system.find <location> <options>use to locate the file and folder
| Option | Description |
|---|---|
-type f |
Hereby, we define the type of the searched object. In this case, 'f' stands for 'file'. |
-name *.conf |
With '-name', we indicate the name of the file we are looking for. The asterisk (*) stands for 'all' files with the '.conf' extension. |
-user root |
This option filters all files whose owner is the root user. |
-size +20k |
We can then filter all the located files and specify that we only want to see the files that are larger than 20 KiB. |
-newermt 2020-03-03 |
With this option, we set the date. Only files newer than the specified date will be presented. |
-exec ls -al {} \; |
This option executes the specified command, using the curly brackets as placeholders for each result. The backslash escapes the next character from being interpreted by the shell because otherwise, the semicolon would terminate the command and not reach the redirection. |
2>/dev/null |
This is a STDERR redirection to the 'null device', which we will come back to in the next section. This redirection ensures that no errors are displayed in the terminal. This redirection must not be an option of the 'find' command. |
-
locateis faster command thanfindsince it uses the local db to search -
sudo updatedbto update the dir database -
>to forward output -
2>to forwardSTDERR -
1>to forwardSTDOUT -
<to give input to something -
>>is use to append result since>will override the results -
cat << EOF > stream.txtwe will use the cat command to read our streaming input through the stream and direct it to a file called "stream.txt." -
Another way to redirect STDOUT is to use pipes
(|). -
These are useful when we want to use the STDOUT from one program to be processed by another. One of the most commonly used tools is grep
-
find /etc/ -name *.conf 2>/dev/null | grep systemd -
The redirections work, not only once. We can use the obtained results to redirect them to another program. For the next example, we will use the tool called wc, which should count the total number of obtained results.
-
head /etc/password -
tail /etc/password -
tail -f /etc/log -
cat /etc/passwd | grep "/bin/bash"use -v flag in grep for excluding the result -
cat /etc/passwd | sortsort the output -
cat /etc/passwd | grep -v "false\|nologin" | cut -d":" -f1- Specific results with different characters may be separated as delimiters. Here it is handy to know how to remove specific delimiters and show the words on a line in a specified position. One of the tools that can be used for this is cut. Therefore we use the option "-d" and set the delimiter to the colon character (:) and define with the option "-f" the position in the line we want to output.
-
cat /etc/passwd | grep -v "false\|nologin" | tr ":" " "- Another possibility to replace certain characters from a line with characters defined by us is the tool tr. As the first option, we define which character we want to replace, and as a second option, we define the character we want to replace it with. In the next example, we replace the colon character with space.
-
cat /etc/passwd | grep -v "false\|nologin" | tr ":" " " | column -t- Since search results can often have an unclear representation, the tool column is well suited to display such results in tabular form using the "-t
-
cat /etc/passwd | grep -v "false\|nologin" | tr ":" " " | awk '{print $1, $NF}'- As we may have noticed, the line for the user "postgres" has one column too many. To keep it as simple as possible to sort out such results, the (g)awk programming is beneficial, which allows us to display the first ($1) and last ($NF) result of the line.
-
cat /etc/passwd | grep -v "false\|nologin" | tr ":" " " | awk '{print $1, $NF}' | sed 's/bin/HTB/g'-
There will come moments when we want to change specific names in the whole file or standard input. One of the tools we can use for this is the stream editor called sed. One of the most common uses of this is substituting text. Here, sed looks for patterns we have defined in the form of regular expressions (regex) and replaces them with another pattern that we have also defined. Let us stick to the last results and say we want to replace the word "bin" with "HTB."
-
The "s" flag at the beginning stands for the substitute command. Then we specify the pattern we want to replace. After the slash (/), we enter the pattern we want to use as a replacement in the third position. Finally, we use the "g" flag, which stands for replacing all matches.
-
-
grep -e "pattern"-e flag is use for pattern