** The most complete Linux command summary **Copy the code

Basic commands:

  1. Uname -m Displays the processor architecture of the machine
  2. Uname -r Displays the kernel version in use
  3. Dmidecode -q Displays hardware system components
  4. (SMBIOS/DMI) hdparm -i /dev/hda Lists the architecture features of a disk
  5. Hdparm -tt /dev/sda Performs a test read of the operating system information on disk
  6. Arch shows the processor architecture of the machine
  7. Uname -m Displays the processor architecture of the machine
  8. Uname -r Displays the kernel version in use
  9. Dmidecode -Q Display hardware system components – (SMBIOS/DMI)
  10. Hdparm -i /dev/hda lists the architectural features of a disk
  11. Hdparm -tt /dev/sda Performs a test read operation on disk
  12. Cat /proc/cpuinfo Displays CPU info information
  13. Cat /proc/interrupts Displays an interrupt
  14. Cat /proc/meminfo Verifies memory usage
  15. Cat /proc/swaps shows which swaps are used
  16. Cat /proc/version Displays the kernel version
  17. Cat /proc/net/dev Displays network adapter statistics
  18. Cat /proc/mounts Displays a loaded file system
  19. Lspci-tv lists PCI devices
  20. Lsusb-tv Displays USB devices
  21. Date Displays the system date
  22. CAL 2007 Displays the calendar for 2007
  23. Date 041217002007.00 Set the date and time – month/day/hour/year. seconds
  24. Clock -w Saves the time change to the BIOS

Shutdown (shutdown, reboot, and logout of the system)

  1. Shutdown -h now Shutdown system (1)
  2. Init 0 Shut down the system (2)
  3. Telinit 0 Shutdown system (3)
  4. Shutdown -h hours:minutes & shutdown the system at the scheduled time
  5. Shutdown -c Cancels shutting down the system at the scheduled time
  6. Shutdown -r now Restart (1)
  7. Reboot to restart (2)
  8. Logout logout

