directory

Introduction to Linux

Summary of Common Linux commands

Commands related to system operations

1. System information processing

2. The system restarts and shuts down

Two, file operation related commands

1. File and directory operations

2. File search operation

3. File mounting system

4. File permission operation

5. Special properties of files

Package and compress files

7. View the file contents

8. Text processing

9. Character setting and file format conversion

10. File system analysis

11. Initialize a file system

12. SWAP file system

Commands related to disk space

4. Commands related to users and groups

Fedora, Redhat, and similar commands

1. RPM package command

2. YUM software package upgrader

Debian, Ubuntu and similar system related commands

1, DEB package

2. APT software tools

Seven, backup and CD related commands

1. Backup operations

2. Disc operation

Ethernet and WIFI wireless related commands


Hello, I’m Little Grey Ape.

Recently, when I was learning about Linux system, I found that there are many common commands in Linux system, so I found many summaries of big guys on the Internet, and then simply collected them. Have inadequacy and complementary place still hope each big man points out.

 

Introduction to Linux

Linux, full name GNU/Linux, is a unix-like operating system that is free to use and freely distributed. It is also a multi-user, multi-task, multi-threading and multi-CPU operating system based on POSIX and Unix. As the Internet grew, Linux gained support from software enthusiasts, organizations, and companies around the world. In addition to maintaining a strong momentum of development in servers, it has made great progress in personal computers and embedded systems. Users can not only intuitively obtain the implementation mechanism of the operating system, but also modify and improve Linux according to their own needs, so that it can maximize the needs of users.

Linux is not only stable, but also open source software. Its core firewall component has high performance and simple configuration, which ensures the security of the system. In many enterprise networks, Linux is used not only as a server but also as a firewall for the sake of speed and security.

Linux has open source, no copyright, technical community of users and other characteristics, open source users can be freely tailored, high flexibility, powerful, low cost. Especially the network protocol stack embedded in the system can realize the function of router after proper configuration. These characteristics make Linux an ideal development platform for routing and switching devices. As a result, many large Internet companies now require developers to be able to use Linux.

 

Summary of Common Linux commands

Commands related to system operations

支那1.支那System information To deal with

Arch shows the processor architecture of the machine

Uname -m Displays the processor architecture of the machine

Uname -r Displays the kernel version in use

Dmidecode -Q Display hardware system components – (SMBIOS/DMI)

Hdparm -i /dev/hda lists the architectural features of a disk

Hdparm -tt /dev/sda Performs a test read operation on disk

Cat /proc/cpuinfo Displays CPU information

Cat /proc/interrupts Displays an interrupt

Cat /proc/meminfo Verifies memory usage

Cat /proc/swaps shows which swaps are used

Cat /proc/version Displays the kernel version

Cat /proc/net/dev Displays network adapter and statistics

Cat /proc/mounts Displays a loaded file system

Lspci-tv lists all PCI devices

Lsusb-tv Displays USB devices

Date Displays the system date

CAL 2020 Displays the calendar for 2020

Date Displays the current system time

Clock -w Saves the time change to the BIOS

2. The system restarts and shuts down

Shutdown -h now Shuts down the system

Init 0 Shuts down the system

Telinit 0 Shut down the system

Shutdown -h hours:minutes & shutdown the system at the scheduled time

Shutdown -c Cancels shutting down the system at the scheduled time

Shutdown -r now Restart

Reboot to restart

Logout logout

 

Two, file operation related commands

1.file and directory operation 

CD /home Go to ‘/ home’ directory

cd .. Returns the upper directory

cd .. /.. Returns the previous two levels of directories

CD goes to the personal home directory

CD ~user1 Go to the personal home directory

CD – Returns the last directory

PWD Displays the current working path

Ls Displays files in a directory

Ls -f Displays files in the directory

Ls -l Displays detailed information about files and directories

Ls -a Displays hidden files

Ls *[0-9]* Displays the file name and directory name containing digits

