technical skills grow

Responsive Ads Here

Sunday, May 31, 2020

File Permissions | Creating | Removing |Copying | Moving files & Directories | Cat |touch | mkdir | cp | Renaming File (mv) | Vim | Soft Link | Hard link

1.BASIC COMMANDS

How to Creating, Removing, Copying, Moving files & Directories in Linux

Using cat command:

[root@dev ~]# cat > filename1
This is world file                                Ctrl+d (To save the file)

To display the content of the file

[root@dev ~]# cat filename1
This is world file

To display the content of the file

[root@dev ~]# cat >> filename1
This second line
[root@dev ~]# cat filename1
This is world file This second line

Creating multiple files at same time using touch command

[root@dev db_bak]# touch file{1..5}
[root@dev db_bak]# ls
file1  file2  file3  file4  file5

2.Creating a Directory:

[root@dev db_bak]# mkdir dir1
[root@dev db_bak]# ls
dir1

Making multiple directories inside a directory

 [root@dev ~]# mkdir -p technology/{linux/{shell_script,linux},java/{basic,adv_java},mysql/{DBA,Dev}}

[root@dev ~]# tree technology/
technology/
|-- java
|   |-- adv_java
|   `-- basic
|-- linux
|   |-- linux
|   `-- shell_script
`-- mysql
    |-- DBA
    `-- Dev

9 directories, 0 files
 

Copying files into directory

[root@dev ~]# ls
filename    

[root@dev ~]# cp filename technology/
[root@dev ~]# ls
filename  

[root@dev ~]# cd technology/
[root@dev technology]# ls
filename  java  linux  mysql

Copying directories from one location to other

[root@dev technology]# cp -rvfp java  linux/
‘java’ -> ‘linux/java’
‘java/basic’ -> ‘linux/java/basic’
‘java/adv_java’ -> ‘linux/java/adv_java’
[root@dev technology]# cd linux/
[root@dev linux]# ls
java  linux  shell_script

Moving files from one location to other (cut and Paste)
[root@dev technology]# ls
filename  java  linux  mysql
[root@dev technology]# mv filename  java/

[root@dev technology]# cd java/
[root@dev java]# ls
adv_java  basic  filename

Moving a Directory from one location to other

[root@dev technology]# ls
java  linux  mysql
[root@dev technology]# mv java/ linux/
[root@dev technology]# ls
linux  mysql
[root@dev technology]# cd linux/
[root@dev linux]# ls
java  linux  shell_script

4.Renaming a File

[root@dev linux]# ls
java  linux  shell_script
[root@dev linux]# mv linux/ linux_adv
[root@dev linux]# ls
java  linux_adv  shell_script

[root@dev linux]# rm file

rm: remove regular empty file ‘file’? y

6.Vim editor command

Command Mode:
gg     To go to the beginning of the page
G       To go to end of the pagew
b       To move the cursor forward, word by word
nb     To move the cursor backward, word by word
nw    To move the cursor forward to n words (5W)
nb     To move the cursor backward to n words (5B)
u       To undo last change (word)  

Ctrl+R   To redo the changes

yy    To copy line 

nyy   to copy no of line

dd    to delete line 

p     to past line

7.Symbolic Link :-  There are two types of Links

 Soft Link :                                                       

1. Size of link file is equal to no. of characters in the name of original file
2. Can be created across the Partition
3.Inode no. of source and link file is different
4.if original file is deleted, link is broken and data is lost
5.SHORTCUT FILE

[root@dev ~]# ln -s /aws/  aws.slink 

Hard link :

1. Size of both file is same
2 .Can't be created across the partition
3.Inode no. of both file is same
4.If original file is deleted then also link will contain data
5.BACKUP FILE

[root@dev ~]# ln  /aws/  aws.hlink  

8.File Permissions:

Permissions are applied on three levels:-
 Owner or User level
 Group level
 Others level
Access modes are of three types:-
 r  - read only
 w - write/edit/delete/append
 x  - execute/run a command

[root@dev ~]# chmod u=rwx,g=rw,o=r filename
[root@dev ~]# ls -l filename
-rwxrw-r--. 1 root root 13 Nov 18 15:35 filename

2 Absolute Method (numbers) In Absolute method we use numbers instead of using symbols i.e.
Read=4
Write=2
Execute=1

[root@dev ~]# chmod 764 filename
[root@dev ~]# ls -l filename
-rwxrw-r--. 1 root root 13 Nov 18 15:35 filename

Removing all permissions from others
[root@dev ~]# chmod 760 filename (where 0 indicates no permissions)

Umask:
When we create any file using touch, cat or vi commands they get created with default file permissions as stored in umask (User file creation mask).

[root@dev ~]# umask
0022

Calculation of default permissions for file and directory, basing upon the umask value
Note: For a file by default it cannot have the execute permission, so the maximum full permission for a file at the time of creation can be 666 (i.e. 777 -111 = 666), whereas a directory can have full permissions i.e. 777

The full permission for the file                         666
Minus the umask value                                   -022
The default permission for file is                     644  (rw-,r--,r--)


The full permission for the directory                777

Minus the umask value                                    - 022 

The default permission for file is                    755 (rwx, r-x, r-x)


No comments:

Post a Comment

Powered by Blogger.

Labels

Contact Form

Name

Email *

Message *

Search This Blog

Blog Archive

Ad Code

Responsive Advertisement

Recent Posts