The Linux common command collection is not allowed to be missed
- 2020-05-15 02:39:05
- OfStack
Paste study notes directly:
System information
arch Displays the processor architecture of the machine (1)
uname -m Displays the processor architecture of the machine (2)
uname -r Displays the kernel version in use
dmidecode -q Display hardware system components - (SMBIOS / DMI)
hdparm -i /dev/hda list 1 Architecture features of disk
hdparm -tT /dev/sda Perform a testability read operation on the disk
cat /proc/cpuinfo According to CPU info The information of
cat /proc/interrupts According to the interrupt
cat /proc/meminfo Verify memory usage
cat /proc/swaps Show which swap By using
cat /proc/version Displays the version of the kernel
cat /proc/net/dev Displays network adapters and statistics
cat /proc/mounts Displays the loaded file systems
lspci -tv list PCI equipment
lsusb -tv According to USB equipment
date Display system date
cal 2007 According to 2007 Calendar year
date 041217002007.00 Set the date and time - Month day time year . seconds
clock -w Save the time change to BIOS
To turn it off ( Shutdown, restart, and logout of the system )
shutdown -h now Shut down the system (1)
init 0 Shut down the system (2)
telinit 0 Shut down the system (3)
shutdown -h hours:minutes & Shut down the system on schedule
shutdown -c Cancel scheduled system shutdown
shutdown -r now restart (1)
reboot restart (2)
logout The cancellation
Files and directories
cd /home Enter the '/ home' directory '
cd .. On the back 1 Level directory
cd ../.. Return to the previous two levels of directory
cd Go to your home directory
cd ~user1 Go to your home directory
cd - Return to the directory where you were last
pwd Show work path
ls View the files in the directory
ls -F View the files in the directory
ls -l Displays file and directory details
ls -a Show hidden files
ls *[0-9]* Displays the file name and directory name containing the number
tree Displays the tree structure of files and directories starting from the root directory (1)
lstree Displays the tree structure of files and directories starting from the root directory (2)
mkdir dir1 create 1 called 'dir1' The directory where the '
mkdir dir1 dir2 Create two directories at the same time
mkdir -p /tmp/dir1/dir2 create 1 A directory tree
rm -f file1 delete 1 called 'file1' The file '
rmdir dir1 delete 1 called 'dir1' The directory where the '
rm -rf dir1 delete 1 called 'dir1' Deletes its contents at the same time
rm -rf dir1 dir2 Delete both directories and their contents at the same time
mv dir1 new_dir rename / mobile 1 A directory
cp file1 file2 copy 1 A file
cp dir/* . copy 1 All files in the directory to the current working directory
cp -a /tmp/dir1 . copy 1 Directory to the current working directory
cp -a dir1 dir2 copy 1 A directory
ln -s file1 lnk1 create 1 A soft link to a file or directory
ln file1 lnk1 create 1 A physical link to a file or directory
touch -t 0712250000 file1 Modify the 1 The time stamp of a file or directory - (YYMMDDhhmm)
file file1 outputs the mime type of the file as text
iconv -l Lists known encodings
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.
find . -maxdepth 1 -name *.jpg -print -exec convert "{}" -resize 80x60 "thumbs/{}" \; batch resize files in the current directory and send them to a thumbnails directory (requires convert from Imagemagick)
File search
find / -name file1 from '/' Start searching for files and directories on the root file system
find / -user user1 Search belongs to the user 'user1' Files and directories
find /home/user1 -name \*.bin In the directory '/ home/user1' Middle search zone '.bin' Closing file
find /usr/bin -type f -atime +100 Search in the past 100 An execution file that has not been used within days
find /usr/bin -type f -mtime -10 Search in the 10 A file that has been created or modified within days
find / -name \*.rpm -exec chmod 755 '{}' \; The search for '.rpm' End of the file and define its permissions
find / -xdev -name \*.rpm The search for '.rpm' At the end of the file, ignore the cd-rom, disc and other mobile devices
locate \*.ps Looking for to '.ps' Closing file - First run 'updatedb' The command
whereis halt According to 1 a 2 Base file, source code, or man The location of the
which halt According to 1 a 2 The full path to a base file or executable
mount 1 File system
mount /dev/hda2 /mnt/hda2 mount 1 called hda2 The dish - Determine the directory '/ mnt/hda2' existing
umount /dev/hda2 uninstall 1 called hda2 The dish - Start at the hardpoint '/ mnt/hda2' exit
fuser -km /mnt/hda2 Force uninstall when the device is busy
umount -n /mnt/hda2 Run the unload operation without writing /etc/mtab file - This is useful when the file is read-only or when the disk is full
mount /dev/fd0 /mnt/floppy mount 1 A floppy disk
mount /dev/cdrom /mnt/cdrom mount 1 a cdrom or dvdrom
mount /dev/hdc /mnt/cdrecorder mount 1 a cdrw or dvdrom
mount /dev/hdb /mnt/cdrecorder mount 1 a cdrw or dvdrom
mount -o loop file.iso /mnt/cdrom mount 1 A file or ISO Image file
mount -t vfat /dev/hda5 /mnt/hda5 mount 1 a Windows FAT32 The file system
mount /dev/sda1 /mnt/usbdisk mount 1 a usb A thumb drive or flash memory device
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share mount 1 a windows A network share
Disk space
df -h Displays a list of mounted partitions
ls -lSr |more Arrange files and directories by size
du -sh dir1 To estimate the directory 'dir1' Used disk space '
du -sk * | sort -rn Displays the file and directory sizes in order of size
rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n Displays installed ones in order of size rpm The space used by the package (fedora, redhat Such systems )
dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n Displays installed by size deb The space used by the package (ubuntu, debian Such systems )
Users and groups
groupadd group_name create 1 Two new user groups
groupdel group_name delete 1 A group of users
groupmod -n new_group_name old_group_name rename 1 A group of users
useradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1 create 1 A to belong to "admin" Users of user groups
useradd user1 create 1 A new user
userdel -r user1 delete 1 A user ( '-r' Exclude home directory )
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 Modify user properties
passwd Change password
passwd user1 Modify the 1 User's password ( Only allow root perform )
chage -E 2005-12-31 user1 Set the expiration date of the user password
pwck check '/etc/passwd' File format and syntax corrections exist for users as well
grpck check '/etc/passwd' File format and syntax corrections as well as the existence of groups
newgrp group_name Log into 1 To change the default group for the newly created file
File permissions - use "+" Set permissions to use "-" Used to cancel
ls -lh Show permissions
ls /tmp | pr -T5 -W$COLUMNS Divide the terminal into 5 Bar displays
chmod ugo+rwx directory1 Set the directory to the owner (u) , groups, (g) And others (o) To read ( r ), and write (w) And perform (x) The permissions
chmod go-rwx directory1 Delete the group (g) With others (o) Read and write access to the directory
chown user1 file1 change 1 The owner property of a file
chown -R user1 directory1 change 1 Change the properties of all the files in the directory at the same time
chgrp group1 file1 Change the group of files
chown user1:group1 file1 change 1 The owner and group properties of a file
find / -perm -u+s list 1 All of the systems used SUID Controlled file
chmod u+s /bin/file1 Set up the 1 a 2 Base file SUID position - The user who runs the file is also given the same privileges as the owner
chmod u-s /bin/file1 disable 1 a 2 Base file SUID position
chmod g+s /home/public Set up the 1 A directory of SGID position - similar SUID But this is for the directory
chmod g-s /home/public disable 1 A directory of SGID position
chmod o+t /home/public Set up the 1 A file STIKY position - Only legal owners are allowed to delete files
chmod o-t /home/public disable 1 A directory of STIKY position
Special properties of the file - use "+" Set permissions to use "-" Used to cancel
chattr +a file1 Only appends are allowed to read and write files
chattr +c file1 Allows this file to be compressed automatically by the kernel / Unpack the
chattr +d file1 When doing a file system backup, dump The program will ignore this file
chattr +i file1 Set to an immutable file that cannot be deleted, modified, renamed, or linked
chattr +s file1 allow 1 Two files were safely deleted
chattr +S file1 1 Once the application writes to the file, the system immediately writes the modified result to disk
chattr +u file1 If a file is deleted, the system will allow you to recover the deleted file later
lsattr Displays special properties
Package and compress files
bunzip2 file1.bz2 Unpack the 1 called 'file1.bz2' The file
bzip2 file1 The compression 1 called 'file1' The file
gunzip file1.gz Unpack the 1 called 'file1.gz' The file
gzip file1 The compression 1 called 'file1' The file
gzip -9 file1 Maximum compression
rar a file1.rar test_file create 1 called 'file1.rar' The package
rar a file1.rar file1 file2 dir1 At the same time compression 'file1', 'file2' As well as the directory 'dir1'
rar x file1.rar Unpack the rar package
unrar x file1.rar Unpack the rar package
tar -cvf archive.tar file1 create 1 It's uncompressed tarball
tar -cvf archive.tar file1 file2 dir1 create 1 A contains 'file1', 'file2' As well as 'dir1' Archive file
tar -tf archive.tar According to 1 The contents of a package
tar -xvf archive.tar The release of 1 A package
tar -xvf archive.tar -C /tmp Release the compressed package into /tmp directory
tar -cvfj archive.tar.bz2 dir1 create 1 a bzip2 Format of the compressed package
tar -xvfj archive.tar.bz2 Unpack the 1 a bzip2 Format of the compressed package
tar -cvfz archive.tar.gz dir1 create 1 a gzip Format of the compressed package
tar -xvfz archive.tar.gz Unpack the 1 a gzip Format of the compressed package
zip file1.zip file1 create 1 a zip Format of the compressed package
zip -r file1.zip file1 file2 dir1 Compress several files and directories into 1 a zip Format of the compressed package
unzip file1.zip Unpack the 1 a zip Format package
RPM package - ( Fedora, Redhat And similar systems)
rpm -ivh package.rpm The installation 1 a rpm package
rpm -ivh --nodeeps package.rpm The installation 1 a rpm The package ignores the dependency warnings
rpm -U package.rpm update 1 a rpm The package does not change its configuration file
rpm -F package.rpm update 1 One is sure to have been installed rpm package
rpm -e package_name.rpm delete 1 a rpm package
rpm -qa Displays all installed files on the system rpm package
rpm -qa | grep httpd Displays all name contained "httpd" The wording of the rpm package
rpm -qi package_name To obtain 1 Special information about installed packages
rpm -qg "System Environment/Daemons" According to 1 A component of rpm package
rpm -ql package_name According to 1 Two already installed rpm A list of files provided by the package
rpm -qc package_name According to 1 Two already installed rpm A list of configuration files provided by the package
rpm -q package_name --whatrequires Display and 1 a rpm The package has a list of dependencies
rpm -q package_name --whatprovides According to 1 a rpm The volume of the package
rpm -q package_name --scripts Display at installation / Script executed during deletion l
rpm -q package_name --changelog According to 1 a rpm Package modification history
rpm -qf /etc/httpd/conf/httpd.conf Confirm which files are given rpm Provided by the package
rpm -qp package.rpm -l According to the 1 Not yet installed rpm A list of files provided by the package
rpm --import /media/cdrom/RPM-GPG-KEY Import the public key digital certificate
rpm --checksig package.rpm confirm 1 a rpm Package integrity
rpm -qa gpg-pubkey Verify all installed rpm Package integrity
rpm -V package_name Check file size, License, type, owner, group, MD5 Review and last modified time
rpm -Va Check all installed in the system rpm package - Be careful with
rpm -Vp package.rpm confirm 1 a rpm The package has not been installed
rpm2cpio package.rpm | cpio --extract --make-directories *bin* from 1 a rpm The package runs the executable
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm from 1 a rpm The source code to install 1 A built package
rpmbuild --rebuild package_name.src.rpm from 1 a rpm The source code to build 1 a rpm package
YUM Software package upgrader - ( Fedora, RedHat And similar systems)
yum install package_name Download and install 1 a rpm package
yum localinstall package_name.rpm Will be installed 1 a rpm Package, use your own repository to resolve all dependencies for you
yum update package_name.rpm Updates all installations on the current system rpm package
yum update package_name update 1 a rpm package
yum remove package_name delete 1 a rpm package
yum list Lists all packages installed on the current system
yum search package_name in rpm Search the repository for software packages
yum clean packages Clean up the rpm Cache removes downloaded packages
yum clean headers Delete all header files
yum clean all Delete all cached package and header files
DEB package (Debian, Ubuntu And systems like that )
dpkg -i package.deb The installation / update 1 a deb package
dpkg -r package_name Delete from the system 1 a deb package
dpkg -l Displays all installed files on the system deb package
dpkg -l | grep httpd Displays all name contained "httpd" The wording of the deb package
dpkg -s package_name Get already installed on the system 1 Information about a special package
dpkg -L package_name Display system installed 1 a deb A list of files provided by the package
dpkg --contents package.deb Displays what has not been installed 1 A list of files provided by a package
dpkg -S /bin/ping Confirm which files are given deb Package provides
APT Software tools (Debian, Ubuntu And systems like that )
apt-get install package_name The installation / update 1 a deb package
apt-cdrom install package_name Install from CD / update 1 a deb package
apt-get update Upgrade the packages in the list
apt-get upgrade Upgrade all installed software
apt-get remove package_name Delete from the system 1 a deb package
apt-get check Verify that the dependent software repository is correct
apt-get clean Clean the cache from the downloaded package
apt-cache search searched-package Returns the package name that contains the string to search for
View file contents
cat file1 From the first 1 Four bytes start to view the contents of the file forward
tac file1 From the last 1 Rows begin to be viewed in reverse 1 The contents of a file
more file1 To view 1 The contents of a long file
less file1 Similar to the 'more' Command, but it allows forward and forward operations in files 1 Reverse operation of the sample
head -2 file1 To view 1 The first two lines of a file
tail -2 file1 To view 1 The last two lines of a file
tail -f /var/log/messages Live view is added to 1 The contents of a file
Text processing
cat file1 file2 ... | command <> file1_in.txt_or_file1_out.txt general syntax for text manipulation using PIPE, STDIN and STDOUT
cat file1 | command( sed, grep, awk, grep, etc...) > result.txt merge 1 The detailed text of the file, and the introduction is written 1 In a new file
cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt merge 1 The detailed text of the file, and the introduction is written 1 Two existing files
grep Aug /var/log/messages In the file '/var/log/messages' Search for keywords in "Aug"
grep ^Aug /var/log/messages In the file '/var/log/messages' Look for to "Aug" Beginning words
grep [0-9] /var/log/messages choose '/var/log/messages' All lines in the file that contain Numbers
grep Aug -R /var/log/* In the directory '/var/log' And the following directory to search for strings "Aug"
sed 's/stringa1/stringa2/g' example.txt will example.txt In the file "string1" replace "string2"
sed '/^$/d' example.txt from example.txt Delete all blank lines from the file
sed '/ *#/d; /^$/d' example.txt from example.txt Remove all comments and blank lines from the file
echo 'esempio' | tr '[:lower:]' '[:upper:]' Merge the contents of the next and next cells
sed -e '1d' result.txt From the file example.txt To exclude the first 1 line
sed -n '/stringa1/p' The view contains only terms "string1" The rows of
sed -e 's/ *$//' example.txt Delete every 1 The blank character at the end of the line
sed -e 's/stringa1//g' example.txt Only terms are removed from the document "string1" And keep the rest
sed -n '1,5p;5q' example.txt Viewing from the first 1 Line to the first 5 line
sed -n '5p;5q' example.txt Look at the first 5 line
sed -e 's/00*/0/g' example.txt Replace multiple zeros with a single zero
cat -n file1 Indicates the number of lines in the file
cat example.txt | awk 'NR%2==1' delete example.txt All the even lines in the file
echo a b c | awk '{print $1}' To view 1 Line first 1 bar
echo a b c | awk '{print $1,$3}' To view 1 The first 1 And the first 3 bar
paste file1 file2 Merge the contents of two files or two columns
paste -d '+' file1 file2 Merge the contents of two files or two columns, in between "+" Distinguish between
sort file1 file2 Sort the contents of two files
sort file1 file2 | uniq Retrieves the union of two files ( Duplicate lines are reserved 1 Copy of the )
sort file1 file2 | uniq -u Delete the intersection, leaving the other rows
sort file1 file2 | uniq -d Takes the intersection of two files ( Only files that exist in both files are left )
comm -1 file1 file2 Compare the contents of two files to delete only 'file1' The contents contained
comm -2 file1 file2 Compare the contents of two files to delete only 'file2' The contents contained
comm -3 file1 file2 Comparing the contents of two files removes only the parts that the two files have in common
Character setup and file format conversion
dos2unix filedos.txt fileunix.txt will 1 Text file format from MSDOS Converted to UNIX
unix2dos fileunix.txt filedos.txt will 1 Text file format from UNIX Converted to MSDOS
recode ..HTML < page.txt > page.html will 1 Two text files to convert to html
recode -l | more Displays all allowed conversion formats
File system analysis
badblocks -v /dev/hda1 Check the disk hda1 Bad magnetic block on
fsck /dev/hda1 repair / check hda1 On the disk linux File system integrity
fsck.ext2 /dev/hda1 repair / check hda1 On the disk ext2 File system integrity
e2fsck /dev/hda1 repair / check hda1 On the disk ext2 File system integrity
e2fsck -j /dev/hda1 repair / check hda1 On the disk ext3 File system integrity
fsck.ext3 /dev/hda1 repair / check hda1 On the disk ext3 File system integrity
fsck.vfat /dev/hda1 repair / check hda1 On the disk fat File system integrity
fsck.msdos /dev/hda1 repair / check hda1 On the disk dos File system integrity
dosfsck /dev/hda1 repair / check hda1 On the disk dos File system integrity
Initialize the 1 File system
mkfs /dev/hda1 in hda1 Partition to create 1 File system
mke2fs /dev/hda1 in hda1 Partition to create 1 a linux ext2 File system
mke2fs -j /dev/hda1 in hda1 Partition to create 1 a linux ext3( Log type ) File system
mkfs -t vfat 32 -F /dev/hda1 create 1 a FAT32 The file system
fdformat -n /dev/fd0 formatting 1 A floppy disk
mkswap /dev/hda3 create 1 a swap The file system
SWAP The file system
mkswap /dev/hda3 create 1 a swap The file system
swapon /dev/hda3 To enable the 1 A new one swap The file system
swapon /dev/hda2 /dev/hdb3 To enable the two swap partition
The backup
dump -0aj -f /tmp/home0.bak /home making 1 a '/home' A full backup of the directory
dump -1aj -f /tmp/home0.bak /home making 1 a '/home' Interactive backup of directories
restore -if /tmp/home0.bak reduction 1 10 interactive backups
rsync -rogpav --delete /home /tmp Synchronize the directories on both sides
rsync -rogpav -e ssh --delete /home ip_address:/tmp through SSH channel rsync
rsync -az -e ssh --delete ip_addr:/home/public /home/local through ssh And the compression will 1 Two remote directories are synchronized to a local directory
rsync -az -e ssh --delete /home/local ip_addr:/home/public through ssh And compression synchronize the local directory to the remote directory
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' through ssh Execute on the remote host 1 The operation of secondary backing up the local disk
dd if=/dev/sda of=/tmp/file1 Backup disk contents to 1 A file
tar -Puf backup.tar /home/user perform 1 Time for '/home/user' Interactive backup of directories
( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' through ssh Copy in a remote directory 1 Directory contents
( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' through ssh Copy in a remote directory 1 Local directories
tar cf - . | (cd /tmp/backup ; tar xf - ) Local will 1 Copy the directory to another 1 Keep the original permissions and links
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents from 1 Directory lookup and copy all to '.txt' End the file to another 1 A directory
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 Find all '.log' End the file and make it 1 a bzip package
dd if=/dev/hda of=/dev/fd0 bs=512 count=1 do 1 A will MBR (Master Boot Record) The action of copying content to a floppy disk
dd if=/dev/fd0 of=/dev/hda bs=512 count=1 Restore from a backup that has been saved to a floppy disk MBR content
CD
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force empty 1 One can copy the cd-rom content
mkisofs /dev/cdrom > cd.iso Create on disk 1 A CD iso Image file
mkisofs /dev/cdrom | gzip > cd_iso.gz Create on disk 1 A compact disc iso Image file
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd create 1 A directory of iso Image file
cdrecord -v dev=/dev/cdrom cd.iso burn 1 a ISO Image file
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - burn 1 It's compressed ISO Image file
mount -o loop cd.iso /mnt/iso mount 1 a ISO Image file
cd-paranoia -B from 1 a CD CD transcribed audio tracks to wav In the file
cd-paranoia -- "-3" from 1 a CD CD transcribed audio tracks to wav In the file (parameter -3 )
cdrecord --scanbus Scan the bus for recognition scsi channel
dd if=/dev/hdc | md5sum check 1 A device md5sum Code, such as 1 zhang CD
network - (Ethernet and WIFI Wireless)
ifconfig eth0 According to 1 Two Ethernet card configurations
ifup eth0 To enable the 1 a 'eth0' Network equipment
ifdown eth0 disable 1 a 'eth0' Network equipment
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 control IP address
ifconfig eth0 promisc Set up the 'eth0' To sniff packets in promiscuous mode (sniffing)
dhclient eth0 In order to dhcp Mode is enabled 'eth0'
route -n show routing table
route add -net 0/0 gw IP_Gateway configura default gateway
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 configure static route to reach network '192.168.0.0/16'
route del 0/0 gw IP_gateway remove static route
echo "1" > /proc/sys/net/ipv4/ip_forward activate ip routing
hostname show hostname of system
host www.example.com lookup hostname to resolve name to ip address and viceversa(1)
nslookup www.example.com lookup hostname to resolve name to ip address and viceversa(2)
ip link show show link status of all interfaces
mii-tool eth0 show link status of 'eth0'
ethtool eth0 show statistics of network card 'eth0'
netstat -tup show all active network connections and their PID
netstat -tupl show all network services listening on the system and their PID
tcpdump tcp port 80 show all HTTP traffic
iwlist scan show wireless networks
iwconfig eth1 show configuration of a wireless network card
hostname show hostname
host www.example.com lookup hostname to resolve name to ip address and viceversa
nslookup www.example.com lookup hostname to resolve name to ip address and viceversa
whois www.example.com lookup on Whois database
Microsoft Windows networks (SAMBA)
nbtscan ip_addr netbios name resolution
nmblookup -A ip_addr netbios name resolution
smbclient -L ip_addr/hostname show remote shares of a windows host
smbget -Rr smb://ip_addr/share like wget can download files from a host windows via smb
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share mount a windows network share
Ok, that's all, you can also combine the relevant linux books for learning, I hope you can make progress in the New Year!