Tree Displays the tree structure of files and directories starting from the root directory

Lstree displays the tree structure of files and directories starting from the root directory

Mkdir dir1 Creates a directory called ‘dir1’

Mkdir dir1 dir2 Create two directories simultaneously

Mkdir -p/TMP /dir1/dir2 Creates a directory tree

Rm -f file1 delete a file called ‘file1’

Rmdir dir1 Delete a directory called ‘dir1’

Rm -rf dir1 Deletes a directory named ‘dir1’ and its contents at the same time

Rm -rf dir1 dir2 Delete both directories and their contents

Mv dir1 new_dir Renames or moves a directory

Cp file1 file2 Copies 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 Copies a directory

Ln -s file1 lnk1 Creates a soft link to a file or directory

Ln file1 lnk1 Creates a physical link to a file or directory

Touch -t YYMMDDhhmm file1 Changes the timestamp of a file or directory

Iconv-l lists the known encodings

2,File search operation 

Find / -name file1 Searches for files and directories in the root file system starting with ‘/’

Find / -user user1 Searches for files and directories belonging to user ‘user1’

Find /home/user1-name \*. Bin Searches for files ending in’.bin’ in the directory ‘/home/user1’

Find /usr/bin-type f-atime +100 Searches for execution files that have not been used in the past 100 days

Find /usr/bin-type f-mtime-10 Searches for files that have been created or modified within 10 days

find / -name \*.rpm -exec chmod 755 ‘{}’ \; Search for files ending in ‘.rpm’ and define their permissions

Find / -xdev-name \*. RPM Searches for files ending in ‘. RPM ‘, ignoring removable devices such as CD-ROM drives and flash drives

Locate \*.ps Finds files ending in ‘.ps’

Whereis Halt displays the location of a binary, source, or MAN

Which HALT displays the full path to a binary or executable file

3,file Mount system* * * *

Mount /dev/hda2 / MNT /hda2 to mount a disk named hda2 – make sure the directory ‘/ MNT /hda2’ already exists

Umount /dev/hda2 Unmount a disk named hda2 from the mount point ‘/ MNT /hda2’

User-km/MNT /hda2 Forcibly uninstalls the device when it is busy

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

Mount /dev/fd0/mnt /floppy Mounts a floppy disk

Mount /dev/cdrom/MNT /cdrom To mount a Cdrom or dvdrom

Mount /dev/hdc/MNT/cdRecorder to mount a CDRW or DVdrom

Mount /dev/hdb/mnt/cdRecorder to mount a CDRW or dvdrom

Mount -o loop file.iso/MNT /cdrom To mount a file or iso image file

Mount -t vfat /dev/hda5 / MNT /hda5 Mount a Windows FAT32 file system

Mount /dev/sda1 / MNT /usbdisk To mount a USB flash drive or flash storage device

Mount -t SMBFS -o username=user,password=pass //WinClient/share/MNT /share Mount a Windows network share

 

4,File permissions operation

Ls -lh Displays permissions

The ls/TMP | pr – T5 – W $COLUMNS will be divided into 5 bar terminal display

Chmod ugo+ RWX directory1 Sets owner (u), group (g), and other (O) permissions for the directory to read (r), write (w), and execute (x)

Chmod go-rwx directory1 Deletes the read/write permissions of the group (g) and others (O) on the directory

Chown user1 file1 changes the owner attribute of a file

Chown -r user1 directory1 Changes the owner properties of a directory and the properties of all files in the directory

CHGRP group1 file1 Specifies the group that changes the file

Chown user1:group1 file1 Changes the owner and group properties of a file

Find / -perm -u+s lists all files in a system that use SUID control

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

Chmod u-s /bin/file1 Disables the SUID bit of a binary file

Chmod g+s /home/public Sets the SGID bit of a directory – similar to SUID, except for directories

Chmod g-s /home/public Disables the SGID bit of a directory

