♾️ DevOps and 🐧 Linux Commands: A Powerful DuoπŸ”₯

♾️ DevOps and 🐧 Linux Commands: A Powerful DuoπŸ”₯

Basics commands, Files and Directories operations

πŸ‘‰ Quick Intro

  • Linux is open source, which means it is free and you can make any changes in the source code and use your own Linux

  • Linux has multi-user support

  • Linux Torvalds used Unix OS to create his own OS, which is named Linux

  • It's essential to understand the fundamental Linux commands and how to use them effectively. This comprehensive guide will take you through a detailed exploration of these commands.

πŸ‘‰ Command Line Interface πŸ§‘β€πŸ’»

CLI is like talking to a computer using special words (commands), you type in commands, and the computer does what you say. It's a bit like magic πŸͺ„ words to make your computer do things.

What does CLI look like?

let's see what is written in CLI

  • user name of logged-in user

  • computer name

  • ~ is the home directory of logged-in user, which in this case is /home/ec2-user

  • # at the end represents the root user, like the admin user in Windows

  • $ at the end represents a normal user

  • pwd is a present working directory

πŸ‘‰ Types of files

  • Ordinary File / Normal File πŸ“

    • start with '-' in the ls -l command

    • contains data like text, images, audio, video, etc.

  • Directory File [folder] πŸ“‚

    • start with 'd' in the ls -l command

    • contains all kinds of files in it

  • Link File πŸ”—

    • start with 'l' in the ls -l command

    • it is a link to another file

look at the first character of each line

πŸ‘‰ Let's start with Commands βš™οΈ

  1. Basics commands βœ”οΈ

    pwd - present working directory, the current location of a user in the file structure

    cd - change directory

    whoami - it will display the current logged-in username

    who - shows logged-in users of the system

    date - display current date with time

    cal - display calendar

    history - get all commands that are executed in the past

    history n - get only 'n' recent commands that are executed in the past

    man <command> - it will give documentation of the command

    unzip <zip-file> - extract the zip file

    tar -xvzf <tar-file> - extract the tar file

  2. Create or delete files and directories πŸ“

    touch <file> - create an empty file

    touch <file1> <file2> ... - create multiple empty files

    touch file{1..5}.txt ... - create multiple empty files with numeric names as file1.txt file2.txt ... file5.txt

    cat > <file> - create a file with data [ctrl+d to save and exit]

    cat >> <file> - append file with data [ctrl+d to save and exit]

    cat <file> - display data in the file

    mkdir <dir> - create directory

    mkdir <dir1> <dir2> - create multiple directories

    mkdir -p dir1/dir2/dir3/dir4 - create nested directories

    mkdir dir{1..5}.txt ... - create multiple empty directories with numeric names as dir1.txt dir2.txt ... dir5.txt

    rm <file> - delete file

    rmdir <dir> - delete an empty directory

    rmdir <dir1> <dir2> - delete multiple empty directories

    rm -d <dir> - delete an empty directory

    rm -r <dir> - delete a non-empty directory

  3. File operations βš™οΈ

    cat file1 > file2 - copy content of file1 to file2

    cat file1 file2 > file3 - copy content of file1 & file2 to file3

    cp file1 file2 - copy content of file1 to file2

    cp -r dir1 dir2 - copy all files from dir1 to dir 2

    mv file1 file2 - rename or move file or dir

    cmp file1 file2 - display only the first difference

    diff file1 file2 - display all differences

  4. List files πŸ“ƒ

    ls - used to list files and dir in current dir [alphabetical order]

    ls <dir> - used to list files and dir in a given dir

    🚩 FLAGS

    ls -l - list files and dir with info

    ls -r - ordering files reversely alphabetical order

    ls -t - list files and dir by ordering them based on modified date and time

    ls -tr - ordering files reversely based on modified date and time

    ls -ltr

    ls -a - list hidden files also

    ls -R - shows files and dir with subdirectories content

  5. Read file data and details βœ”οΈ

    wc <file> - display no. of lines, words, and characters in the file

    🚩FLAGS

    -l --> Display only the number of lines

    -w --> Display only the number of words

    -c --> Display only the number of characters

    cat <file> - display the content of the file

    cat -n <file> : display the content of a file with line number

    tac <file> : display the content of the file line-wise from bottom to top

    rev <file> : each line in reverse order from top to bottom

    head <file> : display top lines of file [default is 10]

    head -n <number> <file> : display top n lines

    tail <file> : display bottom lines of file [default is 10]

    tail -n <number> <file> : display bottom n lines

    tail -n +<number> <file> : display lines from nth to last

    grep 'text' file : display matched lines with the file name

    grep 'text' * : search text in all files in the current dir

    grep -n 'text' : display matched lines with line number

    grep -l 'text' : display only file name

    grep -L 'text' : display file names that do not contain

    grep -v 'text' : Invert the string match

    grep -i 'text' file : search text in file [case insensitive]

    grep -R 'text' : search text in all subdirectory file

    grep ^text file : display lines that start with a text

    grep text$ file : display lines that end with a text

These basic Linux commands provide you with a solid foundation for navigating and managing your Linux system. As you continue your journey with Linux, you'll discover additional commands and tools that will empower you to perform more advanced tasks and streamline your system administration and development activities. Linux's robust command-line interface offers endless possibilities for customization, automation, and control, making it a powerful and versatile platform for a wide range of use cases.

Happy Learning !!! πŸ‘‹