×
Community Blog Learning How to Use Common Linux Commands

Learning How to Use Common Linux Commands

This article lists and describes some of the most common commands of the Linux operating system.

Linux commands are used to manage Linux systems. CPU, memory, disk drives, keyboard, mouse, and users are all files on Linux systems. Commands for Linux system management are the core of normal system operation.

Note: The number in parathesis on each heading denotes the number of commands for each topic.

Online Query and Help Commands (2)

  • man: View the help information and dictionary of commands. info is a more complex command, which is not commonly used.
  • help: View the help information of built-in Linux commands, such as the cd command

File and Directory Operation Commands (18)

  • ls: Short for list; it lists the contents of directories and the content attribute information.
  • cd: Short for change directory; it switches the current working directory to a specified one.
  • cp: Short for copy; it copies files or directories.
  • find: Search for directories and their files
  • mkdir: Short for make directories; it creates directories.
  • mv: Short for move; it moves or renames files.
  • pwd: Short for print working directory; it displays the absolute path of the current working directory.
  • rename: Rename files
  • rm: Short for remove; it removes one or more files or directories.
  • rmdir: Short for remove empty directories; it removes empty directories.
  • touch: Create new empty files and change the timestamp attribute of existing files
  • tree: Display contents of a directory in a tree structure
  • basename: Display the file name or directory name
  • dirname: Display the file path or directory path
  • chattr: Change the extended attributes of files
  • lsattr: Display the extended attributes of files
  • file: Display the file type
  • md5sum: Calculate and verify the MD5 value of a file

Commands for Viewing Files and Processing Content (21)

  • cat: Short for concatenate, it concatenates multiple files and prints the results to the screen or redirects to a specified file.
  • tactac: It is the reverse spelling of cat. It displays the contents of the file in reverse.
  • more: Display file content by page
  • less: Display file content by page but used in the opposite way
  • head: Display the head part of the file content
  • tail: Display the tail part of the file content
  • cut: Cut each line in the file by the specified delimiter and output the results
  • split: Split a file into different small fragments
  • paste: Merge file contents by line
  • sort: Sort the text of a file
  • uniq: Remove duplicate lines
  • wc: Count the number of lines, words, or bytes of a file
  • iconv: Convert the encoding format of a file
  • dos2unix: Convert files from DOS format to UNIX format
  • diff: Short for difference; it mainly compares differences between text files.
  • vimdiff: A file comparison tool that is visible in the command line. It is mainly used for text files.
  • rev: Output the file content in reverse
  • grep/egrep: Filter strings; one of the three most commonly used commands
  • join: Merge two files by the same fields
  • tr: Replace or remove characters
  • vi/vim: A command-line text editor

Commands for File Compression and Decompression (4)

  • tar: Pack and compress files
  • unzip: Decompress files
  • gzip: A compression tool
  • zip: A compression tool

Information Display Commands (11)

  • uname: Display the information of the operating system
  • hostname: Display or set the hostname of the current system
  • dmesg: Display the power-on information for diagnosing system faults
  • uptime: Display the system uptime and load
  • stat: Display the status of a file or the file system
  • du: Calculate the disk space usage
  • df: Report the disk space usage of the file system
  • top: Display the system resource usage in real-time
  • free: Display the system memory
  • date: Display and set the system time
  • cal: Display the time information (such as the calendar)

File Search Commands (4)

  • which: Query binary commands based on the path of environment variable PATH
  • find: Search for files or directories by traversing the disk
  • whereis: Query binary commands based on the path of environment variable PATH
  • locate: Search for commands in databases (/var/lib/mlocate/mlocate.db) and update the database using updatedb

User Management Commands (10)

  • useradd: Add a user
  • usermod: Modify existing user attributes in the system
  • userdel: Delete users
  • groupadd: Add a user group
  • passwd: Change the user password
  • chage: Change the valid period of a user password
  • id: Display the UID, GID, and user group to which the user belongs
  • su: Switch the user identity
  • visudo: Command for editing the /etc/sudoers files
  • sudo: Run the commands permitted in the sudoers file as another user (root user by default)

Basic Network Operation Commands (11)

  • telnet: Use the TELNET protocol for remote login
  • ssh: Use the SSH encryption protocol for remote login
  • scp: Short for secure copy; it copies files between different hosts.
  • wget: Use command lines to download files
  • ping: Test the network connectivity between hosts
  • route: Display and set the routing table in Linux systems
  • ifconfig: Display, configure, enable, or disable network interfaces.
  • ifup: Enable the NIC
  • ifdown: Disable the NIC
  • netstat: Check the network status
  • ss: Check the network status

