Complete collection of linux commands (recommended collection)

1. 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 being used
dmidecode -q displays the hardware system components - (SMBIOS/DMI)
hdparm -i /dev/ hda List the architectural features of a disk
hdparm -tT /dev/sda Perform test read operations on the disk
cat /proc/cpuinfo Display CPU info information
cat /proc/interrupts Display interrupts
cat /proc/meminfo Verify memory usage
cat /proc/swaps Show which swaps are used
cat /proc/version Show kernel version
cat /proc/net/dev Show network adapters and statistics
cat /proc/mounts Show loaded file systems
lspci -tv List PCI devices
lsusb -tv Display USB device
date Display system date
cal 2007 Display calendar date for 2007
041217002007.00 Set date and time - month, day, hour, minute, year.second
clock -w Save time modification to BIOS

Shutdown (system shutdown, restart and logout)
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 &
Shutdown -c Cancel Shut down the system at the scheduled time
shutdown -r now Restart (1)
reboot Restart (2)
logout Logout

2. Files and Directories

cd /home Enter the '/ home' directory'
cd .. Return to the previous directory
cd ../.. Return to the directory two levels above
cd Enter the personal home directory
cd ~user1 Enter the personal home directory
cd - Return to the last location Directory
pwd Display working path
ls View files in the directory
ls -F View files in the directory
ls -l Display file and directory details
ls -a Display hidden files
ls *[0-9]* Display file names and directories containing numbers Name
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 creates a directory called 'dir1'
mkdir dir1 dir2 creates two files at the same time directory
mkdir -p /tmp/dir1/dir2 Create a directory tree
rm -f file1 Delete a file called 'file1'
rmdir dir1 Delete a directory called 'dir1'
rm -rf dir1 Delete a directory called 'dir1' Directory and delete its contents at the same time
rm -rf dir1 dir2 Delete two directories and their contents at the same time
mv dir1 new_dir Rename/move a directory
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 directory pointing to a file or directory Soft link
ln file1 lnk1 Create a physical link to a file or directory
touch -t 0712250000 file1 Modify the timestamp of a file or directory - (YYMMDDhhmm)
file file1 outputs the mime type of the file as text
iconv -l List known encoding
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)

3. File search


find / -name file1 Search for files and directories in the root file system starting from '/'
find / -user user1 Search for files and directories belonging to user 'user1'
find /home/user1 -name \*.bin in directory '/home/ Search for files ending with '.bin' in 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 Files that were created or modified within 10 days
find / -name \*.rpm -exec chmod 755 '{}' \; Search for files ending with '.rpm' and define their permissions
find / -xdev -name \*. rpm searches for files ending with '.rpm', ignoring removable devices such as CD-ROM drives, USB drives, etc.
locate \*.ps searches for files ending with '.ps' - first run the 'updatedb' command
whereis halt displays a binary file, source code or The location of man
which halt displays the full path to a binary or executable file

4. Mount a file system

mount /dev/hda2 /mnt/hda2 Mount a disk called hda2 - Make sure the directory '/mnt/hda2' already exists
umount /dev/hda2 Unmount a disk called hda2 - First, start from the mount point '/mnt/hda2' Exit
fuser -km /mnt/hda2 Force an unmount when the device is busy
umount -n /mnt/hda2 Run an unmount operation without writing the /etc/mtab file - useful when the file is read-only or when the disk is full
mount /dev /fd0 /mnt/floppy mount a floppy disk
mount /dev/cdrom /mnt/cdrom mount a cdrom or dvdrom
mount /dev/hdc /mnt/cdrecorder mount a cdrw or dvdrom
mount /dev/hdb /mnt/cdrecorder mount Mount a cdrw or dvdrom
mount -o loop file.iso /mnt/cdrom 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 mounts a usb disk or flash memory device
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share mounts a windows network share

5. Disk space

df -h displays the list of mounted partitions
ls -lSr |more sorts files and directories by size
du -sh dir1 estimates the used disk space of directory 'dir1'
du -sk * | sort -rn based on capacity Display the size of files and directories in sequence
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 ( fedora, redhat type systems)
dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n displays the space used by installed deb packages based on size (ubuntu, debian type systems)


6. 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 " User of the admin" user group 
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 Modify user attributes 
passwd Modify password 
passwd user1 Modify a user's password (only allowed to be executed by root) 
chage -E 2005-12-31 user1 Set the expiration period of user password 
pwck Check the file format and syntax correction of '/etc/passwd' and Existing users 
grpck Check '/etc/passwd' for file format and syntax corrections and existing groups 
newgrp group_name Log into a new group to change the default group for newly created files 