Chmod o+t /home/public Sets the STIKY bits of a file – only allows legal owners to delete files

Chmod o-t /home/public Disables the STIKY bit of a directory

5,Special properties of the file

Chattr +a file1 Files can be read or written in appending mode only

Chattr +c file1 allows this file to be automatically compressed/uncompressed by the kernel

Chattr +d file1 This file is ignored by the dump program during file system backup

Chattr + I file1 is set to an immutable file that cannot be deleted, modified, renamed, or linked

Chattr +s file1 allows a file to be safely deleted

Chattr +S file1 Causes the system to write the changes to disk as soon as the application writes to the file

Chattr +u file1 If a file is deleted, the system will allow you to restore the deleted file at a later time

Lsattr displays special attributes

6,Package and compress files

Bunzip2 file1.bz2 unzip a file called ‘file1.bz2’

Bzip2 file1 compresses a file called ‘file1’

Gunzip file1.gz Unzip a file called ‘file1.gz’

Gzip file1 compresses a file called ‘file1’

Gzip-9 File1 Maximum compression

Rar a file1.rar test_file creates a package called ‘file1.rar’

Rar a file1. Rar file1 file2 dir1 Compresses ‘file1’, ‘file2’ and directory ‘dir1’ simultaneously.

Unrar x file1.rar Decompresses the RAR package

Tar -cvf archive.tar file1 Creates an uncompressed tarball

Tar -cvf archive.tar file1 file2 dir1 Creates an archive file containing ‘file1’, ‘file2’ and ‘dir1’

Tar -tf archive.tar displays the contents of a package

Tar -xvf archive.tar Releases a package

Tar -xvf archive.tar -c/TMP Release the compressed package to the/TMP directory

Tar -cvfj archive.tar.bz2 dir1 Creates a compressed package in bzip2 format

Tar -jxvf archive.tar.bz2 Decompress a bzip2 package

Tar -cvfz archive.tar.gz dir1 Create a compressed package in gzip format

Gz Decompress a package in gzip format

Zip file1. Zip file1 Creates a zip package

Zip -r file1.zip file1 file2 dir1 Compresses several files and directories into a zip package

Unzip file1.zip Decompresses a zip package

 

7,Viewing file Contents 

Cat file1 Forwards the file from the first byte

Cat file1 file2 Displays the contents of files 1 and 2 simultaneously

Cat file1 file2 > mfile Merge file file1 and file file2 and save them to file mfile

Tac file1 looks at the contents of a file in reverse, starting with the last line

More file1 Displays the contents of a long file

Less file1 is similar to the ‘more’ command, but it allows reverse operations in a file as well as operations

Head-2 file1 Displays the first two lines of a file

Head -v file1 Displays the content of file file1 and the file title

Tail-2 file1 Displays the last two lines of a file

Tail -c 10 file1 Displays the last 10 characters of a file

Tail -f /var/log/messages View the contents added to a file in real time

Eight,Text processing

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

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

Grep Aug /var/log/messages Find the keyword “Aug” in the file ‘/var/log/messages’

Grep ^Aug /var/log/messages Look for words starting with “Aug” in the file ‘/var/log/messages’

Grep [0-9] /var/log/messages Select all lines containing numbers in the ‘/var/log/messages’ file

Grep Aug -r /var/log/* Search for the string “Aug” in the directory ‘/var/log’ and subsequent directories

Sed ‘s/stringa1/stringa2/g’ example. TXT replace “string1” in example. TXT with “string2”

Sed ‘/^$/d’ example.txt deletes all blank lines from example.txt

sed ‘/ *#/d; /^$/d’ example.txt Removes all comments and blank lines from example.txt

Echo ‘esempio’ | tr / : the lower: ‘ ‘[: upper:]’ merger and content of cells

Sed -e ‘1d’ result. TXT excludes the first line from the file example. TXT

Sed -n ‘/stringa1/p’ looks at lines containing only the word “string1”

Sed -e ‘s/ *$//’ example. TXT deletes the whitespace character at the end of each line

Sed -e ‘s/stringa1//g’ example. TXT deletes only the word “string1” from the file and keeps all the rest

Sed – n ‘1, 5 p; 5q’ example.txt Displays the contents from line 1 to line 5

sed -n ‘5p; 5q’ example.txt Look at line 5

Sed -e ‘s/00*/0/g’ example.txt replaces multiple zeros with a single zero