Files and Directories

  1. CD /home Go to ‘/ home’ directory
  2. cd .. Returns the upper directory
  3. cd .. /.. Returns the previous two levels of directories
  4. CD goes to the personal home directory
  5. CD ~user1 Go to the personal home directory
  6. CD – Returns the last directory
  7. PWD Displays the working path
  8. Ls Displays files in a directory
  9. Ls -f Displays files in the directory
  10. Ls -l Displays detailed information about files and directories
  11. Ls -a Displays hidden files
  12. ls [0-9]Displays file names and directory names that contain numbers
  13. Tree Displays the tree structure of files and directories starting from the root directory (1)
  14. Lstree displays the tree structure of files and directories starting from the root directory (2)
  15. Create a directory called ‘dir1’
  16. Mkdir dir1 dir2 Create two directories simultaneously
  17. Mkdir -p/TMP /dir1/dir2 Creates a directory tree
  18. Rm -f file1 delete a file called ‘file1’
  19. Rmdir dir1 Delete a directory called ‘dir1’
  20. Rm -rf dir1 Deletes a directory named ‘dir1’ and its contents at the same time
  21. Rm -rf dir1 dir2 Delete both directories and their contents
  22. Mv dir1 new_dir Renames or moves a directory
  23. Cp file1 file2 Copies a file
  24. Cp dir/*. Copy all files in a directory to the current working directory
  25. Cp -a/TMP/dir1. copy a directory to the current working directory
  26. Cp -a dir1 dir2 Copies a directory
  27. Ln -s file1 lnk1 Creates a soft link to a file or directory
  28. Ln file1 lnk1 Creates a physical link to a file or directory
  29. Touch -t 0712250000 file1 Changes the timestamp of a file or directory – (YYMMDDhhmm)
  30. file file1 outputs the mime type of the file as text
  31. Iconv-l lists the known encodings
  32. iconv -f fromEncoding -t toEncoding inputFile > outputFile creates a new from the given input file by assuming it is encoded in fromEncoding and converting it to toEncoding.
  33. find . -maxdepth 1 -name *.jpg -print -exec convert “{}” -resize 80×60 “thumbs/{}” ; batch resize files in the current directory and send them to a thumbnails directory (requires convert from Imagemagick)

File search

  1. Find / -name file1 Searches for files and directories in the root file system starting with ‘/’
  2. Find / -user user1 Searches for files and directories belonging to user ‘user1’
  3. Find /home/user1-name *. Bin Searches for files ending in’.bin’ in the directory ‘/home/user1’
  4. Find /usr/bin-type f-atime +100 Searches for execution files that have not been used in the past 100 days
  5. Find /usr/bin-type f-mtime-10 Searches for files that have been created or modified within 10 days
  6. find / -name *.rpm -exec chmod 755 ‘{}’ ; Search for files ending in ‘.rpm’ and define their permissions
  7. Find / -xdev-name *. RPM Searches for files ending in ‘. RPM ‘, ignoring removable devices such as CD-ROM drives and FLASH drives
  8. Locate *.ps Finds a file ending in ‘. Ps’ – run ‘updatedb’ first
  9. Whereis Halt displays the location of a binary, source, or MAN
  10. Which HALT displays the full path to a binary or executable file

Mount a file system

  1. Mount /dev/hda2 / MNT /hda2 to mount a disk named hda2 – make sure the directory ‘/ MNT /hda2’ already exists
  2. Umount /dev/hda2 Unmount a disk named hda2 from the mount point ‘/ MNT /hda2’
  3. Fuser-km/MNT /hda2 Forcibly uninstalls the device when it is busy
  4. Umount -n/MNT /hda2 Run the unmount operation without writing to the /etc/mtab file – useful when the file is read-only or when the disk is full
  5. Mount /dev/fd0/mnt /floppy Mounts a floppy disk
  6. Mount /dev/cdrom/MNT /cdrom To mount a Cdrom or dvdrom
  7. Mount /dev/hdc/MNT/cdRecorder to mount a CDRW or DVdrom
  8. Mount /dev/hdb/mnt/cdRecorder to mount a CDRW or dvdrom
  9. Mount -o loop file.iso/MNT /cdrom To mount a file or iso image file
  10. Mount -t vfat /dev/hda5 / MNT /hda5 Mount a Windows FAT32 file system
  11. Mount /dev/sda1 / MNT /usbdisk To mount a USB flash drive or flash storage device
  12. Mount -t SMBFS -o username=user,password=pass //WinClient/share/MNT /share Mount a Windows network share

Disk space

  1. Df -h Displays the list of mounted partitions
  2. Ls – lSr | more arranged in size files and directories
  3. Du -sh dir1 Estimated disk space used by directory ‘dir1’
  4. Du – sk * | sort – rn) based on size, in turn, according to the size of the files and directories
  5. RPM – q – a – qf ’10 {NAME} {SIZE} t % % n’ | sort – k1, 1 n based on the SIZE of the display has been installed in turn the space used by RPM package (fedora, redhat class system)
  6. DPKG — query – W f = ‘Installed – Size; 10t{Installed-Size; 10} tInstalled – Size; 10 t {Package} n ‘| sort – k1, 1 n based on the size of the display installed deb Package used by space (ubuntu, debian system)

Users and Groups

  1. Groupadd group_name Creates a user group
  2. Groupdel group_name Deletes a user group
  3. Groupmod -n new_group_name old_group_name Renames a user group
  4. Useradd -c “Name Surname “-g admin -d /home/user1 -s /bin/bash user1 Creates a user belonging to user group admin
  5. Useradd user1 creates a new user
  6. Userdel -r user1 Deletes a user (‘-r’ excludes the home directory)
  7. Usermod -c “User FTP” -g system -d/FTP /user1 -s /bin/nologin user1 Modifies User attributes
  8. Passwd Changes the password
  9. Passwd user1 Changes the password of a user (root only).
  10. Chage -E 2005-12-31 user1 Sets the validity period of the user password
  11. PWCK checks ‘/etc/passwd’ for file format and syntax corrections as well as existing users
  12. GRPCK checks ‘/etc/passwd’ for file format and syntax corrections as well as existing groups
  13. Newgrp group_name logs in to a new group to change the default group for newly created files

File permission – Use “+” to set the permission and “-” to cancel it

  1. Ls -lh Displays permissions
  2. The ls/TMP | pr – T5 – W $COLUMNS will be divided into 5 bar terminal display
  3. Chmod ugo+ RWX directory1 Sets owner (u), group (g), and other (O) permissions for the directory to read (r), write (w), and execute (x)
  4. Chmod go-rwx directory1 Deletes the read/write permissions of the group (g) and others (O) on the directory
  5. Chown user1 file1 changes the owner attribute of a file
  6. Chown -r user1 directory1 Changes the owner properties of a directory and the properties of all files in the directory
  7. CHGRP group1 file1 Specifies the group that changes the file
  8. Chown user1:group1 file1 Changes the owner and group properties of a file
  9. Find / -perm -u+s lists all files in a system that use SUID control
  10. Chmod u+s /bin/file1 Sets the SUID bit of a binary file – the user running the file is given the same permissions as the owner
  11. Chmod u-s /bin/file1 Disables the SUID bit of a binary file
  12. Chmod g+s /home/public Sets the SGID bit of a directory – similar to SUID, except for directories
  13. Chmod g-s /home/public Disables the SGID bit of a directory
  14. Chmod o+t /home/public Sets the STIKY bits of a file – only allows legal owners to delete files
  15. Chmod o-t /home/public Disables the STIKY bit of a directory
  16. Chmod +x file path Adds execution permissions for the owner, group, and other users
  17. The chmod -x file path allows the owner, owning group, and other users to delete files
  18. Chmod u+x file path adds execution permissions for the owner
  19. Chmod g+x File path Adds execution permission to the owning group
  20. Chmod o+x File path Add execution permission for other users
  21. Chmod ug+x file path Add execution permission for the owner and owning group
  22. Chmod =wx File path Add write and execute permissions for the owner, owning group, and other users, and cancel read permissions
  23. Chmod ug=wx File path Add write and execute permissions for the owner and owning group and cancel read permissions

Special properties of the file – Use “+” to set permissions and “-” to cancel

  1. Chattr +a file1 Files can be read or written in appending mode only
  2. Chattr +c file1 allows this file to be automatically compressed/uncompressed by the kernel
  3. Chattr +d file1 This file is ignored by the dump program during file system backup
  4. Chattr + I file1 is set to an immutable file that cannot be deleted, modified, renamed, or linked
  5. Chattr +s file1 allows a file to be safely deleted
  6. Chattr +S file1 Causes the system to write the changes to disk as soon as the application writes to the file
  7. Chattr +u file1 If a file is deleted, the system will allow you to restore the deleted file at a later time
  8. Lsattr displays special attributes

Package and compress files

  1. Bunzip2 file1.bz2 unzip a file called ‘file1.bz2’
  2. Bzip2 file1 compresses a file called ‘file1’
  3. Gunzip file1.gz Unzip a file called ‘file1.gz’
  4. Gzip file1 compresses a file called ‘file1’
  5. Gzip-9 File1 Maximum compression
  6. Rar a file1.rar test_file creates a package called ‘file1.rar’
  7. Rar a file1. Rar file1 file2 dir1 Compresses ‘file1’, ‘file2’ and directory ‘dir1’ simultaneously.
  8. Rar x file1.rar Decompresses the RAR package
  9. Unrar x file1.rar Decompresses the RAR package
  10. Tar -cvf archive.tar file1 Creates an uncompressed tarball
  11. Tar -cvf archive.tar file1 file2 dir1 Creates an archive file containing ‘file1’, ‘file2’ and ‘dir1’
  12. Tar -tf archive.tar displays the contents of a package
  13. Tar -xvf archive.tar Releases a package
  14. Tar -xvf archive.tar -c/TMP Release the compressed package to the/TMP directory
  15. Tar -cvfj archive.tar.bz2 dir1 Creates a compressed package in bzip2 format
  16. Tar -xvfj archive.tar.bz2 Decompress a bzip2 package
  17. Tar -cvfz archive.tar.gz dir1 Create a compressed package in gzip format
  18. Tar -xvfz archive.tar.gz Decompress a gzip package
  19. Zip file1. Zip file1 Creates a zip package
  20. Zip -r file1.zip file1 file2 dir1 Compresses several files and directories into a zip package
  21. Unzip file1.zip Decompresses a zip package

RPM package – (Fedora, Redhat, and similar systems)

  1. RPM -ivh package. RPM Installs an RPM package
  2. RPM -ivh –nodeeps package. RPM Installs an RPM package and ignores dependency warnings
  3. RPM -u package. RPM Updates an RPM package without changing its configuration file
  4. RPM -f package. RPM Updates an RPM package that has been installed
  5. RPM -e package_name. RPM Deletes an RPM package
  6. RPM -qa Displays all installed RPM packages in the system
  7. RPM – qa | grep HTTPD shows all name contains “HTTPD” RPM package
  8. RPM -qi package_name Gets special information about an installed package
  9. RPM -qg “System Environment/Daemons” displays the RPM package of a component
  10. RPM -ql package_name Displays a list of files provided by an installed RPM package
  11. RPM -QC package_name Displays a list of configuration files provided by an installed RPM package
  12. RPM -q package_name –whatrequires displays a list of dependencies that exist with an RPM package
  13. RPM -q package_name –whatprovides Displays the volume of an RPM package
  14. RPM -q package_name –scripts displays the script L executed during installation/deletion
  15. RPM -q package_name –changelog Displays the change history of an RPM package
  16. The RPM – qf/etc/HTTPD/conf/HTTPD. Conf the confirmation to the documents provided by which RPM package
  17. RPM -qp package. RPM -l displays a list of files provided by an RPM package that has not yet been installed
  18. RPM –import /media/cdrom/RPM -gpg-key Import the public KEY digital certificate
  19. RPM –checksig package. RPM Verifies the integrity of an RPM package
  20. RPM -qa gpg-pubkey Check the integrity of all installed RPM packages
  21. RPM -v package_name Check the file size, license, type, owner, group, MD5 check, and last modification time
  22. RPM -va Check all installed RPM packages in the system – Use them with caution
  23. RPM -vp package. RPM Check that an RPM package is not installed
  24. rpm2cpio package.rpm | cpio –extract –make-directories binRun the executable from an RPM package
  25. rpm -ivh /usr/src/redhat/RPMS/arch/package. RPM Installs a built package from an RPM source
  26. Rpmbuild –rebuild package_name.src. RPM Builds an RPM package from an RPM source

YUM Package Upgrader – (Fedora, RedHat and similar systems)

  1. Yum install package_name Download and install an RPM package
  2. Yum localInstall package_name. RPM will install an RPM package and use your own repository to resolve all dependencies for you
  3. Yum update package_name. RPM Updates all installed RPM packages in the system
  4. Yum update package_name Updates an RPM package
  5. Yum remove package_name Deletes an RPM package
  6. Yum List lists all packages installed on the current system
  7. Yum Search package_name Searches for packages in the RPM repository
  8. Yum Clean Packages delete the downloaded packages from the RPM cache
  9. Yum Clean headers deletes all header files
  10. Yum Clean All deletes all cached packages and headers

DEB packages (Debian, Ubuntu, and similar systems)

  1. DPKG -i package.deb Installs/updates a deb package
  2. DPKG -r package_name Deletes a DEB package from the system
  3. DKG -l displays all deb packages installed in the system
  4. DPKG -l | grep HTTPD shows all name contains “HTTPD” deb package
  5. DKG -s package_name Gets information about a particular package that has been installed on the system
  6. DPKG -l package_name displays a list of files provided by a DEB package that has been installed on your system
  7. DPKG –contents package.deb displays a list of files provided by a package that has not yet been installed
  8. DPKG -s /bin/ping confirms which deb package is providing the file given

APT software tools (Debian, Ubuntu and similar systems)

  1. Apt-get install package_name Install/update a deb package
  2. Apt-cdrom install package_name Install/update a deb package from the cd-rom
  3. Apt-get Update Updates software packages in the list
  4. Apt-get upgrade Upgrades all installed software
  5. Apt-get remove package_name Deletes a deb package from the system
  6. Apt-get check Verifies that the software repository is correct
  7. Apt-get clean Cleans the cache from downloaded packages
  8. Apt-cache search searched-package returns the name of the package containing the searched string

Viewing file Contents

  1. Cat file1 Forwards the file from the first byte
  2. Tac file1 looks at the contents of a file in reverse, starting with the last line
  3. More file1 Displays the contents of a long file
  4. Less file1 is similar to the ‘more’ command, but it allows the same reverse operation in the file as the forward operation
  5. Head-2 file1 Displays the first two lines of a file
  6. Tail-2 file1 Displays the last two lines of a file
  7. Tail -f /var/log/messages View the contents added to a file in real time

Text processing

  1. cat file1 file2 … | command <> file1_in.txt_or_file1_out.txt general syntax for text manipulation using PIPE, STDIN and STDOUT
  2. cat file1 | command( sed, grep, awk, grep, etc…) > result.txt merges the detailed text of a file and writes the introduction to a new file
  3. cat file1 | command( sed, grep, awk, grep, etc…) >> result.txt merges the detailed text of a file and writes the introduction to an existing file
  4. Grep Aug /var/log/messages Find the keyword “Aug” in the file ‘/var/log/messages’
  5. Grep ^Aug /var/log/messages Look for words starting with “Aug” in the file ‘/var/log/messages’
  6. Grep [0-9] /var/log/messages Select all lines containing numbers in the ‘/var/log/messages’ file
  7. Grep Aug -r /var/log/* Search for the string “Aug” in the directory ‘/var/log’ and subsequent directories
  8. Sed ‘s/stringa1/stringa2/g’ example. TXT replace “string1” in example. TXT with “string2”
  9. Sed ‘/^$/d’ example.txt deletes all blank lines from example.txt
  10. sed ‘/ *#/d; /^$/d’ example.txt Removes all comments and blank lines from example.txt
  11. Echo ‘esempio’ | tr / : the lower: ‘ ‘[: upper:]’ merger and content of cells
  12. Sed -e ‘1d’ result. TXT excludes the first line from the file example. TXT
  13. Sed -n ‘/stringa1/p’ looks at lines containing only the word “string1”
  14. Sed -e ‘s/ *$//’ example. TXT deletes the whitespace character at the end of each line
  15. Sed -e ‘s/stringa1//g’ example. TXT deletes only the word “string1” from the file and keeps all the rest
  16. Sed – n ‘1, 5 p; 5q’ example.txt Displays the contents from line 1 to line 5
  17. sed -n ‘5p; 5q’ example.txt Look at line 5
  18. Sed -e ‘s/00*/0/g’ example.txt replaces multiple zeros with a single zero
  19. Cat -n file1 indicates the number of lines in a file
  20. The cat example. TXT | awk ‘NR % 2 = = 1’ delete example. All even lines of the TXT file
  21. Echo a b c | awk ‘} {print $1 to check the line of the first column
  22. Echo a b c | awk ‘,1,1,3} {print 1 ‘to view a line of the first and the third column
  23. Paste File1 file2 Combines the contents of two files or columns
  24. Paste -d ‘+’ file1 file2 Combines the contents of two files or columns with “+” between them
  25. Sort file1 file2 Sorts the contents of two files
  26. Sort file1 file2 | uniq took out two file and set the line only keep a (repeat)
  27. Sort file1 file2 | uniq -u delete intersection, leaving the other line
  28. Sort file1 file2 | uniq – d out the intersection of two files (leaving only exists in two files in the file at the same time)
  29. Comm-1 file1 file2 Compares the contents of two files and deletes only the contents contained in ‘file1’
  30. Comm-2 file1 file2 Compares the contents of two files and deletes only the contents contained in ‘file2’
  31. Comm-3 file1 file2 Compares the contents of two files and deletes only the common parts of the two files

Character Settings and file format conversion

  1. TXT Fileunix. TXT converts a text file format from MSDOS to UNIX
  2. Unix2dos fileunix.txt Converts a text file from UNIX to MSDOS
  3. recode .. HTML < page.txt > page.html converts a text file to HTML
  4. Recode – l | more show all allow conversion formats

File System Analysis

  1. Badblocks -v /dev/hda1 Check the bad magnetic blocks on disk Hda1
  2. FSCK /dev/hda1 Fixes/checks the integrity of the Linux file system on the hda1 disk
  3. Ext2 /dev/hda1 Repair/check the integrity of the ext2 file system on the hda1 disk
  4. E2fsck /dev/hda1 Repair/check the integrity of the ext2 file system on disk hda1
  5. E2fsck -j /dev/hda1 Restores/checks the integrity of the ext3 file system on hda1
  6. Ext3 /dev/hda1 Repair/check the integrity of the ext3 file system on the hda1 disk
  7. Fsck. vfat /dev/hda1 Repair/check the integrity of the FAT file system on hda1
  8. Fsck.msdos /dev/hda1 Fixes/checks the integrity of the DOS file system on the hda1 disk
  9. Dosfsck /dev/hda1 Fixes/checks the integrity of the DOS file system on the hda1 disk

Example Initialize a file system

  1. MKFS /dev/hda1 Creates a file system in the hda1 partition
  2. Mke2fs /dev/hda1 Creates a Linux ext2 file system in the hda1 partition
  3. Mke2fs -j /dev/hda1 creates a Linux ext3(journaling) file system in the hda1 partition
  4. MKFS -t vfat 32 -f /dev/hda1 Creates a FAT32 file system
  5. Fdformat -n /dev/fd0 Formats a floppy disk
  6. Mkswap /dev/hda3 Create a swap file system

SWAP file system

  1. Mkswap /dev/hda3 Create a swap file system
  2. Swapon /dev/hda3 Enables a new swap file system
  3. Swapon /dev/hda2 /dev/hdb3 Enable two swap partitions

The backup

  1. Dump-0aj -f/TMP /home0.bak /home Make a full backup of the ‘/home’ directory
  2. Dump-1aj -f/TMP /home0.bak /home Make an interactive backup of the ‘/home’ directory
  3. Restore-if/TMP /home0.bak Restores an interactive backup
  4. Rsync-rogpav –delete /home/tmp To synchronize the directories on both sides
  5. Rsync-rogpav -e SSH –delete /home ip_address:/ TMP Rsync through the SSH channel
  6. Rsync-az -e SSH –delete ip_addr:/home/public /home/local To synchronize a remote directory to the local directory through SSH and compression
  7. Rsync-az -e SSH –delete /home/local ip_addr:/home/public To synchronize the local directory to the remote directory through SSH and compression
  8. Dd bs = 1 m if = / dev/hda | gzip | SSH user @ ip_addr ‘dd of = hda. Gz’ via SSH on a remote host to perform a backup of the local disk operations
  9. Dd if=/dev/sda of=/ TMP /file1 Backs up the disk content to a file
  10. Tar -puf backup.tar /home/user Perform an interactive backup operation on the ‘/home/user’ directory
  11. (CD/TMP/local / && tar c.) | SSH – c user @ ip_addr ‘CD/home/share / && tar x – p’ via SSH to copy a directory content in the remote directory
  12. C/home (tar) | SSH – c user @ ip_addr ‘CD/home/backup – home && tar x – p’ via SSH in the remote directory copy a local directory
  13. tar cf – . | (cd /tmp/backup ; Tar xf -) locally Copy a directory to another location, keeping the original permissions and links
  14. Find/home/user1 -name “*.txt ‘| xargs cp – av — target – directory = / home/backup / — parents from a directory to find and copy all in’. TXT ‘ End the file in another directory
  15. Find/var/log – the name ‘*. The log’ | tar CV – files – from = – | bzip2 > the tar. The.bz2 find all to ‘log’ at the end of the file and make a bzip package
  16. Dd if=/dev/hda of=/dev/fd0 bs=512 count=1 Copy the contents of the MBR (Master Boot Record) to the floppy disk
  17. Dd if=/dev/fd0 of=/dev/hda bs=512 count=1 Restore the MBR content from the backup saved to the floppy disk

CD

  1. Cdrecord -v gracetime=2 dev=/dev/ cdrom-eject blank= fast-force Clears the contents of a reproducible CD
  2. Mkisofs /dev/cdrom > cd.iso Create an ISO image file on the disk
  3. Mkisofs/dev/cdrom | gzip > cd_iso. Gz on disk to create a compressed the cd-rom iso image files
  4. Mkisofs-j-allow-leading-dots -r -v “Label CD” -iso-level 4 -o./cd.iso data_cd Create a directory

Iso image file

  1. CD record -v dev=/dev/cdrom cd.iso Burns an ISO image file
  2. Gzip – dc cd_iso. Gz | cdrecord dev = / dev/cdrom – burn a compressed the ISO image file
  3. Mount -o loop CD. Iso/MNT /iso Mount an ISO image file
  4. Cd-paranoi-b transcribe audio tracks from a CD to a WAV file
  5. Cd-paranoia — “-3” transcribe audio tracks from a CD to a WAV file (parameter -3)
  6. Cdrecord –scanbus scans the bus to identify SCSI channels
  7. Dd if = / dev/HDC | md5sum check md5sum encoding of a device, such as a CD

Networking – (Ethernet and WIFI wireless)

  1. Ifconfig eth0 displays the configuration of an Ethernet card
  2. Ifup eth0 Enables an ‘eth0’ network device
  3. Ifdown eth0 Disables an ‘eth0’ network device
  4. Ifconfig eth0 192.168.1.1 netmask 255.255.255.0 Control IP address
  5. Ifconfig eth0 promisc Set ‘eth0’ to promiscuous mode to sniff packets
  6. Dhclient eth0 enable ‘eth0’ in DHCP mode
  7. route -n show routing table
  8. route add -net 0/0 gw IP_Gateway configura default gateway
  9. Route add-net 192.168.0.0 gw 192.168.1.1 configure static route to reach network ‘192.168.0.0/16’
  10. route del 0/0 gw IP_gateway remove static route
  11. echo “1” > /proc/sys/net/ipv4/ip_forward activate ip routing
  12. hostname show hostname of system
  13. host www.example.com lookup hostname to resolve name to ip address and viceversa(1)
  14. nslookup www.example.com lookup hostname to resolve name to ip address and viceversa(2)
  15. ip link show show link status of all interfaces
  16. mii-tool eth0 show link status of ‘eth0’
  17. ethtool eth0 show statistics of network card ‘eth0’
  18. netstat -tup show all active network connections and their PID
  19. netstat -tupl show all network services listening on the system and their PID
  20. tcpdump tcp port 80 show all HTTP traffic
  21. iwlist scan show wireless networks
  22. iwconfig eth1 show configuration of a wireless network card
  23. hostname show hostname
  24. host www.example.com lookup hostname to resolve name to ip address and viceversa
  25. nslookup www.example.com lookup hostname to resolve name to ip address and viceversa
  26. whois www.example.com lookup on Whois database

Listing the contents of a directory

  1. Ls -a: Displays all files (including hidden files).
  2. Ls -l: Displays detailed information.
  3. Ls-r: displays the subdirectory structure recursively.
  4. Ls-ld: displays directory and link information.
  5. CTRL + R: Command searched in history (enter any character in the command);
  6. In Linux. The leading file is a hidden file;
  7. PWD: Displays the current directory

View the file type

  1. File: View the file type

Copy file directories

1. Cp: copy files and directories cp Source files (folders) Target files (folders) Common parameters are as follows: -r: copy the entire directory tree recursively. -v: displays detailed information. To copy a folder, add a -r parameter to the end of the cp command, for example, cp -r source folder Destination folder

2, touch+ file name: when the file does not exist, create the corresponding file; Changes the creation time of a file when it exists. Function: Generate an empty file or modify the file access/modified time record value. Touch * : change the current file time to the current system time touch -d 20040210 test: change the date of the test file to 20040210 touch ABC: change the current system time if the ABC file exists. If not, an empty file is generated for the current time

3, MV file destination directory: move or rename the file or directory (if the file name is specified, you can rename the file). You can move files and directories to another directory or change the names of files and directories. The format is mv [parameter]< source file or directory > < Destination file or directory > mva.txt.. / : move the a.txt file to the upper directory mv a.txt b.txt: rename a.txt to b.txt mvdir2.. / : Move the dir2 directory up one level

Rm: delete the file. Common parameters are as follows: -i: interactive. -r: recursive deletion includes all contents in a directory

5, mkdir + folder name: create folder;

Rm -r + Folder name: Delete folder (empty folder and non-empty folder can be deleted) rmdir folder name: Delete folder (only empty folder can be deleted)

7, mkdir -p dir1/dir2: create a dir1 directory in the current directory and create a dir2 directory in the dir1 directory.

Rmdir -p dir1/dir2: delete the dir2 directory under dir1. If dir1 is empty, delete it

9. Rm * : Delete all files in the current directory

-f: force to delete files rm -f *. TXT: force to delete all files whose suffix is TXT

11, the -i parameter: when deleting files, ask rm -i * : delete all files in the current directory. The following prompt is displayed: rm:backup:is a directory Y Asks when a file is deleted. You can press Y or N to allow or deny file deletion

-r: delete the test directory. -r: delete the test directory. -r: delete the test directory. Delete all files (including all files in the current directory, all subdirectories, and files in subdirectories) Generally, r and f are used together to delete directories, avoiding trouble rm -rf test: forcibly delete the directory without asking questions

13. Grep: Run the following command to search for matching characters in the file and run the following command: grep[parameter] < string to find > < source file to find string > greplinux test. TXT: Search for Linux in the test. TXT file and run the following command

14. The ln command function creates a link between a file and a directory. Format: ln [parameter] < source file or directory > < Destination file or directory > Link can be soft link or hard link 1. Soft link: ln -s /usr/share/do doc: create a link file doc and point to /usr/share/do 2. Hard links: Ln /usr/share/test hard: creates a hard link to the test file, and the test file is stored in the storage area. + % Y – % m % d; Date -s: sets the current system time hwclock(clock) : displays the hardware clock time (administrator permission is required). CAL [Parameter] Month year CAL: displays the calendar of the current month cal4 2004: displays the calendar of April 2004 cal-Y 2003: displays the calendar of 2003 Uptime: displays the system running time

Echo “liuyazhuang” >> liuyazhuang. TXT cat: displays the content of the file, or merges several files into one file. Format: format: cat [parameter] < filename > cat test. TXT: according to the test. TXT file contents cat test. TXT | more: it says the test page. TXT file contents cat test. TXT > > test1. TXT: Cat test.txt test2.txt >readme.txt: TXT file. Head: displays the first lines of the file (10 lines by default) -n: specifies the number of lines to display format: head -n file name Tail: displays the last lines of the file (10 lines by default) -n: specifies the number of lines to display -f: specifies the number of lines to display. Tail [parameter]< file name > tail-10 /etc/passwd: Tail +10 /etc/passwd: Displays the last 10 lines of the /etc/passwd file. More: Tail +10 /etc/passwd: displays the last 10 lines of the /etc/passwd file. The more command is generally used when the content to be displayed is longer than one screen. In order to avoid flash in the face display, users can use the more command to pause the screen when it is full of a page. At this time, users can press the space bar to continue to display the next screen, or press the Q button to stop the display. Ls – al | more: in the form of officer, display etc directory file list, display a full picture was suspended, can press the blank space key continue to show the next screen, or press Q jump from less: Page to display the contents of a file (with up and down page) Press the up key to page, and press q to exit. The usage of ‘less’ is similar to that of the more command, and it can also be used to browse more than one page of a file. The difference is that in addition to pressing the space bar to scroll down files, the less command can also use the up and down keys to scroll files. To end browsing, simply press the Q key at the less prompt “:”. Ls – al | less, in the form of officer, list all the contents of the/etc directory. Users can browse by pressing up and down or jump away by pressing Q

3. View the hardware information Ispci: view the PCI device -v: view the details Isusb: View the USB device -V: View the details Ismod: View the loaded module (driver)

Time -h to shutdown the computer -r: to restart the computer such as: shutdown -h now 10 minutes later: shutdown -h +10 23:30: Shutdown -h 23:30: shutdown -r now poweroff: shuts down the computer immediately reboot: restarts the computer immediately

Zip liuyazhuang.zip myfile format: “Zip compressed zip file name” unzip: Decompress the zip file unzip liuyazhuang.zip gzip: Zip file name tar: Liuyazhuang archive file tar -cvf out.tar liuyazhuang archive file The tar -cvzf backup.tar.gz /etc/z parameter gzip the archived file to reduce its size. -c: creates a new tar file -v: displays information about the running process. -f: specifies the file name. -z: uses the gzip command to compress the file. Gz * : Package all files as test.tar and run the gzip command to compress tar -tf test.tar. Tar -xvf test.tar Unpack test.tar -zxvf foo.tar.gz Unpack the gzip gunzip command gziptest. TXT: Gizp -l test.txt.gz: displays the compression ratio

This command requires a database to be established in advance. By default, the database is updated once a day. You can run the updatedb command to manually create and update the database. Find Search location Search parameters are as follows: -name liuyazhuang finds the file whose name contains “liuyazhuang” in the current directory. Find / – name. conf Finds the file whose suffix is Find / -type d Find. -name “a”-exec ls -l {}; Find function: Used to find files or directories. Format: find [< path >] [Matching condition] find / -name httpd.conf Searches for the httpd.conf file in the root directory of the system

CTRL + C: Terminates the current command

9. Dmesg Function The dmesg command displays system diagnosis information, operating system version, physical memory size, and other information

10. Df Function The df command is used to view the usage of each partition of a file system

11. Du Function The du command displays the number of disk space used by subdirectories in a directory. Format: du [parameter] < directory name >

12, the free command function: used to check the system memory, virtual memory (swap space) size usage VIM VIM is a powerful command line text editor, in Linux, you can start the VIM editor by using the VIM command. If the target file exists, vim opens the target file. If the target file does not exist, vim creates and opens the file :q: exits the vim editor

VIM Mode The VIM has three modes (1) Command mode (common mode) After the VIM starts, the VIM enters the command mode by default. You can press esc to return to the command mode (multiple times). In the command mode, you can enter different commands to select, copy, paste, and undo. Common commands for naming mode are as follows: I: insert text before the cursor. O: Insert a new line below the current line; Dd: delete the entire line. Yy: Put the contents of the current line into the buffer (copy the current line) N + YY: Put the contents of the N lines into the buffer (copy the n lines) P: Put the text in the buffer behind the cursor (paste) U: undo the previous operation r: replace the current character/find the keyword

(2) Insert mode Press the “I” key in command mode to enter the insert mode. In the insert mode, you can enter the edited text content. Use the ESC key to return to the command mode.

Ex mode: Press the “:” key in command mode to enter ex mode, and the cursor moves to the bottom. Here you can save your changes or exit the vim. ext mode: :w: save your current changes :q: Exit :q! X: save and exit, equivalent to :wq :set number Display line number :! System commands Execute a system command and display the result :sh: Switch to the command line, press CTRL + D to switch back to vim

Software package management commands (RPM) 1. Software package Installation The RPM command is used to install all components in the software package to the correct path in the system. The command for installing the software package is RPM -ivh wu-ftpd-2.6.2-8.i386. RPM I: RPM installation mode v: Check file information h: The installation progress is displayed as #

2. Software Package Deletion In this mode, all contents of the specified software package are deleted except the modified configuration file. Run the following command to delete the RPM software package: RPM -e wu-ftpd note The software name “wu-ftpd” or “wu-ftpd-2.6.2-8” must be used instead of the original installation package name: wu-ftpd-2.6.2-8.i386.rpm

3. Upgrade software Packages In upgrade mode, the system installs the latest version specified by the user and deletes the same software packages that have been installed in the system. Run the following command to upgrade the software package: RPM -uvh wu-ftpd-2.6.2-8.i386. RPM -uvh: upgrade parameters

4. Software package Update In the update mode, the RPM command checks whether the specified software package is newer than the existing software package. If this is the case, the RPM command automatically updates the specified package; Conversely, if an earlier version of a software package is not specified, the RPM command does not install the package. In upgrade mode, the RPM command installs the specified software package regardless of whether an older version is available on the system. RPM -fvhwu-ftpd-2.6.2-8.i386. RPM -fvh: updates parameters

5. Software Package Query To obtain information about RPM software packages, use the query mode. You can use the -q parameter to query the contents of an installed software package RPM -q wu-ftpd To query the installation location of the software package: RPM -ql package-name RPM -ql xv