Skip to main content

Command Palette

Search for a command to run...

Basic Linux Commands For DevOps

Updated
•5 min read•View as Markdown
H

👋 Hi, I’m Huzefa Ahmed, and I’m starting my DevOps engineering journey! 🚀 I’m passionate about AWS DevOps and aim to land a full-time role in this field.

As I dive into cloud technologies, automation, and continuous integration, I’ll share my progress, insights, and challenges. Let’s connect, learn, and grow as a DevOps community!

Follow my journey on Hashnode and LinkedIn as I work towards securing a job in DevOps!

LinkedIn: https://www.linkedin.com/in/huzefa-ahmed-15720b278/

What is Linux?

Linux is an open-source operating system. An operating system is the software that directly manages a system's hardware and resources, like CPU, memory, and storage. The OS sits between applications and hardware and makes the connections between all of your software and the physical resources that do the work.

Architecture of Linux

The architecture of the Linux system is a layered structure that comprises several components, each with a specific function.

The main components of the Linux operating system are:

  1. Application: This is the topmost layer of the Linux architecture and consists of the various applications that run on top of the operating system and interact with its components.

  2. Shell: The shell is a command-line interface that allows users to interact with the system through a set of commands.

  3. Kernel: The kernel is the central component of the Linux operating system architecture. It manages system resources and provides services to applications and processes running on the system.

  4. Hardware: This is the bottommost layer of the Linux architecture and represents the physical hardware components of the computer, such as the processor, memory, and storage. The hardware layer is responsible for interacting with the various hardware devices and providing access to them for the rest of the operating system.

➡Basic Linux Commands

1. File and Directory Management:

  • pwd: Displays the current working directory.

    • Example: pwd
  • ls: Lists files and directories.

    • Example: ls -l
  • cd: Changes directory.

    • Example: cd /path/to/directory
  • mkdir: Creates a new directory.

    • Example: mkdir new_folder
  • rm: Removes files or directories.

    • Example: rm filename or rm -r directory_name
  • rmdir: Removes an empty directory.

    • Example: rmdir empty_directory
  • cp: Copies files or directories.

    • Example: cp source_file destination_directory
  • mv: Moves or renames files or directories.

    • Example: mv oldname newname
  • touch: Creates a new empty file.

    • Example: touch newfile.txt
  • ln: Creates a hard link to a file.

    • Example: ln file link
  • ln -s: Creates a symbolic (soft) link to a file or directory.

    • Example: ln -s /path/to/file link

2. File Viewing and Editing:

  • cat: Displays file content.

    • Example: cat filename
  • zcat: Displays the content of compressed files without uncompressing them.

    • Example: zcat file.gz
  • head: Displays the first few lines of a file.

    • Example: head filename
  • tail: Displays the last few lines of a file.

    • Example: tail filename
  • more: Views file content one screen at a time.

    • Example: more filename
  • wc: Counts words, lines, and characters in a file.

    • Example: wc filename
  • cut: Cuts parts of a line or file by delimiter.

    • Example: cut -d ' ' -f 1 filename
  • sort: Sorts the content of a file.

    • Example: sort filename
  • diff: Compares the content of two files line by line.

    • Example: diff file1 file2

3. Process Management:

  • ps: Displays running processes.

    • Example: ps aux
  • top: Displays real-time system resource usage.

    • Example: top
  • kill: Terminates a process by its PID.

    • Example: kill 1234
  • nohup: Runs a command immune to hangups.

    • Example: nohup command &
  • vmstat: Displays system performance statistics.

    • Example: vmstat
  • fuser: Identifies processes using a file or socket.

    • Example: fuser filename

4. System Information:

  • uname: Displays system information.

    • Example: uname -a
  • uptime: Shows system uptime.

    • Example: uptime
  • free: Displays memory usage.

    • Example: free -h
  • date: Displays or sets the system date and time.

    • Example: date
  • who: Displays who is logged into the system.

    • Example: who
  • whoami: Displays the current user.

    • Example: whoami
  • id: Displays user ID and group information.

    • Example: id
  • which: Locates the executable path of a command.

    • Example: which command
  • hostname: Shows or sets the system's hostname.

    • Example: hostname
  • watch: Runs a command repeatedly, showing output changes over time.

    • Example: watch df -h

5. User and Permission Management:

  • useradd: Creates a new user.

    • Example: sudo useradd username
  • su: Switches to another user account.

    • Example: su username
  • userdel: Deletes a user.

    • Example: sudo userdel username
  • groupadd: Creates a new group.

    • Example: sudo groupadd groupname
  • gpasswd: Administers group memberships.

    • Example: sudo gpasswd -a username groupname
  • umask: Shows or sets the default file creation permissions.

    • Example: umask
  • chmod: Changes file permissions.

    • Example: chmod 755 filename
  • chown: Changes file ownership.

    • Example: chown user:group filename
  • chgrp: Changes group ownership of a file.

    • Example: chgrp groupname filename

6. Networking Commands:

  • ssh: Connects to a remote server via SSH.

    • Example: ssh user@hostname
  • scp: Securely copies files between hosts.

    • Example: scp file user@hostname:/path
  • rsync: Syncs files between directories or hosts.

    • Example: rsync -av source destination
  • traceroute: Traces the route packets take to a network host.

  • tracepath: Similar to traceroute but requires no superuser privileges.

  • mtr: Combines traceroute and ping.

  • nslookup: Queries DNS for domain name information.

  • telnet: Connects to remote hosts via the Telnet protocol.

    • Example: telnet hostname
  • ip: Shows or manipulates IP addresses and routing.

    • Example: ip addr show
  • iwconfig: Configures wireless network interfaces.

    • Example: iwconfig
  • ss: Displays socket statistics.

    • Example: ss -tuln
  • dig: Queries DNS information.

  • whois: Queries information about domains.

  • nc: Netcat command for sending data across the network.

    • Example: nc -l 12345
  • arp: Displays or modifies the ARP table.

    • Example: arp -a
  • ifplugstatus: Checks network cable status.

    • Example: ifplugstatus
  • iptables: Configures IP packet filter rules.

    • Example: sudo iptables -L

7. Archiving and Compression:

  • zip: Compresses files into a ZIP archive.

  • unzip: Extracts files from a ZIP archive.

  • tar: Archives files into tarballs.

    • Example: tar -cvf archive.tar file_or_directory

8. Shutdown and Reboot:

  • sudo shutdown: Shuts down the system.

    • Example: sudo shutdown -h now
  • sudo reboot: Reboots the system.

    • Example: sudo reboot

9. Miscellaneous:

  • cat /etc/passwd: Displays system user information.

    • Example: cat /etc/passwd
  • route: Shows or manipulates the IP routing table.

    • Example: route -n
  • nmap: Scans networks for open ports and services.

    • Example: nmap 192.168.1.1

More from this blog

Devops Journey

11 posts