Day 2- Basic Linux Commands

Day 2- Basic Linux Commands

Introduction to Linux:

  • Linux is a free and open-source operating system kernel initially developed by Linus Torvalds in 1991.

  • It is widely used in various devices, from servers and desktop computers to smartphones and embedded systems.

  • Linux offers stability, security, and customization, making it a popular choice among tech enthusiasts, developers, and businesses.

Basic Linux Commands:

  1. Check your present working directory:

    Use the pwd command to know your current location in the terminal.

    Example:

     bashCopy code$ pwd
     /home/user/Documents
    
  2. List all files and directories (including hidden files):

    Use the ls command to view the contents of the current directory.

    Example:

     shellCopy code$ ls
     file1.txt  file2.txt  folder1  folder2
    
     $ ls -a
     .  ..  .hidden_file  file1.txt  file2.txt  folder1  folder2
    
  3. Create a nested directory A/B/C/D/E:

    Use the mkdir command with the -p option to create nested directories.

    1. Example:

       cssCopy code$ mkdir -p A/B/C/D/E
      
  4. Change Directory (cd): Use the cd command to navigate to a different directory.

    Example:

     shellCopy code$ cd /home/user/Documents
    
  5. Remove Directory (rmdir): Use the rmdir command to remove an empty directory.

    Example:

     shellCopy code$ rmdir empty_directory
    
  6. Remove Files and Directories (rm): Use the rm command with the -r option to remove directories and their contents.

    Example:

     shellCopy code$ rm file.txt
     $ rm -r folder
    
  7. Copy Multiple Files (cp): Use the cp command to copy multiple files to a destination directory.

    Example:

     shellCopy code$ cp file1.txt file2.txt /home/user/Documents/
    
  8. Move Multiple Files (mv): Use the mv command to move multiple files to a destination directory.

    Example:

     shellCopy code$ mv file1.txt file2.txt /home/user/Documents/
    
  9. File Permissions (chmod): Use the chmod command to change file permissions.

    Example:

     shellCopy code$ chmod +x script.sh
    
  10. Display File Contents (less): Use the less command to view the content of a file page by page.

    Example:

    rubyCopy code$ less large_file.txt
    
  11. File Count (wc): Use the wc command to count the number of lines, words, and characters in a file.

    Example:

    shellCopy code$ wc file.txt
       10    25   200 file.txt
    
  12. Find Files (find): Use the find command to search for files or directories.

    Example:

    arduinoCopy code$ find /home/user -name "file*.txt"
    
  13. Create and Edit Text Files (nano): Use the nano command to create and edit text files in the terminal.

    Example:

    rubyCopy code$ nano new_file.txt