Day - 2 Linux Commands for DevOps Engineer

Day - 2 Linux Commands for DevOps Engineer

Table of contents

No heading

No headings in the article.

As a DevOps professional, you'll frequently work with Linux systems and utilize various commands to manage and automate tasks. Here are some commonly used Linux commands along with explanations and examples:

  1. ls: This command lists files and directories in the current directory.

    Example:

    • ls -l lists files and directories in long format with detailed information.

    • ls -l--> list the files and directories in long list format with extra information

    • ls -a --> list all including hidden files and directory

    • ls *.sh --> list all the files having .sh extension.

    • ls -i --> list the files and directories with index numbers inodes

    • ls -d */ --> list only directories.(we can also specify a pattern)

  2. cd: Used to change the current directory.

    Example:

    • cd /var/www changes the current directory to "/var/www".

    • pwd --> print work directory. Gives the present working directory.

    • cd path_to_directory --> change directory to the provided path

    • cd ~ or just cd --> change directory to the home directory

    • cd - --> Go to the last working directory.

    • cd .. --> change directory to one step back.

    • cd ../.. --> Change directory to 2 levels back.

  3. pwd: Prints the current working directory.

    • Example: pwd displays the current directory path.
  4. mkdir: Creates a new directory.

    Example:

    • mkdir project creates a directory named "project".

    • mkdir directoryName --> to make a directory in a specific location

    • mkdir directoryName # make a new folder 'newFolder'

    • mkdir NewFolder # make a hidden directory (also . before a file to make it hidden)

    • mkdir A B C D #make multiple directories at the same time

    • mkdir /home/user/Mydirectory # make a new folder in a specific location

    • mkdir -p A/B/C/D # make a nested directory

  5. rm: Removes files and directories.

    • Example: rm file.txt deletes a file named "file.txt".

    • Example: rm -r directory deletes a directory and its contents recursively.

  6. cp: Copies files and directories.

    • Example: cp file.txt /tmp copies "file.txt" to the "/tmp" directory.
  7. mv: Moves or renames files and directories.

    • Example: mv file.txt newfile.txt renames "file.txt" to "newfile.txt".

    • Example: mv file.txt /tmp moves "file.txt" to the "/tmp" directory.

  8. touch: Creates an empty file or updates the access and modification timestamps of an existing file.

    • Example: touch file.txt creates an empty file named "file.txt".
  9. cat: Displays the contents of a file.

    • Example: cat file.txt outputs the content of "file.txt" to the console.
  10. grep: Searches for a specified pattern in files.

    • Example: grep "error" logfile.txt searches for the word "error" in "logfile.txt".
  11. chmod: Modifies file permissions.

  12. chown: Changes the owner of a file or directory.

    • Example: chown user:group file.txt changes the owner and group of "file.txt".
  13. ssh: Connects to a remote machine using the Secure Shell protocol.

    • Example: ssh user@hostname establishes an SSH connection to "hostname" as "user".
  14. scp: Securely copies files between local and remote systems using SSH.

    • Example: scp file.txt user@hostname:/path copies "file.txt" to the remote machine at "/path".
  15. wget: Downloads files from the web.

These commands are just a starting point, and there are many more available in Linux. Their usage may vary depending on your specific requirements and the tasks you need to accomplish as a DevOps professional.

Hope this is useful for you :)