Unix 1 — introduction
The first few blogs will be focused on Unix commands. Coming from a non-technical background myself, I do try my very best to avoid commands. However, from my first-hand experience, this strategy is going to work. As such I can’t emphasise enough on the importance of learning the commands. I am half way through all Pentesterlab exercises now. I can safely say that there are only a handful commands that we must know really well at this stage.
I will also briefly touch on the find command but will go into more detail in the next session.
- id and pwd
After opening the terminal, it is usually a good idea to find out who you really are and where you currently are in the directory tree by typing in id command and pwd command.
2. cd and ls
The cd command can help you to move to a different directory. For example, by typing in cd .. you will be able to move up a directory. If you would like to know what directories and files are in the directory, you could type in is. The ls –a command can be used to view any hidden files.
For example, you could use cd /mnt to go into the mnt directory. I am using the Kali app on Windows10, so I will see my c drive and d drive in mnt.
After I am in mnt, I could just type in cd c to go into my c drive.
3. cat
To view a file, it is really as simple as typing in cat [ filename] if you are in the directory where the file is. Here is a trick if you don’t want to type in the full file name. You only need to type in the first few letters, then hit the Tab key.
For example, I would like to see what is in bootstrap.css. It is such a long name, so I typed in cat boo then hit the tab key to get the full command cat bootstrap.css.
Another trick to find the command that you previously executed quickly is to use the up arrow key on your keyboard.
All these commands are stored in .bash_history. Please note that the file starts with . a dot. This means it’s a hidden file, so as mentioned previously, you will need to use ls –a to see whether .bash_history is in the current directory.
4. find
To carry out a simple search on a file, you could type in find –name [filename]. For example, I would like to find my bootstrap.css file. I would type in find –name bootstrap.css and there it is!
We will go into more details about the find command and how it combines with grep as a filter for your search in the next session.