7. File permissions - use "+" to set permissions, use "-" to cancel 


ls -lh display permissions 
ls /tmp | pr -T5 -W$COLUMNS Divide the terminal into 5 columns and display 
chmod ugo+rwx directory1 Set the owner (u), group (g) and others (o) of the directory to read (r), write (w) and execute (x) permissions 
chmod go-rwx directory1 deletes the read, write and execute 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 attribute of a directory and changes the attributes of all files in the directory at the same time 
chgrp group1 file1 changes the group of the file 
chown user1:group1 file1 changes the owner and group attributes of a file 
find / -perm -u +s List all files in a system that use SUID control 
chmod u+s /bin/file1 Set the SUID bit of a binary file - the user running the file is also given the same permissions as the owner 
chmod us /bin/file1 Disable SUID bit of a binary file 
chmod g+s /home/public Sets the SGID bit of a directory - similar to SUID, but for directories 
chmod gs /home/public Disables the SGID bit of a directory 
chmod o+t /home/public Set the STIKY bit on a file - only allows the legitimate owner to delete the file 
chmod ot /home/public disables the STIKY bit of a directory 

8. Special attributes of files - use "+" to set permissions, use "-" to cancel 


chattr +a file1 Only allows reading and writing files in append mode 
chattr +c file1 Allows this file to be automatically compressed/decompressed by the kernel 
chattr +d file1 When performing a file system backup, the dump program will ignore this file 
chattr +i file1 Set to disable The changed file cannot be deleted, modified, renamed or linked 
chattr +s file1 Allows a file to be safely deleted 
chattr +S file1 Once the application performs a write operation on the file, the system immediately writes the modification results to the disk 
chattr +u file1 If the file is deleted, the system will allow you to restore the deleted file later 
lsattr displays special attributes 

9. Packaging and Compressing Files 


bunzip2 file1.bz2 decompresses a file called 'file1.bz2' 
bzip2 file1 compresses a file called 'file1' 
gunzip file1.gz decompresses a file called 'file1.gz' 
gzip file1 compresses a file called 'file1' 
gzip - 9 file1 Maximize compression 
of rar a file1.rar test_file Create a package called 'file1.rar' 
rar a file1.rar file1 file2 dir1 Compress 'file1', 'file2' and directory 'dir1' at the same time 
rar x file1.rar Decompress rar Package 
unrar 


_ -tf archive.tar Display the contents of a package 
tar -xvf archive.tar Release a package 
tar -xvf archive.tar -C /tmp Release the compressed package to the /tmp directory 
tar -cvfj archive.tar. bz2 dir1 Create a bzip2 format compressed package
tar -xvfj archive.tar.bz2 Decompress a bzip2 format compressed package 
tar -cvfz archive.tar.gz dir1 Create a compressed package in gzip format 
tar -xvfz archive.tar.gz Decompress a compressed package in gzip format 
zip file1.zip file1 Create a compressed package in zip format 
zip -r file1.zip file1 file2 dir1 Compress several files and directories into a zip format compressed package at the same time 
unzip file1.zip Decompress a zip format compressed package 

10. RPM package - (Fedora, Redhat and similar systems) 


rpm -ivh package.rpm Install an rpm package 
rpm -ivh --nodeeps package.rpm Install an rpm package and ignore dependency warnings 
rpm -U package.rpm Update an rpm package without changing its configuration file 
rpm -F package.rpm Update an rpm package that has been installed 
rpm -e package_name.rpm Delete an rpm package 
rpm -qa Display all installed rpm packages in the system 
rpm -qa | grep httpd Display all rpm packages whose names contain the word "httpd" rpm 
- qi package_name Get special information about an installed package 
rpm -qg "System Environment/Daemons" Display the rpm package of a component 
rpm -ql package_name Display the file list provided by an installed rpm package 
rpm -qc package_name Display an installed rpm List of configuration files provided by the package 
rpm -q package_name --whatrequires Displays the list of dependencies with an rpm package 
rpm -q package_name --whatprovides Displays the volume occupied by an rpm package 
rpm -q package_name --scripts Displays the installation/removal The script l rpm -q package_name --changelog executed during the period 
displays the modification history of an rpm package. 
rpm -qf /etc/httpd/conf/httpd.conf Confirm which rpm package the given file is provided by 
rpm -qp package.rpm -l Display a list of files provided by an rpm package that has not been installed 
rpm --import /media /cdrom/RPM-GPG-KEY Import public key digital certificate 
rpm --checksig package.rpm Confirm the integrity of an rpm package 
rpm -qa gpg-pubkey Confirm the integrity of all installed rpm packages 
rpm -V package_name Check file size , permission, type, owner, group, MD5 check and last modification time 
rpm -Va Check all installed rpm packages in the system - use 
rpm with caution -Vp package.rpm Confirm that an rpm package has not been installed 
rpm2cpio package.rpm | cpio --extract --make-directories *bin* Run the executable file 
rpm from an rpm package rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm Install a built package from an rpm source 
rpmbuild --rebuild package_name.src.rpm Build an rpm package from an rpm source code 

