A complete collection of commonly used Linux commands and explanations (1)

Table of contents

1. System information

2. Shut down, restart and log out 

3. Files and Directories

3.1 Navigation commands

3.2 View commands

3.3 Create and delete commands

3.4 Copy and link commands

3.5 Other commands

4. File search

5. Mount the file system

6. Disk space

7. Users and groups

Summarize



Preface

Linux is a free and open source operating system that is based on Unix systems and is widely used around the world. The core of the Linux operating system was developed by Linus Torvalds in 1991 and is participated and maintained by developers around the world.

This article introduces some common Linux commands, including system information, shutdown, restart and logout, files and directories, file search, mounting file system, disk space, users and groups. Please see the text for common Linux commands and explanations.


Using Linux commands may require some learning and adaptation, but once you master them, they will bring many conveniences and advantages. Whether for personal use or in areas such as server management, Linux commands are very useful and powerful tools. The following are some common Linux commands and explanations:

1. System information

  • arch: Displays the machine’s processor architecture (Method 1)
  • uname -m: Displays the machine's processor architecture (Method 2)
  • uname -r: displays the kernel version in use
  • dmidecode -q: Display hardware system components (SMBIOS/DMI)
  • hdparm -i /dev/hda: List the architectural characteristics of a disk
  • hdparm -tT /dev/sda: performs a test read operation on the disk
  • cat /proc/cpuinfo: Display CPU information
  • cat /proc/interrupts: display interrupts
  • cat /proc/meminfo: Verify memory usage
  • cat /proc/swaps: shows which swaps are used
  • cat /proc/version: displays the kernel version
  • cat /proc/net/dev: Display network adapter and statistics
  • cat /proc/mounts: displays mounted file systems
  • lspci -tv: List PCI devices
  • lsusb -tv: Display USB devices
  • date: display system date
  • cal 2007: Display the calendar for 2007
  • date 041217002007.00: Set date and time - month, day, hour, minute, year, second.
  • clock -w: Save time modifications to BIOS

2. Shut down, restart and log out 

  • shutdown -h now: Shut down the system immediately (Method 1)
  • init 0: Shut down the system (Method 2)
  • telinit 0: Shut down the system (Method 3)
  • shutdown -h hours:minutes &: Shut down the system at scheduled time
  • shutdown -c: Cancel system shutdown at scheduled time
  • shutdown -r now: Restart the system immediately (Method 1)
  • reboot: Restart the system (Method 2)
  • logout: log out the current user



3. Files and Directories

3.1 Navigation commands

  • cd /home: Enter the '/home' directory
  • cd ...: Return to the previous directory
  • cd …/…: Return to the directory two levels above
  • cd: Enter your personal home directory
  • cd ~user1: Enter your personal home directory
  • cd -: Return to the last directory you were in
  • pwd: displays the current working path

3.2 View commands

  • ls: View files in a directory
  • ls -F: View files in a directory and mark file types
  • ls -l: Display detailed information about files and directories
  • ls -a: Display all files, including hidden files
  • ls  [0-9] : Displays content containing numbers in file names and directory names
  • tree: Display files and directories in a tree structure (Method 1)
  • lstree: Display files and directories in a tree structure (Method 2)

3.3 Create and delete commands

  • mkdir dir1: Create a directory named 'dir1'
  • mkdir dir1 dir2: Create two directories at the same time
  • mkdir -p /tmp/dir1/dir2: Create a directory tree
  • rm -f file1: delete a file named 'file1'
  • rmdir dir1: Delete a directory named 'dir1'
  • rm -rf dir1: Delete a directory named 'dir1' and its contents
  • rm -rf dir1 dir2: Delete two directories and their contents at the same time
  • mv dir1 new_dir: Rename or move a directory

