Linux Basic commands for Devops
List of important Commands:
find
tree
chmod
chown
umask
find
Search all empty files in the current directory
find . -type f -empty
where
. specify current directory
f specify type file and
-empty specify empty files
where
. specify current directory
f specify type file and
-empty specify empty files
Search only files in the current directory
find . type -f
Search files in the home directory
find ~ type -f
Search all empty files in the current directory
find ~ type -d -empty
Find the directories using names
find . -type d -name dir1
Files or directories with 777 permissions
find -type f -perm 0777
find -type d -perm 0777
Files with read permissions
find . -type f -perm /u=r
Files with execute permissions
find . -type f -perm /u=x
Find and remove multiple files
find . -type -f -name "*.sh" -exec rm -rf {} \;
Find all hidden files
find . type f -name ".*"
Find last 10 days modify files
find -type f -mtime 10
Find files in the specific directory
find /tmp -type f
Search all empty files in the user home directory
$ find ~ -type f -empty
Search all empty files on the server
# find / -type f -empty
chmod
How to create a directory using custom permissions?
# chmod -m 755 /dir1
# chmod -m 755 /dir1
Default values:
ROOT - 0022
NORMAL - 0002
ROOT - 0022
NORMAL - 0002
Permission table:
User Umask Directory permission File permission
NORMAL 0002 664 775
User Umask Directory permission File permission
NORMAL 0002 664 775
umask
How to calculate the UMASK values for file and directory permissions?
Base Permission for File => 0666
ROOT => 0666 - 0022 = 644
NORMAL => 0666 - 0002 = 664
ROOT => 0666 - 0022 = 644
NORMAL => 0666 - 0002 = 664
Base Permission for Directory => 0777
ROOT => 0777 - 0022 = 755
NORMAL => 0777 - 0002 = 775
ROOT => 0777 - 0022 = 755
NORMAL => 0777 - 0002 = 775
How to display the UMASK value?
$ umask
What are the default UMASK value for root and normal user?
User Umask Directory permission File permission
NORMAL 0002 664 775
NORMAL 0002 664 775
ROOT 0022 644 755
How to change the default UMASK value?
# umask 0222
Note: The value would set to the current specific session but not permanently
Example:
# umask
0022 ----------------- default value
# umask 0222
# umask
0222 ----------------- post modified the new UMASK value
How to set UMASK value permanently?
for specific user -> .bash_profile (user home location)
for all users -----> /etc/profile
Chmod
File or directory Permissions:
r -----------> read -----------> 4
w-----------> write ----------> 2
x -----------> execute -------> 1
If 664 means -----> rw-rw-r--
Owner Group Others
rw- rw- r--
read permission ======> chmod +r <file_name>
Execute permission ===> chmod +x <file_name>
Execture permission only for User ====> chmod u+x <file_name>
Write permission for user + group + others ===> chmod ugo+w <file_name>
Grants multiple permissions with a single command:
chmod u+rwx, g+x <file_name>
Tree
What is Inode?
It's a data structure, It can store file or directory information like permissions, owner, group name, size, timestamp. However, Inode doesn't contain file-name or directory-name.
display inode number: using "i" option
# ls -li
total 0
721864 drwxr-xr-x. 2 root root 6 Jan 18 17:58 DevOps
12792107 drwxr-xr-x. 3 root root 18 Jan 18 17:57 dir1
4326266 drwxr-xr-x. 2 root root 6 Jan 18 17:58 Python
8657718 drwxr-xr-x. 2 root root 6 Jan 18 17:59 Scripts
Comments
Post a Comment