Cat -n file1 indicates the number of lines in a file

The cat example. TXT | awk ‘NR % 2 = = 1’ delete example. All even lines of the TXT file

Echo a b c | awk ‘} {print $1 to check the line of the first column

Echo a b c | awk ‘{print $1, $3}’ see a row of the first and the third column

Paste File1 file2 Combines the contents of two files or columns

Paste -d ‘+’ file1 file2 Combines the contents of two files or columns with “+” between them

Sort file1 file2 Sorts the contents of two files

Sort file1 file2 | uniq took out two file and set the line only keep a (repeat)

Sort file1 file2 | uniq -u delete intersection, leaving the other line

Sort file1 file2 | uniq – d out the intersection of two files (leaving only exists in two files in the file at the same time)

Comm-1 file1 file2 Compares the contents of two files and deletes only the contents contained in ‘file1’

Comm-2 file1 file2 Compares the contents of two files and deletes only the contents contained in ‘file2’

Comm-3 file1 file2 Compares the contents of two files and deletes only the common parts of the two files

9,Character Settings and file format conversion

TXT Fileunix. TXT converts a text file format from MSDOS to UNIX

Unix2dos fileunix.txt Converts a text file from UNIX to MSDOS

recode .. HTML < page.txt > page.html converts a text file to HTML

Recode – l | more show all allow conversion formats

10,File System Analysis

Badblocks -v /dev/hda1 Check the bad magnetic blocks on disk Hda1

FSCK /dev/hda1 Fixes/checks the integrity of the Linux file system on the hda1 disk

Ext2 /dev/hda1 Repair/check the integrity of the ext2 file system on the hda1 disk

E2fsck /dev/hda1 Repair/check the integrity of the ext2 file system on disk hda1

E2fsck -j /dev/hda1 Restores/checks the integrity of the ext3 file system on hda1

Ext3 /dev/hda1 Repair/check the integrity of the ext3 file system on the hda1 disk

Fsck. vfat /dev/hda1 Repair/check the integrity of the FAT file system on hda1

Fsck.msdos /dev/hda1 Fixes/checks the integrity of the DOS file system on the hda1 disk

Dosfsck /dev/hda1 Fixes/checks the integrity of the DOS file system on the hda1 disk

11,Example Initialize a file system 

MKFS /dev/hda1 Creates a file system in the hda1 partition

Mke2fs /dev/hda1 Creates a Linux ext2 file system in the hda1 partition

Mke2fs -j /dev/hda1 creates a Linux ext3(journaling) file system in the hda1 partition

MKFS -t vfat 32 -f /dev/hda1 Creates a FAT32 file system

Fdformat -n /dev/fd0 Formats a floppy disk

Mkswap /dev/hda3 Create a swap file system

12,SWAP file system 

Mkswap /dev/hda3 Create a swap file system

Swapon /dev/hda3 Enables a new swap file system

Swapon /dev/hda2 /dev/hdb3 Enable two swap partitions

Commands related to disk space

Df -h Displays the list of mounted partitions

Ls – lSr | more arranged in size files and directories

Du -sh dir1 Estimated disk space used by directory ‘dir1’

Du – sk * | sort – rn) based on size, in turn, according to the size of the files and directories

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)

dpkg-query -W -f=’${Installed-Size; 10} ${Package} n ‘t | sort – k1, 1 n based on the size of the display installed deb Package used by space (ubuntu, debian system)

 