3.4 Copy and link commands

  • cp file1 file2: copy a file
  • cp dir/* .: Copy all files in a directory to the current working directory
  • cp -a /tmp/dir1 .: Copy a directory to the current working directory
  • cp -a dir1 dir2: copy a directory
  • ln -s file1 lnk1: Create a soft link to a file or directory
  • ln file1 lnk1: Create a physical link to a file or directory

3.5 Other commands

  • touch -t 0712250000 file1: Modify the timestamp of a file or directory (YYMMDDhhmm)
  • file file1: Display the MIME type of the file
  • iconv -l: List known encodings
  • iconv -f fromEncoding -t toEncoding inputFile > outputFile: Convert the input file fromEncoding to toEncoding and output it as an output file
  • find . -maxdepth 1 -name *.jpg -print -exec convert “{}” -resize 80x60 “thumbs/{}” ;: Batch resize files in the current directory and send them to the thumbnails directory (requires Imagemagick convert Order)

4. File search

  • find / -name file1: Search for files and directories named 'file1' starting from the root file system
  • find / -user user1: Search files and directories belonging to user 'user1'
  • find /home/user1 -name *.bin: Search for files ending with '.bin' in the directory '/home/user1'
  • find /usr/bin -type f -atime +100: Search for executable files that have not been used in the past 100 days
  • find /usr/bin -type f -mtime -10: Search for files created or modified in the past 10 days
  • find / -name *.rpm -exec chmod 755 '{}' ;: Search for files ending with '.rpm' and set their permissions
  • find / -xdev -name *.rpm: Search for files ending with '.rpm', but ignore removable devices such as optical drives and flash drives
  • locate *.ps: Find files ending with '.ps' (you need to execute the 'updatedb' command before running)
  • whereis halt: displays the location of binary files, source code or man documents
  • which halt: displays the full path of the binary or executable file

5. Mount the file system

  • mount /dev/hda2 /mnt/hda2: Mount the partition named hda2 to the /mnt/hda2 directory (make sure the directory already exists)
  • umount /dev/hda2: Unmount the partition named hda2 (first exit from the mount point /mnt/hda2)
  • fuser -km /mnt/hda2: Force uninstall when the device is busy
  • umount -n /mnt/hda2: Performs an unmount operation without writing the /etc/mtab file. It is very useful for read-only file systems or when the disk is full.
  • mount /dev/fd0 /mnt/floppy: mount floppy disk
  • mount /dev/cdrom /mnt/cdrom: Mount CD-ROM or DVD-ROM
  • mount /dev/hdc /mnt/cdrecorder: mount CD-RW or DVD-ROM
  • mount /dev/hdb /mnt/cdrecorder: mount CD-RW or DVD-ROM
  • mount -o loop file.iso /mnt/cdrom: Mount file or ISO image file
  • mount -t vfat /dev/hda5 /mnt/hda5: Mount Windows FAT32 file system
  • mount /dev/sda1 /mnt/usbdisk: Mount a USB flash drive or flash device
  • mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share: Mount Windows network share

6. Disk space

  • df -h: Displays the list of mounted partitions and their disk space usage
  • ls -lSr | more: Sort files and directories by size
  • du -sh dir1: Estimate the disk space used by directory 'dir1'
  • du -sk * | sort -rn: Display the size of files and directories in order by capacity
  • rpm -q -a --qf '%10{SIZE}t%{NAME}\n' | sort -k1,1n: Display the space used by installed rpm packages in order based on size (applicable to Fedora, Red Hat and other systems)
  • dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n: Display the space used by installed deb packages based on size (applicable to Ubuntu, Debian and other systems)

7. Users and groups

  • groupadd group_name: Create a new user group
  • groupdel group_name: Delete a user group
  • groupmod -n new_group_name old_group_name: Rename a user group
  • useradd -c “Name Surname” -g admin -d /home/user1 -s /bin/bash user1: Create a user group belonging to the “admin”, the home directory is /home/user1, and use /bin/bash as the default shell user
  • useradd user1: Create a new user
  • userdel -r user1: Delete a user (use the -r parameter to also delete the user's home directory)
  • usermod -c “User FTP” -g system -d /ftp/user1 -s /bin/nologin user1: Modify the user’s attributes, including the user’s comments, user groups, home directory, and default shell
  • passwd: Modify the current user’s password
  • passwd user1: Modify the password of user user1 (only the root user can execute)
  • chage -E 2005-12-31 user1: Set the password expiration date of user user1
  • pwck: Check and fix the /etc/passwd file for format and syntax errors, and check for existing users
  • grpck: Check and fix format and syntax errors in the /etc/group file, and check for existing user groups
  • newgrp group_name: Log in to a new group to change the default group for newly created files.


Summarize

Linux commands are important tools for managing and operating Linux systems. They can perform various tasks, including file operations, system management, network configuration, etc. By learning and using Linux commands, users can better understand and master the working principles of the operating system, thereby improving their skills and problem-solving abilities. Being familiar with and mastering common Linux commands is very beneficial for any user using Linux systems.

Follow, like, collect, I hope friends can connect three times with one click!

Guess you like

Origin blog.csdn.net/m0_71369515/article/details/132713220
Recommended