11. YUM software package upgrader-(Fedora, RedHat and similar systems) 


yum install package_name Download and install an rpm package 
yum localinstall package_name.rpm will install an rpm package and use your own software warehouse to resolve all dependencies for you 
yum update package_name.rpm Update all installed rpm packages in the current system 
yum update package_name update An rpm package 
yum remove package_name Delete an rpm package 
yum list List all packages installed in the current system 
yum search package_name Search for software packages in the rpm warehouse 
yum clean packages Clean the rpm cache Delete downloaded packages 
yum clean headers Delete all header files 
yum clean all deletes all cached packages and header files 

12. DEB package (Debian, Ubuntu and similar systems) 


dpkg -i package.deb Install/update a deb package 
dpkg -r package_name Delete a deb package from the system 
dpkg -l Display all installed deb packages in the system 
dpkg -l | grep httpd Display all names containing the word "httpd" deb package 
dpkg -s package_name Get information about a special package that has been installed in the system 
dpkg -L package_name Display the file list provided by a deb package that has been installed in the system 
dpkg --contents package.deb Display the file list provided by a package that has not yet been installed The file list 
dpkg -S /bin/ping confirms which deb package the given file is provided by 

13. APT software tools (Debian, Ubuntu and similar systems) 


apt-get install package_name Install/update a deb package 
apt-cdrom install package_name Install/update a deb package from CD 
apt-get update Upgrade a package in the list 
apt-get upgrade Upgrade all installed software 
apt-get remove package_name from The system deletes a deb package. 
apt-get check confirms that the dependent software repository is correct. 
apt-get clean cleans the cache from the downloaded software package. 
apt-cache search searched-package returns the name of the software package containing the search string. 

14. View file content 


cat file1 View the contents of a file in forward direction starting from the first byte 
tac file1 View the contents of a file in reverse direction starting from the last line 
more file1 View the contents of a long file 
less file1 Similar to the 'more' command, but it allows the contents of a file to be The same reverse operation as the forward operation 
head -2 file1 View the first two lines of a file 
tail -2 file1 View the last two lines of a file 
tail -f /var/log/messages View the content added to a file in real time 

