<Linux Fundamental Part 3>
In part 3, we are going to learn advanced file operators (continued from Linux Fundamental Part 2), users & groups, and introduction to shell scripting.
cp does exactly the same thing as mv, except instead of moving it, it duplicates it. The syntax for this command is also the same as mv: cp <file> <destination>
cd allows you to change the location of the current directory and the syntax for this command is cd <directory>. Relative and absolute paths are supported.
mkdir allows you to make a new directory to store files in and the syntax for this command is mkdir <directory name>.
ln has two different main uses. One of those is hard linking, which completely duplicates the file, and links the duplicated file to the original copy.
The syntax for this command is ln <source> <destination>.
Make sure to use ln carefully because it can be very easy to erase data from a file.
The next form of linking is called symbolic link (or symlink). Symbolic link is just a reference, meaning that actual symbolic link does not contain data at all.
The syntax for this command is ln -s <file> <destination>.
ls -al shows what is linked with a symbolic link. It's important to know permission on the symlink. As you can see the picture, the file has 777 perms, which means you have execute, write, and read perms. The symlink has the same permission as the original file.
find lists every file in the current directory. It's worth nothing that find is recursive so if you are to run find /, then it will list every file on the OS. Another thing to know is that it only lists files that you have permission to access.
find is very useful. You can use find dir -user or find dir -group to see the list every fil owned by a user or group. These commands are effectively useful when working with files.
grep is one of the most useful commands to learn. It allows you to find the data inside of data. grep is the best command to narrow the output down to find what you're looking for when working with large files. The syntax for this command is grep <string> <file>.
You can also search multiple files simultaneously using grep <string> <file1> <file2>.
For example, you can find where the file is if you know the name of the file or you can find out whether what you're looking for is in the file and what line number is in it by using grep.
sudo is Linux's run as administrator button. The syntax for this command is sudo <command>.
When using sudo, the command is automatically run as root.
For example, type sudo -i and enter password to run Linux as root.
If you are an administrator in Linux, you have a permission to add users or group into a part of your administrator.
The syntax for this command is adduser <username>.
If you want to add a user to a group, the syntax for this is usermod -a -G <groups separated by commas> <user>.
nano is a terminal based text editor.
The syntax for this command is nano <file you want to write to>.
Other text editors like gedit are also used in Linux.
Linux provides us a way to run commands one after another without using any special operators. This is done by storing the commands you want to run in a file with a .sh extension.
bash <name of the file>.sh will execute commands inside of files in order, as shown in the picture.
Also, note that sh extension isn't necessary if you provide a shebang(#!), and then path to the shell you want to use to run commands.
When working with files and directories, it's important to know how the Linux file system works. Everything on the Linux file system extends from "/", which is equivalent of C: in Windows. For example if you were to delete "/", you would delete every file on your system.
Here's some lists of Linux file system:
/etc/passwd -stores user information
/etc/shadow -has all the passwords of users
/tmp -used for temporary files
/etc/sudoers -controls the sudo permissions of every user on system
/home -The directory where all your downloads and etc are. equivalent of C:\user\<user> in Windows
/root -The root user's home directory
/usr -where all your software is installed
/bin and /sbin-used for system critical files. Must not delete
/var -miscellaneous directory
$PATH -stores all the binary you are able to run
You can install any programs in Linux. However, you must need root to have permission to do so. The syntax for installing packages is apt install <packages>.
You can look it up to find many different packages to install on google or whatever browser you use.
ps command allows you to see a list of user created processes.
To view a list of all the system processes, use the -ef flag
The 3-5 digits in the second column is called Process ID's(PID's) and they are how you interact with processes. If you want to stop these processes, use kill <PID>.
The top commands show you what processes are taking up the most system resources. You can manage the resource allocation on your system through it.
Congratulations! You have finished all Linux fundamental series. It's just a first step to reach to be an ethical hacker.
Good Luck with your long journey on TryHackMe!