Top 50 Linux Commands You Should Know

op 50 Linux Commands You Should Know

Linux is a powerful and diverse operating system, so naturally, the command line offers a wealth of power and functionality. If you’re starting on your journey toward Linux mastery, here are a few of the most commonly used commands that will carry you a long way.

File Operations

  1. ls: Lists all files and directories in the present working directory. You can use flags like -l for long listing, -a to show hidden files, and -h to show file size in human-readable format.
  2. cd: Changes the current directory. You can use cd .. to go one directory up, cd / to go to the root directory.
  3. pwd: Displays the present working directory. It shows the full path starting from the root directory.
  4. touch: Creates a new file. For example, touch newfile.txt will create a new file named newfile.txt.
  5. cp: Copies files from the source directory to the destination directory. For example, cp source.txt destination.txt will copy source.txt to destination.txt.
  6. mv: Moves files between directories, or renames a file. For example, mv oldname.txt newname.txt will rename oldname.txt to newname.txt.
  7. rm: Deletes a directory or a file. Be careful with this command, as the deleted files cannot be recovered. Use -r flag to remove directories.
  8. find: Searches for files and directories. For example, find /home -name myfile.txt will search for myfile.txt in the /home directory.

Process Management

  1. ps: Displays your currently active processes. Use aux flags to view all running processes on the system.
  2. top: Displays all running processes and their usage of system resources like CPU and memory.
  3. kill: Kills a process. You need to know the PID (Process ID) of the process to kill it.
  4. bg: Sends a process to the background. This is useful if you have a process that you want to keep running while you do other things.
  5. fg: Brings a process to the foreground. If you have a process running in the background, you can bring it to the foreground with this command.

File Permissions

  1. chmod: Changes the permissions of a file or directory. Permissions are defined as a three-digit code, where each digit is an integer between 0-7.
  2. chown: Changes the owner and group of a file or directory. For example, chown user:group file.txt will change the owner of file.txt to user and the group to group.
  3. chgrp: Changes the group of a file or directory. For example, chgrp group file.txt will change the group of file.txt to group.

Networking

  1. ping: Sends an ICMP echo request to establish a connection to server/IP. This is useful for troubleshooting network connectivity issues.
  2. netstat: Displays network statistics. This is useful for checking your network connections, and for troubleshooting.
  3. ssh: Secure Shell to get remote control of any Linux machine. For example, ssh user@hostname will start a SSH session with hostname as user.
  4. scp: Securely copies files between hosts on a network. For example, scp source.txt user@hostname:/path will copy source.txt to /path on hostname as user.

Package Management

  1. apt-get: APT package handling utility (Debian). You can use apt-get install package to install a package, apt-get remove package to remove a package.
  2. yum: Package manager (Red Hat). Similar to apt-get, you can use yum install package to install a package, yum remove package to remove a package.
  3. dnf: Next-generation package manager (Fedora). It’s the successor to yum and uses the same syntax.

Disk Usage

  1. df: Shows disk usage. It displays the amount of disk space used and available on your filesystem.
  2. du: Estimates file and directory space usage. For example, du -sh /path will show the total disk usage of /path in human-readable format.
  3. fdisk: Disk partition manipulator. It’s a powerful tool for creating, deleting, resizing, and managing disk partitions.
  4. dd: Converts and copies a file. It’s a low-level command that allows you to make exact copies of a file, convert data formats, and more.

Text Manipulation

  1. cat: Concatenates and displays file content. For example, cat file.txt will display the content of file.txt.
  2. more: Views the contents of a file one screen at a time. This is useful for viewing large files.
  3. less: Opposite of the ‘more’ command. It allows backward navigation in the file as well as forward navigation.
  4. head: Displays the beginning of a file. For example, head -n 5 file.txt will display the first 5 lines of file.txt.
  5. tail: Displays the end of a file. For example, tail -n 5 file.txt will display the last 5 lines of file.txt.
  6. sort: Sorts the contents of a text file. For example, sort file.txt will sort the lines in file.txt.
  7. cut: Removes sections from lines of files. For example, cut -d':' -f1 /etc/passwd will display the first field of each line in /etc/passwd.
  8. wc: Counts lines, words, and characters in specified files. For example, wc -l file.txt will count the number of lines in file.txt.

System Information

  1. uname: Shows system information. For example, uname -a will display all system information, including machine name, kernel name, version, and more.
  2. uptime: Shows how long the system has been running. It displays the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.
  3. hostname: Displays the system’s host-name. This is the name that the system is known by to other systems on the network.
  4. useradd: Creates a new user. For example, useradd john will create a new user named john.
  5. userdel: Deletes a user account. For example, userdel john will delete the user john and his home directory.
  6. su: Switches the user ID to another user. For example, su john will switch the current session’s user to john.
  7. sudo: Executes commands as another user. For example, sudo apt-get update will run the apt-get update command with root privileges.
  8. passwd: Changes the user password. For example, passwd john will change the password for the user john.

Compression / Decompression

  1. tar: Stores and extracts files from a tape or disk archive. For example, tar -cvf archive.tar file1 file2 will create an archive named archive.tar from file1 and file2.
  2. gzip: Compresses or decompresses named files. For example, gzip file.txt will compress file.txt to file.txt.gz.
  3. gunzip: Decompresses files. For example, gunzip file.txt.gz will decompress file.txt.gz to file.txt.
  4. zip: Package and compress files. For example, zip archive.zip file1 file2 will create a compressed archive named archive.zip from file1 and file2.
  5. unzip: Extract files from a ZIP archive. For example, unzip archive.zip will extract all files from archive.zip.

Searching

  1. grep: Searches the input files for a pattern. For example, grep 'pattern' file.txt will search for pattern in file.txt.
  2. locate: Finds files by name. For example, locate file.txt will find all instances of file.txt in the system.

These top 50 Linux commands provide a solid foundation for efficiently navigating and managing your Linux system. Experiment with them in your terminal to gain confidence and proficiency, gradually unlocking the full potential of the command line.

Exit mobile version