<Linux Fundamental Part 2>
You might be familiar with these operators If you have ever learned computer science. && is used to execute two commands, but a first command must be executed successfully to execute a second command. For example, ls && echo hello will output a list of every directory and file and then 'hello'. However, if you put a wrong command, then it will fail too execute.
You can effectively use && with commands. For example, you can both create a file and put a content inside the file; touch a.txt && echo hello >> a.txt.
& is a background operator, which means, with &, you would be able to run other commands even though you are already running a command that takes some times.
In other words, let's say you're running a command that takes 10 seconds. If you use & operator, you would be able to run other commands during that period. For example, sleep 10 would have you wait for 10 seconds in which you can't do nothing but just wait. However, sleep 10 & allows you to do anything while sleep 10 is executed.
Also, note that & and && are completely different operators!
A special operator $ is used to denote environment variables. These are variables set by the computer that are used to affect different processes and how they work. Meaning that if you edit these variables you can change how certain processes work on your computer.
$USER is an environment variable that stores your current user. You can use this as an input for other commands.
Environment variables can be set pretty easily, just running export <varname>=<value> will set that as an environment variable.
The | operator (usually called a pipe) allows you to take the output of a command and use it as input for a second command.
For example, I used >> operator (we will get into this after finishing two other operators), and cat to get the output of a file and pipe that into grep to search for a specific string (we will learn grep later in part 3).
Some commands do not support the pipe so make sure to check if the commands you want to use support it.
The ; operator acts very similar to &&. However, unlike &&, it does not require the first command to execute successfully.
In other words, it will still execute if the first command fails to execute. For example, asfdsdf; ls will still work.
> is the operator for output redirection. You can redirect the output of any command to a file using > operator.
It is not useful if you use > to an existing file because It would completely erase the content of the file and replace it with the output from your command.
We've seen this operator already. The >> operator does mainly the same thing as >, with one key difference. >> appends the output of a command to a file, instead of erasing it.
As you can see, the blue and red circled one are called the user, and group attributes respectively. We can edit the permission for these attributes using the chown command.
The syntax for this command is chown user:group file. For example, if we want to change the owner of file to root as well as group to root, we could use chown root:root file.
Note that you can only use 'chown' if you are above that other users. If you are not an administrator user or part of owner, then you are not allowed to do with chown.
This chart shows the value of digits control.
chmod allows you to set the different permissions for a file, and control who can read it. The syntax of this command is typically chmod <permissions> <file>.
The permissions of file are set using a three digit number, where each digit controls a specific permission.
1st digit: controls the permissions for a user.
2nd digit: controls the permission for a group.
3rd digit: controls permissions for everyone that's not a part of the user or group.
Also note that 0 means no permission, meaning that you can put 770 if you want only user and group to have all permissions but everyone else.
As you can see, the red, blue, and black represents user, group and everyone else respectively. rw means 'read and write,' meaning that the user has permission to read and write and group has permission to read as well as everyone else. If we convert this to number form, it is 644.
rm means remove and it should be used carefully because it can completely destroy your Linux system if used carelessly.
However, if user, group, or everyone else don't have write permission to a certain file, they can't delete that file.
mv allows you to move files from one place to another. The syntax for this command is mv <file> <destination>.
For example, if I want to move a file to home directory I could type mv file ~.
You can also use mv to change the name of the file. mv <file> ./<name> will rename a file to whatever name you want to change to.
You have just finished Linux Fundamental 2!
Now that you have gained some knowledge to using Linux. Join the Linux Fundamental 3 room and master your Linux skills!