50 common commands of Ubuntu with examples

The following are commonly used commands in Ubuntu, prioritized according to the commands that are most likely to be forgotten, the top 50:

  1. sudo: Command to execute commands with administrator privileges in Ubuntu. Example: To edit a file with administrator privileges /etc/hosts: sudo nano /etc/hosts.

  2. apt-get: Commands for installing, upgrading, and removing packages in Ubuntu. Example: install nginxpackage: sudo apt-get install nginx.

  3. grep: A command for finding matching text in files or standard input, supporting various regular expressions and options. Example: example.txtFind hellolines in the file that contain the string: grep "hello" example.txt.

  4. ps: The command used to display the system process, supports various options and formats. For example: Display all process information of the current user: ps -u $USER -o pid,cmd,%cpu,%mem.

  5. top: A command used to monitor system processes and resource usage in real time, and supports interactive operations and multiple options. For example: real-time monitoring of system processes and resource usage: top.

  6. df: The command used to display the disk space usage of the file system, supports various options and formats. For example: display disk space usage: df -h.

  7. du: A command used to display the disk space usage of files or directories, supporting various options and formats. For example: Display the disk space usage of all files and subdirectories under the current directory: du -h.

  8. ls: The command used to display the list of files and directories in the current directory, supports multiple options and formats. For example: display a list of all files and directories under the current directory: ls -al.

  9. cd: The command used to switch the current working directory. For example: switch to /home/userdirectory: cd /home/user.

  10. mkdir: The command used to create a new directory, supports various options. new_dirFor example: Create a new directory called: under the current directory mkdir new_dir.

  11. rm: A command to delete a file or directory, supporting various options and formats. For example: delete file.txtthe file named in the current directory: rm file.txt.

  12. mv: Commands for moving or renaming files or directories, supporting various options and formats. For example: move the file file.txtto /home/userthe directory and rename it to new_file.txt: mv file.txt /home/user/new_file.txt.

  13. cp: Command for copying files or directories, supports various options and formats. Example: file.txtcopy the file to/home/user

  14. chown: Used to change the owner of a file or directory. A user with superuser privileges can change the owner and group of any file or directory.
  15. Example: sudo chown user1:group1 file.txt, to file.txtchange the owner of the file to user1and the group to group1.
    parameter:
    • -R: Recursively change the owner of a folder and its contents.
    • --from=currentOwner:currentGroup: Only change the owner and group of files or directories whose current owner and group match the specified values.
    • --preserve-root: Avoid chownrecursive change operations on the root directory by the command.
  16. chmod: Used to change the permissions of a file or directory. Permissions can be represented by numbers or symbols.
    Example: chmod 755 file.txt, file.txtgive the owner of the file read, write, and execute permissions (7), and the group and other users respectively give read and execute permissions (5).
    parameter:
    • -R: Recursively change the permissions of a folder and its contents.
    • u/g/o/a: Indicates user (owner), group, other users, and all users, respectively.
    • +/-=: +Indicates to add permissions, -to delete permissions, =to set specified permissions.
    • r/w/x: Indicates read, write, and execute permissions.
  17. find: Used to search for files or directories under the specified directory.
    Example: find /home -name "*.txt", /homefind all .txtfiles with the extension in the directory.
    parameter:
    • -name pattern: Search for files or directories by name pattern.
    • -type type: Search for files or directories by type, such as ffor files or ddirectories.
    • -mtime n: Search for files or directories by modification time, such as -mtime -1to search for files modified within the last day.
    • -size n: Search for files or directories by size, for example, -size +10Mmeans to search for files whose size is greater than 10MB.
  18. grep: Used to search for the specified text pattern in the file.
    Example: grep "error" log.txt, log.txtfinds lines containing the text "error" in the file.
    parameter:
    • -i: Search regardless of case.
    • -n: Displays the line number of the matching line.
    • -v: Inverts the match, showing the unmatched lines.
    • -E: Enable extended regular expressions, eg grep -E "pattern".
  19. sed: Used for string replacement and editing in text streams.
    Example: sed 's/old/new/g' file.txt, replace file.txtall occurrences of in the file with . parameter: oldnew
    • -i: Edit directly in the original file.
    • -e: multiple edit commands
  20. curl: Used to transfer data on the command line. Example: curl -o example.html https://www.example.com, which means to download https://www.example.comthe content of the website and save it as example.htmla file.

  21. tar: Used to pack and compress files or directories in Linux. Example: tar -cvzf archive.tar.gz /path/to/directory, means to /path/to/directorypackage the files in the directory into archive.tar.gza compressed file.

  22. grep: Used to search for a specified string or pattern in a text file. Example: grep 'example' file.txt, which means file.txtto search for lines containing the string in the file example.

  23. sed: Used to edit and convert text. Example: sed 's/old/new/g' file.txt, means to replace file.txtall oldstrings in the file with new.

  24. awk: Used to process text files and generate reports. Example: awk '{print $1}' file.txt, means to file.txtprint the first word of each line in the file.

  25. ps: Used to view the status of the current process. Example: ps aux, means to display the detailed information of all processes in the current system.

  26. top: Used to dynamically display the activity of the current process in the system. Example: top -u username, which means to display usernamethe process with the user name .

  27. netstat: Used to display network connection and statistics. Example: netstat -an, which means to display the status of all network connections.

  28. traceroute: Used to trace the path a packet takes from a computer to a destination address. Example: traceroute www.example.com, which means to track www.example.comthe routing path accessed by .

  29. iptables: Used to configure network firewall rules for Linux. Example: iptables -A INPUT -p tcp --dport 80 -j ACCEPT, to allow TCP connections through port 80.

  30. ssh: Used to remotely log into another computer and execute commands. Example: ssh [email protected], which means connecting to 192.168.0.100the computer with IP address and userauthenticating with username .

  31. scp: Used to copy files between a local computer and a remote computer. Example: scp file.txt [email protected]:/path/to/destination, means to copy the local file.txtfile to /path/to/destinationthe directory of the remote computer.

  32. rsync: Used to synchronize files and directories between local and remote computers. Example: rsync -avz /path/to/source [email protected]:/path/to/destination, means to synchronize the local /path/to/sourcedirectory to the remote computer's /path/to/destinationdirectory.

  33. find: Used to find files and directories. Example: find /path/to/search -name "filename", means /path/to/searchto search for a file named under the directory filename.

  34. locate: Used to quickly find files and directories. Example: locate filename, which means to find files containing in the file name filename.

  35. htop: Used to dynamically display the activity of the current process in the system. Similar to topthe command, but provides more interactive features and information. Example: htop, which starts htopthe program.

  36. ifconfig: Used to configure and display the status of network interfaces. Example: ifconfig eth0, which means to display eth0the status of the network interface named .

  37. route: Used to view and configure the network routing table. Example: route -n, means to display the routing table in the current system.

  38. ping: Used to test the connectivity of the network connection. Example: ping www.example.com, which means to test www.example.comthe network connection to .

  39. chmod: Used to modify the access permissions of a file or directory. Example: chmod 755 file.txt, which means file.txtset the permission of the file to rwxr-xr-x.

  40. gzip: Used to compress files. Example: gzip file.txt, which means to file.txtcompress the file into file.txt.gza file.

  41. gunzip: Used to decompress files. Example: gunzip file.txt.gz, means to file.txt.gzdecompress the file into file.txta file.

  42. zip: Used to pack and compress files and directories. Example: zip archive.zip /path/to/directory, means to /path/to/directorypackage and compress the directory into archive.zipa file.

  43. unzip: Used to decompress files. Example: unzip archive.zip, means archive.zipextract the file to the current directory.

  44. curl: Used to send HTTP requests on the command line. Example: curl http://www.example.com, means to www.example.comsend an HTTP GET request to and display the response content.

  45. wget: Used to download files from a web server. Example: wget http://www.example.com/file.txt, which means to download http://www.example.com/file.txtthe file.

  46. history: Used to display the history of previously executed commands. Example: history, means to display all the commands executed before.

  47. grep: Used to search for the specified text pattern in the file. Example: grep "pattern" file.txt, which means to search for lines of text file.txtcontaining in the file .pattern

  48. chown: Used to modify the owner and group of a file or directory. Example: chown user:group file.txt, means to file.txtset the owner of the file to userand the group to which it belongs group.

  49. tar: Used to pack and compress files and directories. Example: tar -czvf archive.tar.gz /path/to/directory, means to /path/to/directorypackage and compress the directory into archive.tar.gza file.

  50. crontab: Used to set up scheduled tasks. Example: crontab -e, means to edit the scheduled task of the current user.

Guess you like

Origin blog.csdn.net/polsnet/article/details/130263159