15. 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 one The detailed description text of the file and write the introduction into a new file 
cat file1 | command(sed, grep, awk, grep, etc...) >> result.txt Merge the detailed description text of a file and write the introduction into it Into an existing file 
grep Aug /var/log/messages Search for the keyword "Aug" in the file '/var/log/messages' 
grep ^Aug /var/log/messages In the file '/var/log/messages' 'Find words starting with "Aug" 
grep [0-9] /var/log/messages Select all lines containing numbers in the file '/var/log/messages' 
grep Aug -R /var/log/* in the directory '/var/log' and subsequent directories are searched for the string "Aug" 
sed 's/stringa1/stringa2/g' example.txt will example. Replace "string1" in the txt file with "string2"
sed '/^$/d' example.txt Delete all blank lines from the example.txt file 
sed '/ *#/d; /^$/d' example.txt Remove all comments and blank lines from the example.txt file 
echo 'esempio' | tr '[:lower:]' '[:upper:]' merge The contents of the upper and lower cells 
sed -e '1d' result.txt Exclude the first line from the file example.txt 
sed -n '/stringa1/p' View the lines that only contain the word "string1" 
sed -e 's/ *$/ /' example.txt removes the last whitespace character in each line 
sed -e 's/stringa1//g' example.txt removes only the word "string1" from the document and retains all the remaining words 
sed -n '1,5p;5q' example .txt View content from line 1 to line 5 
sed -n '5p;5q' example.txt View line 5 
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' deletes all even-numbered lines in the example.txt file 
echo abc | awk '{print $1}' checks the first column of a line 
echo abc | awk '{print $1, $3}' View the first and third columns of a line
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, use "+" to distinguish them 
sort file1 file2 Sort the contents of two files 
sort file1 file2 | uniq Take out the union of two files (duplicate lines are only Keep one copy) 
sort file1 file2 | uniq -u deletes the intersection, leaving other lines 
sort file1 file2 | uniq -d removes the intersection of two files (leaving only files that exist in both files) 
comm -1 file1 file2 compares the contents of two files and only deletes the contents of 'file1' 
comm -2 file1 file2 compares the contents of two files and deletes only the contents of 'file2' 
comm -3 file1 file2 compares the contents of two files and deletes only both parts common to files 
 

16. Character settings and file format conversion 


dos2unix filedos.txt fileunix.txt Convert a text file format from MSDOS to UNIX 
unix2dos fileunix.txt filedos.txt Convert a text file format from UNIX to MSDOS 
recode ..HTML < page.txt > page.html Convert a Convert text file to html 
recode -l | more displays all allowed conversion formats 

17. File system analysis 


badblocks -v /dev/hda1 Check bad blocks on disk hda1 
fsck /dev/hda1 Repair/check the integrity of the linux file system on the hda1 disk 
fsck.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 the hda1 disk 
e2fsck -j /dev/hda1 Repair/check the integrity of the ext3 file system on the hda1 disk 
fsck.ext3 /dev/hda1 Repair/check the hda1 disk Integrity of the ext3 file system 
fsck.vfat /dev/hda1 Repair/check the integrity of the fat file system on the hda1 disk 
fsck.msdos /dev/hda1 Repair/check the integrity of the dos file system on the hda1 disk 
dosfsck /dev/hda1 Repair /Check the integrity of the dos file system on the hda1 disk 

18. Initialize a file system 


mkfs /dev/hda1 Create a file system in the hda1 partition 
mke2fs /dev/hda1 Create a linux ext2 file system in the hda1 partition 
mke2fs -j /dev/hda1 Create a linux ext3 (journaled) 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 creates a swap file system 

19. SWAP file system 


mkswap /dev/hda3 creates a swap file system 
swapon /dev/hda3 enables a new swap file system 
swapon /dev/hda2 /dev/hdb3 enables two swap partitions 

20. Backup 


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 Restore an interactive backup 
rsync -rogpav --delete /home /tmp Synchronize directories on both sides 
rsync -rogpav -e ssh --delete /home ip_address:/tmp rsync through SSH channel rsync 
-az -e ssh --delete ip_addr:/home/public /home/local Synchronize a remote directory to a local directory via ssh and compression 
rsync -az -e ssh --delete /home/local ip_addr:/home/public Synchronize a local directory via ssh and compression Directory synchronization to the remote directory 
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' Perform a backup of the local disk on the remote host through ssh dd if=/dev/ 
sda of=/tmp/file1 Back up the disk contents to a file 
tar -Puf backup.tar /home/user Perform an interactive backup operation of the '/home/user' directory 
( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' Copy the contents of a directory in the remote directory through ssh ( tar c /home ) | 
ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' Copy a local directory to the remote directory via ssh 
tar cf - . | (cd /tmp/backup ; tar xf - ) Copy a directory locally Go to another place, retain the original permissions and links 
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents Find and copy all files with Find files ending with '.txt' to another directory 
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 Find all files ending with '.log' file and make a bzip package 
dd if=/dev/hda of=/dev/fd0 bs=512 count=1 Make an action to 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 MBR contents from backup saved to floppy disk 

21. CD 


cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force Clear the contents of a rewritable disc 
mkisofs /dev/cdrom > cd.iso Create an iso image file of the disc on the disk 
mkisofs /dev/cdrom | gzip > cd_iso.gz Create a compressed CD iso image file on the disk 
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd Create a Directory's iso image file 
cdrecord -v dev=/dev/cdrom cd.iso Burn an ISO image file 
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - Burn a compressed ISO image file 
mount -o loop cd .iso /mnt/iso Mount an ISO image file 
cd-paranoia -B Rip audio tracks from a CD disc to a wav file 
cd-paranoia -- "-3" Rip audio tracks from a CD disc to a wav file (parameters -3) 
cdrecord --scanbus scans the bus to identify the scsi channel 
dd if=/dev/hdc | md5sum verifies the md5sum encoding of a device, such as a CD 
 

22. Network - (Ethernet and WIFI wireless


ifconfig eth0 Display the configuration of an Ethernet card 
ifup eth0 Enable an 'eth0' network device 
ifdown eth0 Disable an 'eth0' network device 
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 Control the IP address 
ifconfig eth0 promisc Set 'eth0' into promiscuous mode for sniffing Sniffing packets (sniffing) 
dhclient eth0 Enable 'eth0' in dhcp mode 

Guess you like

Origin blog.csdn.net/T19900/article/details/129543092