4. Commands related to users and groups

Groupadd group_name Creates a user group

Groupdel group_name Deletes a user group

Groupmod -n new_group_name old_group_name Renames a user group

Useradd -c “Name Surname “-g admin -d /home/user1 -s /bin/bash user1 Creates a user belonging to user group admin

Useradd user1 creates a new user

Userdel -r user1 Deletes a user (‘-r’ excludes the home directory)

Usermod -c “User FTP” -g system -d/FTP /user1 -s /bin/nologin user1 Modifies User attributes

Passwd Changes the password

Passwd user1 Changes the password of a user (root only).

Chage -E 2005-12-31 user1 Sets the validity period of the user password

PWCK checks ‘/etc/passwd’ for file format and syntax corrections as well as existing users

GRPCK checks ‘/etc/passwd’ for file format and syntax corrections as well as existing groups

Newgrp group_name logs in to a new group to change the default group for newly created files

Fedora, Redhat, and similar commands

1.The RPM package The command 

RPM -ivh package. RPM Installs an RPM package

RPM -ivh –nodeeps package. RPM Installs an RPM package and ignores dependency warnings

RPM -u package. RPM Updates an RPM package without changing its configuration file

RPM -f package. RPM Updates an RPM package that has been installed

RPM -e package_name. RPM Deletes an RPM package

RPM -qa Displays all installed RPM packages in the system

RPM – qa | grep HTTPD shows all name contains “HTTPD” RPM package

RPM -qi package_name Gets special information about an installed package

RPM -qg “System Environment/Daemons” displays the RPM package of a component

RPM -ql package_name Displays a list of files provided by an installed RPM package

RPM -QC package_name Displays a list of configuration files provided by an installed RPM package

RPM -q package_name –whatrequires displays a list of dependencies that exist with an RPM package

RPM -q package_name –whatprovides Displays the volume of an RPM package

RPM -q package_name –scripts displays the script L executed during installation/deletion

RPM -q package_name –changelog Displays the change history of an RPM package

The RPM – qf/etc/HTTPD/conf/HTTPD. Conf the confirmation to the documents provided by which RPM package

RPM -qp package. RPM -l displays a list of files provided by an RPM package that has not yet been installed

RPM –import /media/cdrom/RPM -gpg-key Import the public KEY digital certificate

RPM –checksig package. RPM Verifies the integrity of an RPM package

RPM -qa gpg-pubkey Check the integrity of all installed RPM packages

RPM -v package_name Check the file size, license, type, owner, group, MD5 check, and last modification time

RPM -va Check all installed RPM packages in the system – Use them with caution

RPM -vp package. RPM Check that an RPM package is not installed

Rpm2cpio package. The RPM | cpio, extract, the make – bin directories * * from a RPM package run an executable file

RPM -ivh /usr/src/redhat/rpm/’ arch ‘/package. RPM Installs a built package from an RPM source

Rpmbuild –rebuild package_name.src. RPM Builds an RPM package from an RPM source

2. YUM software package upgrader

Yum install package_name Download and install an RPM package

Yum localInstall package_name. RPM will install an RPM package and use your own repository to resolve all dependencies for you

Yum update package_name. RPM Updates all installed RPM packages in the system

Yum update package_name Updates an RPM package

Yum remove package_name Deletes an RPM package

Yum List lists all packages installed on the current system

Yum Search package_name Searches for packages in the RPM repository

Yum Clean Packages delete the downloaded packages from the RPM cache

Yum Clean headers deletes all header files

Yum Clean All deletes all cached packages and headers

 

Debian, Ubuntu and similar system related commands

1.DEB package

DPKG -i package.deb Installs/updates a deb package

DPKG -r package_name Deletes a DEB package from the system

DKG -l displays all deb packages installed in the system

DPKG -l | grep HTTPD shows all name contains “HTTPD” deb package

DKG -s package_name Gets information about a particular package that has been installed on the system