In-Depth Network Operation Commands (9)

  • nmap: The network scan command
  • lsof: Short for list open files, it lists all opened files in the system.
  • mail: Send and receive emails
  • mutt: The email management command
  • nslookup: Query DNS servers on the Internet interactively
  • dig: Query the DNS resolution process
  • host: Query DNS
  • traceroute: Track the route status of data transmission
  • tcpdump: The command-line tool for packet capture

Commands for Disks and File Systems (16)

  • mount: Mount a file system
  • umount: Unmount a file system
  • fsck: Check and repair Linux file systems
  • dd: Convert or copy files
  • dumpe2fs: Export information from files systems, including ext2, ext3, and ext4
  • dumpe: The backup tool for xt2, xt3, and xt4 file systems
  • fdisk: The disk partitioning command; it applies to disks less than 2 TB in size.
  • parted: The disk partitioning command with no requirement for the disk size; it is usually used for disks less than 2 TB in size.
  • mkfs: Create a Linux file system in a specific format
  • partprobe: Update the disk partition table of the kernel
  • e2fsck: Check the ext2, ext3, and ext4 file systems
  • mkswap: Create a Linux swap partition
  • swapon: Enable the swap partition
  • swapoff: Disable the swap partition
  • sync: Write data from memory buffers to the disk
  • resize2fs: Resize the ext2, ext3, and ext4 file systems

Commands Related to System Permission and User Authorization (4)

  • chmod: Change file or directory permissions
  • chown: Change the owner and group of a file or directory
  • chgrp: Change the user group of a file
  • umask: Display or set the permission mask

Commands for Viewing System User Login Information (7)

  • whoami: Display the currently valid username, which is equivalent to running the id -un command
  • who: Display the information about users currently logged in to the system
  • w: Display the list of users that have logged in to the system and the instructions being executed by users
  • last: Display the user logged in to the system previously
  • lastlog: Display the last login information of all users in the system
  • users: Display the list of all users currently logged in to the system
  • finger: Search for and display user information

Built-In Commands and Others (19)

  • echo: Print variables or output the specified string directly
  • printf: Format and output the results to standard output
  • rpm: Manage rpm packets
  • yum: Manage rpm packets in a simple and automatic manner
  • watch: Execute the specified command periodically and display the command output in full screen
  • alias: Set the system alias
  • unalias: Remove the system alias
  • date: Display or set the system time
  • clear: Clear the content on the screen
  • history: Display the execution history of commands
  • eject: Eject the drive
  • time: Calculate the command execution time
  • nc: A powerful network tool
  • xargs: Convert standard input to command-line parameters
  • exec: Call and execute the command
  • export: Set or display environment variables
  • unset: Delete variables or functions
  • type: Check whether another command is a built-in command
  • bc: The command-line scientific calculator

Commands for System Management and Performance Monitoring (9)

  • chkconfig: Manage startup items of Linux systems
  • vmstat: Display the virtual memory statistics data
  • mpstat: Display the status statistics data of each available CPU
  • iostat: Display the system I/O statistics data
  • sar: Obtain comprehensive performance data, including CPU, operation queue, disk I/O, paging (swap partition), memory, CPU interrupt, and network
  • ipcs: Report the status of inter-process communication facilities in Linux. The displayed information includes the message list, shared memory, and semaphore information.
  • ipcrm: Delete one or more message queues, semaphore sets, or shared memory identities
  • strace: Diagnose and debug user space trackers in Linux. It monitors interactions between users’ space processes and the kernel, such as system calls, signaling, and process status changes.
  • ltrace: Track the library function calls of the process and show which library function is called

Commands for Shutdown/Restart/Logout and System Information Check (6)

  • shutdown: Shut down the machine
  • halt: Shut down the machine
  • poweroff: Power off
  • logout: Log out from the Shell
  • exit: Log out from the Shell
  • Ctrl + d: The shortcut key for Logging out from the Shell

Process Management Commands (15)

  • bg: Execute the command that is paused in the background
  • fg: Call the commands in the background to the foreground to continue running
  • jobs: Check how many commands are currently running in the background
  • kill: Terminate the process
  • killall: Terminate a process by the name
  • pkill: Terminate a process by the name
  • crontab: Command for scheduled tasks
  • ps: Display the snapshot of the process
  • pstree: Display the process in a tree structure
  • nice/renice: Adjust the program running priority
  • nohup: Ignore the suspend signal and run the specified command
  • pgrep: Query processes that match the specified criteria.
  • runlevel: Display the current system running level
  • init: Change the running level
  • service: Enable, stop, restart, and disable system services. Display the current status of all system services.

This article was originally published on the Programmer Bai Nannan official WeChat account.

Disclaimer: The views expressed herein are for reference only and don't necessarily represent the official views of Alibaba Cloud.

0 0 0
Share on

Alibaba Cloud Community

871 posts | 198 followers

You may also like

Comments