🚀Day 03- Essential Linux Commands

🚀Day 03- Essential Linux Commands

✨What are Linux Commands?

Linux commands are a set of instructions that can be executed in a Unix-like operating system (such as Linux, macOS, or FreeBSD) to perform various tasks, such as managing files, directories, processes, users, and system settings.

Linux commands can be used to perform a wide range of tasks, such as file management, text processing, system configuration, network operations, and more.

✨ Linux Commands By Category

1. File Management Commands

File Management Commands allow you to perform various operations on files and directories. Here are some commonly used file management commands:

  • ls: List the files and directories in a directory on the file system,

  • cd: Change the current working directory.

  • pwd: Print the current working directory.

  • mkdir: Create a new directory.

  • rmdir: Remove directory.

  • touch: Create a new file.

  • cat: Prints the contents of a file.

  • rm: Used to Remove (delete) files or directories from the file system.

  • cp: Used to copy files or directories from one location to another.

  • mv: Used to rename files or directories, as well as move them from one location to another.

  • chmod: Change the permissions (i.e., access permissions) of files and directories.

  • chown: Change the ownership of files and directories

  • find: The find command in UNIX is a command line utility for walking a file hierarchy. It can be used to find files and directories and perform subsequent operations on them. It supports searching by file, folder, name, creation date, modification date, owner, and permissions. By using the ‘-exec’ other UNIX commands can be executed on files or folders found.

  • locate: The locate command is a Unix utility used for quickly finding files and directories. The command is a more convenient and efficient alternative to the find command, which is more aggressive and takes longer to complete the search.

    Opposite to find, the locate command doesn't search the entire filesystem but looks through a regularly updated file database in the system. Thus, the search is completed much faster.

2. Text Processing Commands

Text processing commands are used for manipulating and processing text files or streams of text data. Here are some common text-processing commands:

  • grep: Search for patterns in files

  • sed: Stream editor for text manipulation

  • awk: Text processing tool for pattern matching and data extraction

  • sort: Sort lines of text

  • uniq: Report or omit repeated lines

  • cut: Remove sections from each line of a file

  • head: Display the first line of the files

  • tail: Display the last line of the files

  • more: The more command lets you view text files in your terminal one screen page at a time.

  • less: Less command is used to read the contents of a text file one page (one screen) at a time with navigation. It has faster access because if the file is large, it doesn’t access the complete file, but accesses it page by page.

  • wc: Count lines, words, and characters in files

3. System Management Commands

System management commands are used for managing various aspects of the system, including system configuration, process management, user management, and system monitoring. Here are some common system management commands:

  • ps: Display process status

  • top: Display system processes in real-time

  • df: Display disk space usage

  • du: Estimate file space usage

  • free: Display memory usage

  • uname: Display system information

  • shutdown: Shut down or reboot the system

  • su: Switch user or become superuser

4. Network Commands

Network commands are used for managing various aspects of networking, such as network configuration, network diagnostics, and network troubleshooting. Here are some common network commands:

  • ping: Test network connectivity

  • ifconfig: Configure network interfaces

  • netstat: Display network connections and statistics

  • nslookup: Query DNS for domain information

  • traceroute: Display the route and measure transit delays of packets

  • ssh: Securely connect to remote servers

  • scp: Securely copy files between local and remote systems

  • ftp: Transfer files to/from a remote server using FTP

5. User Management Commands

User management commands are used for creating, modifying, and managing user accounts, as well as setting user permissions and privileges. Here are some common user management commands:

  • useradd: Add a new user account

  • userdel: Delete a user account

  • passwd: Change user password

  • chsh: Change user shell

  • chage: Configure password expiration and account aging

  • id: Display user and group information

  • su: Switch user or become superuser

  • sudo: Execute commands with superuser or other user privileges

✨ Some of the examples of Linux Commands

  1. Check your present working directory

     pwd - command will show you the current working directory in which 
     you are working.
    
  2. List all the files or directories including hidden files

     ls - command is used to list the contents of a file and directory.
     ls -la - command list all including hidden files and directory.
    
  3. Create a nested directory X/Y/Z

     mkdir - command is used to make a new folder in a specific location
     mkdir -p  X/Y/Z - command create nested directory
    
  4. To view what's written in a file

     cat - command is used to print the contents of the file
     syntax - cat <filename?
     e.g cat file.txt
    
  5. To change the access permissions of file

     chmod - command is used to change the permission of the file & 
     directory
     syntax - chmod <permission> <filename>
     e.g chmod 644 file.txt
    
  6. To check which commands you have run till now

     history - command is used to display commands you have executed
     the terminal
    
  7. To remove a Directory / Folder

     There are two main commands are used to delete folders in Linux
     rmdir - command is used to delete empty folder
     rm - command is used to delete empty and non empty folder
     for eg. rmdir empty_folder_name
             rm -d empty_folder_name
             rm -r non_empty_folder_name
    
  8. To create a txt file and to view the content

     touch - command is used to create an empty file
     cat - command is used to view its content
    
  9. Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava

     vim - command is used to edit the file in linux and add a content
     into it.
     for e.g vim devops.txt
     press i to enter into insert mode then insert the data as per
     requirements 
     i.e 
     Apple
     Mango
     Banana
     Cherry
     Kiwi
     Orange
     Guava
    
  10. To Show only top three fruits from the file

    head - command is used to display first 10 lines of the file
    for e.g head -n 3 filename.txt
    
  11. To Show only bottom three fruits from the file

    tail - command is used to display last 10 lines of the file
    for e.g tail -n 3 filename.txt
    
  12. Create a Colors.txt file and Add content in Colors.txt file(One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey

    vim - command is used to edit the file in linux and add a content
    into it.
    for e.g vim Colors.txt
    press i to enter into insert mode then insert the data as per
    requirements 
    i.e 
    Red
    Pink
    White
    Black
    Blue
    Orange
    Purple
    
  13. To find the difference between fruits.txt and Colors.txt file

    diff - command to compare two text files and see the differences
    example:  diff devops.txt Colors.txt
    It will output all lines that are different between the two files
    

Thank you for reading. I hope you will find this article helpful. if you like it please share it with others

Mohd Ishtikhar Khan : )

Â