DPKG -l package_name displays a list of files provided by a DEB package that has been installed on your system

DPKG –contents package.deb displays a list of files provided by a package that has not yet been installed

DPKG -s /bin/ping confirms which deb package is providing the file given

2,APT Software Tools

Apt-get install package_name Install/update a deb package

Apt-cdrom install package_name Install/update a deb package from the cd-rom

Apt-get Update Updates software packages in the list

Apt-get upgrade Upgrades all installed software

Apt-get remove package_name Deletes a deb package from the system

Apt-get check Verifies that the software repository is correct

Apt-get clean Cleans the cache from downloaded packages

Apt-cache search searched-package returns the name of the package containing the searched string

Seven, backup and CD related commands

1.The backupoperation

Dump-0aj -f/TMP /home0.bak /home Make a full backup of the ‘/home’ directory

Dump-1aj -f/TMP /home0.bak /home Make an interactive backup of the ‘/home’ directory

Restore-if/TMP /home0.bak Restores an interactive backup

Rsync-rogpav –delete /home/tmp To synchronize the directories on both sides

Rsync-rogpav -e SSH –delete /home ip_address:/ TMP Rsync through the SSH channel

Rsync-az -e SSH –delete ip_addr:/home/public /home/local To synchronize a remote directory to the local directory through SSH and compression

Rsync-az -e SSH –delete /home/local ip_addr:/home/public To synchronize the local directory to the remote directory through SSH and compression

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

Dd if=/dev/sda of=/ TMP /file1 backup the disk contents to a file tar -puf backup.tar /home/user perform an interactive backup operation on the ‘/home/user’ directory

(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

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

tar cf – . | (cd /tmp/backup ; Tar xf -) locally Copy a directory to another location, keeping the original permissions and links

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

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

Dd if=/dev/hda of=/dev/fd0 bs=512 count=1 Copy the contents of the MBR (Master Boot Record) to the floppy disk

Dd if=/dev/fd0 of=/dev/hda bs=512 count=1 Restore the MBR content from the backup saved to the floppy disk

2,CD operation

Cdrecord -v gracetime=2 dev=/dev/ cdrom-eject blank= fast-force Clears the contents of a reproducible CD

Mkisofs /dev/cdrom > cd.iso Create an ISO image file on the disk

Mkisofs/dev/cdrom | gzip > cd_iso. Gz on disk to create a compressed the cd-rom iso image files

Mkisofs-j-allow-leading-dots -r -v “Label CD” -iso-level 4 -o./cd.iso data_cd Creates an ISO image file for a directory

CD record -v dev=/dev/cdrom cd.iso Burns an ISO image file

Gzip – dc cd_iso. Gz | cdrecord dev = / dev/cdrom – burn a compressed the ISO image file

Mount -o loop CD. Iso/MNT /iso Mount an ISO image file

Cd-paranoi-b transcribe audio tracks from a CD to a WAV file

Cd-paranoia — “-3” transcribe audio tracks from a CD to a WAV file (parameter -3)

Cdrecord – scanbus scan bus in order to identify the SCSI channel dd if = / dev/HDC | md5sum check md5sum encoding of a device, such as a CD

Ethernet and WIFI wireless related commands

Ifconfig eth0 displays the configuration of an Ethernet card

Ifup eth0 Enables an ‘eth0’ network device

Ifdown eth0 Disables an ‘eth0’ network device

Ifconfig eth0 192.168.1.1 netmask 255.255.255.0 Control IP address

Ifconfig eth0 promisc Set ‘eth0’ to promiscuous mode to sniff packets

Dhclient eth0 enable ‘eth0’ in DHCP mode

route -n show routing table 

route add -net 0/0 gw IP_Gateway configura default gateway 

Route add-net 192.168.0.0 gw 192.168.1.1 configure static route to reach network ‘192.168.0.0/16’

 

Think useful remember to like attention yo!

Big bad Wolf accompany you to progress together!