DevOps Prerequisite Part -2 :Linux Most Useful Commands

Sabyasachi Ghosh
5 min readOct 28, 2022

--

Contents :

1.Managing File Permissions in Linux.

2.File & directory commands.

3.sudo user commands.

4.Package installation commands.

5.Disk usage commands.

6.System & hardware information commands.

7.User information commands.

Managing file permissions in Linux :

Permission Groups

For every file and directory in Linux, there are the sets of users for whom we specify permissions. They are:

  • Owners: The user who creates a file, folder, or process is the owner.
  • Groups: Groups refers to anyone who is in the same group as the owner.
  • Others: Any user who is neither the owner of the file/directory and doesn’t belong to the same group is assigned to others group.

Permission Types

There are only three things you can do to a file: Read it, Write to it (modify), or Execute it (run the code on the file). Therefore, in Linux each file or directory has three basic permission types:

  • read: The Read permission refers to a user’s capability to read the contents of the file.
  • write: The Write permissions refer to a user’s capability to write or modify a file or directory.
  • execute: The Execute permission affects a user’s capability to execute a file or view the contents of a directory.

implementation using chmod command:

# we see that chmod 777 file-name changes the permission from r-r-r to -rwx-rwx-rwx

File & Directory commands:

/ is your root directory
~ is your home directory

  1. pwd ( prints out the present working directory)

2. ls / ls -l / ls -al ( Lists the directories)

3.mkdir ( Makes new directories)

4. rmdir (Removes directories) : It removes only empty directories.

5. rmdir -v -p folder1/folder2

6. rm -rf <folder -name> It removes directories & sub-directories folders & files

7. touch <filename. Extension> creates a file

8. cp <file1><file2> Copies a file to another file

9. mv <source><destination> Move One file to another directory

10. cat <filename> Prints the contents of the file in the terminal.

11. nano <file name> : Edit a file using nano editor.

12. echo “text content” > <file name> : This overwrites content in a file.

13. echo “text content”>> <file name> : This adds new line to a file.

14. grep -i “filename to search” <file name> : Searches file/folder in directory.

Sudo User commands :

Ways to become sudo user in Linux OS.

why sudo user ? Because to install any packages we need to be in root directory. There are different ways to become root user

(1) sudo -i
(2) sudo -s
(3) sudo su -
(4) su -root
(5) su -

Package Installation commands:

1. Install package with help of yum command which will look like 

yum install package_name

2. yum info package_name
this is going to display brief detail about a package

3. yum remove package_name
this is going to remove the package

4. Installing a package from a local file ./filename

Disk usage commands:

Disk Usage commands 

1. du pathofdirectory
- To find out the disk usage summary

2. du -h pathofdirectory
This will bring up your information in human readable format

3. du -sh nameofdirectory
This is to find out total disk usage

System & Hardware information commands:

System & hardware information 

1. uname -a
- a here is for all
2. uname -s
- to know the kernel name
3. uname -r
- print kernel release version
4. uname -m
- print Architecture
5. uname -o
- print your operating system

User information commands:

User information :- 

1. who
- Login name of the user
- Date & Time of login
- remote host name of user

2. whoami
- It is displaying the system's username

3. id
- it displays the user identification
(real and effective group id's)

4. groups
- this commands is used to display the groups
for which the user is belonging to.

--

--

No responses yet