Neural Nets

Introduction to popular linux commands

/ 5 min read

Download As PDF

Linux is a powerful and flexible operating system that provides users with a robust command-line interface (CLI) to interact with the system. The command-line offers greater control, efficiency, and the ability to automate tasks. Mastering Linux commands can make you more productive and empower you to troubleshoot, manage, and configure systems. Here’s a guide to 40 of the most popular Linux commands, useful for both beginners and experienced users.


1. ls – List Directory Contents

The ls command lists the contents of a directory. By default, it shows files and subdirectories of the current directory.

  • Usage: ls
  • Options:
    • ls -l: Long listing format (permissions, size, owner)
    • ls -a: Show hidden files
    • ls -h: Human-readable sizes

2. cd – Change Directory

The cd command changes the current working directory.

  • Usage: cd /path/to/directory
  • Shortcuts:
    • cd ~: Navigate to home directory
    • cd ..: Move up one level in directory structure

3. pwd – Print Working Directory

This command prints the full path of the current directory.

  • Usage: pwd

4. cp – Copy Files and Directories

The cp command copies files or directories from one location to another.

  • Usage: cp source destination
  • Options:
    • cp -r: Copy directories recursively
    • cp -i: Prompt before overwriting

5. mv – Move or Rename Files

The mv command is used to move or rename files and directories.

  • Usage: mv source destination

6. rm – Remove Files and Directories

The rm command deletes files or directories.

  • Usage: rm file
  • Options:
    • rm -r: Remove directories and their contents recursively
    • rm -f: Force removal without prompting

7. touch – Create Empty Files

The touch command creates an empty file or updates the timestamp of an existing file.

  • Usage: touch filename

8. cat – Concatenate and Display File Content

The cat command displays the contents of a file on the terminal.

  • Usage: cat filename
  • Option:
    • cat -n: Number the lines

9. mkdir – Make Directories

The mkdir command creates a new directory.

  • Usage: mkdir directory_name
  • Option:
    • mkdir -p /path/to/dir: Create parent directories if needed

10. rmdir – Remove Empty Directories

The rmdir command removes empty directories.

  • Usage: rmdir directory_name

11. echo – Display a Line of Text

The echo command prints a line of text to the terminal.

  • Usage: echo "Hello World"

12. df – Disk Space Usage

The df command shows disk space usage of file systems.

  • Usage: df
  • Option:
    • df -h: Human-readable format

13. du – Directory Disk Usage

The du command estimates the file space usage of a directory.

  • Usage: du directory_name
  • Option:
    • du -h: Human-readable format
    • du -sh: Summary for a directory

14. find – Search for Files

The find command searches for files in a directory hierarchy.

  • Usage: find /path -name filename
  • Option:
    • find / -type d: Search for directories

15. grep – Search Inside Files

The grep command searches for patterns within files.

  • Usage: grep "pattern" file
  • Option:
    • grep -i: Case-insensitive search

16. chmod – Change File Permissions

The chmod command changes the permissions of files or directories.

  • Usage: chmod 755 file
  • Common permissions:
    • 755: Owner has full control, group and others can read/execute
    • 644: Owner can read/write, others can only read

17. chown – Change File Ownership

The chown command changes the ownership of a file or directory.

  • Usage: chown user:group file

18. ps – Process Status

The ps command displays information about running processes.

  • Usage: ps
  • Option:
    • ps aux: Detailed process view

19. kill – Terminate Processes

The kill command terminates a process by its PID (Process ID).

  • Usage: kill PID
  • Option:
    • kill -9 PID: Forcefully terminate a process

20. top – Real-Time Process Monitoring

The top command provides a real-time view of running processes and system resource usage.

  • Usage: top

21. tar – Archive Files

The tar command is used to compress or extract files from an archive.

  • Usage:
    • To create an archive: tar -cvf archive.tar file
    • To extract: tar -xvf archive.tar

22. zip – Compress Files

The zip command compresses files into a .zip archive.

  • Usage: zip archive.zip file

23. unzip – Extract Zip Archives

The unzip command extracts files from a .zip archive.

  • Usage: unzip archive.zip

24. wget – Download Files from the Web

The wget command downloads files from the web using HTTP, HTTPS, or FTP protocols.

  • Usage: wget http://example.com/file

25. curl – Transfer Data from a URL

The curl command retrieves content from a URL, supporting various protocols.

  • Usage: curl http://example.com

26. apt – Package Management (Debian-based)

The apt command manages software packages in Debian-based distributions (like Ubuntu).

  • Usage:
    • To install: apt install package
    • To update: apt update
    • To upgrade: apt upgrade

27. yum – Package Management (RedHat-based)

The yum command manages software packages on RedHat-based distributions like CentOS.

  • Usage:
    • To install: yum install package
    • To update: yum update

28. df – Disk Usage Overview

This command shows the disk usage on mounted filesystems.

  • Usage: df -h (human-readable format)

29. nano – Text Editor

The nano command opens a basic text editor in the terminal.

  • Usage: nano filename

30. vim – Advanced Text Editor

The vim command opens a more advanced, but highly efficient text editor.

  • Usage: vim filename

31. history – Show Command History

The history command displays the list of previously executed commands.

  • Usage: history

32. alias – Create Shortcuts for Commands

The alias command creates shortcuts for longer commands.

  • Usage: alias shortname='command'
  • Example: alias ll='ls -la'

33. ping – Test Network Connectivity

The ping command checks the network connection to a host.

  • Usage: ping google.com

34. netstat – Network Statistics

The netstat command shows network connections, routing tables, and interface statistics.

  • Usage: netstat -tuln

35. ss – View Network Sockets

The ss command is a faster and more efficient alternative to netstat.

  • Usage: ss -tuln

36. uptime – System Uptime and Load

The uptime command shows how long the system has been running and the system load.

  • Usage: uptime

37. whoami – Display Current User

The whoami command shows the currently logged-in user.

  • Usage: whoami

38. hostname – Display System’s Hostname

The hostname command displays or sets the system’s hostname.

  • Usage: hostname

39. man – Manual Pages

The man command shows the manual (help) pages for any Linux command.

  • Usage: man command
  • Example: man ls

40. reboot and shutdown – Restart or Power Off the System

  • To reboot: reboot
  • To shut down: shutdown now

Conclusion

These 40 Linux commands are some of the most commonly used and fundamental to managing a Linux system. Whether you are navigating the file system, managing processes, networking, or configuring your system, mastering these commands will significantly enhance your productivity and system management skills.