Understanding Linux File Permissions and Ownerships

Image
From one of our previous articles "How to manage Linux Users and Groups" we discussed on how Linux becomes a multi-user OS, what is a user and a group with their configurations. By design, even though Linux allows multiple users can use the same computer in the same time without affecting others, Linux doesn't allow you to access or modify files belonging to other users. If Linux allows you to do it, that would be a security risk. But somehow they have implemented a security measure to mitigate that security risk. With that we can make sure only desired users and groups can access the relevant files and directories.

If we take a small demonstration. Here, we will log in as a normal user and try to access a root directory.


It gave a permission denied error when accessing. Why ? That's because /root directory is owned by user root. Only a privileged user can access or modify that.

So, Linux introduces two kind of factors which tells who can access or modify a file as w…

Linux Commands Tips and Tricks

Have you ever noticed a moment when someone doing tasks with some simple terminal commands which took a long time for you to do. And you feels like to asking from yourself "Wow, How did he do that very easily ?"  Then you think yourself, If i also could do like that.

Yeah. That's fine. From this article we discuss most of the tips you should know, some sort of pretty, tiny commands. But they will be very useful. Go through the complete article and make yourself to hear a Wow from someone else. It will make you very comfortable.

1) Execute a previous command

Normally every command that we type is storing in a file named ".bash_history" inside of your home directory. To view the the past typed commands we can use the command history in your terminal. It will list all the commands that you typed.


There are some options we need to know

  • !! : This will run the last command in the history. According to the above image, !! will rerun the history command. 
  • !<number> : If you need to run a specific command in the history. Assume you need to run first command which means tree command according to the above image. It should be !1
  • history | grep <keyword> : This will search the keyword in history. 
  • UP keyboard button press also will take you to the past history commands. 

2) How to clear the terminal

Use command clear to clear the terminal window. 

3) Use Tab auto completion

Use Tab keyboard press to auto complete the commands. This was discussed in a previous article with examples. Please refer "How to get help from Linux". 

4) Changing directories

cd - : Go to the last directory where you were. 
cd ~ : Go to the home directory
cd : Go to your home directory ( same as above command )
cd .. : Go to the previous location. Means one step back. 

5) Run multiple commands in one single line

You can do this just putting a semi colon ";" in between commands. Like below. 

command_1 ; command_2 ; command_3

With this you can run several commands in one single line without waiting to be completing other commands. Means, second commands don't want to wait till first command gets completed. It saves time. 

6) Run multiple commands in one single line, but finishing one after second. 

command_1 && command_2 && command_3

Here, the command waits for the completion of it's previous command. This is useful to trigger if the commands are getting fail. If one commands is failing, next command will not be run. 

7) Search and run previous commands without referring history. 


Ctrl + r + <search keyword>

This is a very useful command that will be helped you a lot. You just press the control key and r letter in the keyboard. Then enter the search keyword you need to find. Then it will show you the most nearest command suits for your keyword in the history. It searches from bottom to top on history. To keep finding the required command, just press Ctrl + r in the keyboard and enter when you found.


8) Vim Cheat sheet

:w : Save the file
:wq : Save the file and quite
:q : Quite the file without saving
:wq! : Forcefully save and quite the file
:q! : Forcefully quite the file without saving
yy  : yank ( Copy a line to the text editor )
p : Paste the copied content into the text editor.
dd : Delete a line
x : Delete a character
/<keyword> : search for a keyword in text file
gg : Go to the first line of the text editor
G : Go to the last line of the text editor
:set num : View the document showing line numbers
i : Insert mode

9) Displaying the files with more lines

Use command less to view the files which have more lines. Use arrow UP and DOWN in the keyboard to go though the file.

less <filename>

10) Make a file empty without deleting.

Use echo  > filename command. This will send a blank character to that file and will replace every content in the file.


In this article, we have mentioned 10 useful tips for you. You can refer more with man pages. Practice more.

Cheers!

Comments

Popular posts from this blog

Different types of users in linux

SUDO: What is it in Linux ?