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…

Getting touch with Linux commands (part 4)


Here, we will cover how to move and rename files. Just like "cp" command for copying files as discussed in previous article "Linux commands part 3", we can use "mv" linux inbuilt command for moving files in Linux operating system. In this article we will discuss most of the useful syntax's with mv command.

mv : Move command in Linux operating system. 

syntax : mv <options>  <source> <destination>

* source could be one or more sources and destination can be another different filename when renaming. 

eg_1 : How to rename a file

Here, we have created some files with subject names.



But, we need to rename the file named "language" with "english".  To rename we can use mv command as below.

How to use mv command to rename a file ?


eg_2 : How to move a single / multiple files 

Here, we have created a directory named "marks".



And we need to move the files ( english, history, maths, science ) to the new directory named "marks". We use mv command as below.

How to use mv command to move multiple files to a new directory.

Guess, if you need to move only file named  "english". Then you can use command as below.

mv english marks/ 

eg_3 : How to move a directory to another location

Here, we have created a backup directory for subjects with name "backup_subjects". Now we have two directories.


Now we need to move the subjects directory with it's all content to be moved to backup directory. Below is the command.





When moving a directory, we don't need to move with recursive option like when copying. Please refer the article for "cp command in Linux" for more details.

* Keep in remind, when using mv command, last argument should be the destination. Check the below.

Guess we created new directories named test1, test2, test3.


We run the below command as in the image.


What does the above means ? It moves english, history, maths files and the directory test1 as well as to the directory test2.  So, the last argument should be the destination. Don't assume that the first 3 files will be moved to the mentioned 2 directories.



You have earned most of basics that must be aware in order to use mv command in Linux. There are more options you can use than the basics. Please go through man pages, info pages, man mv, info mv, mv --help. 

Other Linux commands resources



Cheers!

Comments

Post a Comment

Popular posts from this blog

Different types of users in linux

Understanding Linux File Permissions and Ownerships

SUDO: What is it in Linux ?