CentOS common file operation commands and centos commands
Summary of common CentOS file operation commands
I can say that I am a newbie in linux, and I often forget some commands, especially some operations on files. I often need to read the previous notes, today, I posted the "common file operation commands for CentOS" compiled on Baidu to my new blog for later reference!
The blog will also summarize some articles on php, mysql, and apache in linux. Please stay tuned! (A new blog forum is being built recently .. When building the php environment later, I will summarize the article on the blog)
The following are some common commands for linux and CentOS:
Cd pwd
NO1. display current path
[root@rehat root]# pwd
NO2. return the user's home directory
[root@rehat root]# cd
NO3. change to another path
[root@rehat root]# cd /etc
NO4. return to the upper-level directory
[root@rehat root]# cd ..
NO5. return to the root directory
[root@rehat root]# cd /
Common CentOS command to query files or folders find
NO1. search for all files in the current user's home directory
[root@rehat root]# find ~
NO2. grant the file owner in the current directory read and write permissions, and the users in the file group and other users have read permissions;
[root@rehat root]# find . -perm 644 -exec ls -l {} \;
NO3. in order to find all common files with a length of 0 in the system and list their full paths;
[root@rehat root]# find / size 0 -type f -exec ls -l {} \;
NO4. search for common files that were modified seven days ago in the/var/logs directory and ask them before deletion;
[root@rehat root]# find /var/logs -mtime +7 -type f -ok rm -i {} \;
NO5. find all files belonging to the root group in the system;
[root@rehat root]# find / -group root -exec ls -l {} \;
The NO6. find command will delete the admin. log file that contains the numeric suffix since the last seven days.
[root@rehat root]# find . -name "admin.log[0-9][0-9][0-9]" -atime -7 -ok rm { } \;
NO7. to find and sort all directories in the current File System
[root@rehat root]# find . -type d | sort
NO8. to find all rmt tape devices in the system
[root@rehat root]# find /dev/rmt
Common CentOS commands for displaying file/folder lists ls/dir
NO1. display all files, including hidden files starting.
[root@rehat root]# ls -a
NO2. display file details
[root@rehat root]# ls -l
NO3. display information about the current directory and all subdirectories
[root@rehat root]# ls -Rl
NO4. display directories in chronological order, which is useful for finding the latest file
[root@rehat root]# ls -tl
NO5. sort by file size
[root@rehat root]# ls -Sl
NO6. display the file size and sort by size
[root@rehat root]# ls -s -l -S
Common CentOS commands for moving or changing file/folder names are similar to cp commands.
NO1. if the target file already exists, back up the original directory file before moving it.
[root@rehat root]# mv -b test.txt test2/
In this way, there will be two test.txt and text.txt ~ files under test2 ~
Test.txt ~ Is the hosts file. test.txt is the new file.
NO2. if the target object already exists but you do not want to overwrite it
[root@rehat root]# mv -f test.txt test2/
NO3. when both the source and target have the same file, if the source file matches the new object, the object will be moved; otherwise, the object will not be moved.
[root@rehat root]# mv -u test.txt test2/
NO4. change file name
[root@rehat root]# mv test.txt test2.txt
NO5. change the directory name
[root@rehat root]# mv /test2 /test2_2[/size]
Common CentOS commands for creating/changing file systems
NO1. create a file system type
[root@rehat root]# umount /dev/sdb1 [root@rehat root]# mkfs -t ext3 /dev/db1 [root@rehat root]# mount /dev/sdb1 /practice
Common CentOS command for changing file or folder permissions chmod
NO1. set your notes to be read only by yourself.
[Root @ rehat root] # chmod go-rwx test.txt or [root @ rehat root] # chmod 700 test.txt
NO2. Modify permissions for multiple files at the same time
[root@rehat root]# chmod 700 test1.txt test2.txt
NO3. modify the permissions of a directory, including its subdirectories and files
[root@rehat root]# chmod 700 -R test
Common CentOS commands used to change the file or folder owner
Chown this command can only be used by the root user
NO1. change the owner of a file
[root@rehat root]# chown jim:usergroup test.txt
NO2. change the owner of a directory and contain sub-Directories
[root@rehat root]# chown jim:usergroup -R test
Common CentOS commands for viewing text file content cat
NO1. view the file content and add a line number before each line
[root@rehat root]# cat -n test.txt
NO2. view the file content and add the row number before the non-empty row
[root@rehat root]# cat -b test.txt
NO3. merge the content of two files
[root@rehat root]# cat test1.txt test2.txt > test_new.txt
NO4. complete the content of the two files and trace back to a file
[root@rehat root]# cat test1.txt test2.txt >> test_total.txt
NO5. clear the content of a file
[root@rehat root]# cat /dev/null > test.txt
NO6. create a new file
[Root @ rehat root] # cat> new.txt press CTRL + C to end the input
Common CentOS commands for editing file files vi
NO1. create a file
[root@rehat root]# vi newfile.txt
NO2. modify an archive file
[Root @ rehat root] # vi test.txt already exists
Two working modes of NO3. vi: Command mode and edit mode
NO4. after entering vi, it is in command mode. Press the Insrt key to enter edit mode.
Press ESC to enter the command mode. You cannot edit the command mode. You can only enter the command
NO5. Common commands in command mode
: W Save the current document: q directly exit vi: wq first save and then exit. : Q! Force exit without saving
Common CentOS command mkdir for creating a directory
NO1. create a level-1 directory in the current path
[root@rehat root]# mkdir test
NO2. create a multi-level directory in the current path
[root@rehat root]# mkdir -p mytest/test1/test1_1
NO3. grant permissions to the newly created directory while creating the Directory
[root@rehat root]# mkdir -m 777 testmod
In this way, anyone has any permission for this directory.
Common CentOS commands for copying files and folders cp
NO1. copy the files in the specified directory to the current directory and rename
[root@rehat root]# cp ~/.bashrc bashrc_bak
NO2. force copy the file from the specified directory to the current directory, regardless of whether the current directory contains the file
[root@rehat root]# cp -f ~/.bashrc bashrc
NO2. copy the specified directory to the current directory
[root@rehat root]# cp -r /root/test . [root@rehat root]# cp -r /root/test/ .
The two have the same effect. When copying a directory, all the last-level directories in the source path will be copied, including the directory itself.
NO3. copy files from the specified directory to the specified directory
[root@rehat root]# cp ~/.bashrc /bak/.bashrc
NO4. during replication, all the attributes of the source file are also copied. If no parameter is specified, the properties of the target file and the source file may be inconsistent.
[root@rehat root]# cp -a ~/.bashrc /bak/.bashrc
NO5. if two folders need to be synchronized, one file is changed and the other file is changed, but ensure that the files of both files are up-to-date.
[root@rehat root]# cp -u /src/.bashrc /bak_src/bashrc
Create a link file, including the common CentOS command ln for hard and soft links
NO1. create a shortcut similar to Windows
[root@rehat root]# ln -s test.txt test.txt_slnk
NO2. if you want to back up a file with insufficient space, you can create a hard connection for the file. In this way, even if the original file is deleted, as long as the linked file is not deleted, it is still not deleted in the bucket.
[root@rehat root]# ln -l test.txt test.txt_hlnk
View cpu using common CentOS commands
more /proc/cpuinfo | grep "model name" grep "model name" /proc/cpuinfo [root@localhost /]# grep "CPU" /proc/cpuinfo model name : Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz model name : Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz
If you feel more comfortable to watch
grep "model name" /proc/cpuinfo | cut -f2 -d:
View memory using common CentOS commands
grep MemTotal /proc/meminfo grep MemTotal /proc/meminfo | cut -f2 -d: free -m |grep "Mem" | awk '{print $2}'
Use common CentOS commands to check whether the cpu is 32-bit or 64-bit (32 or 64)
getconf LONG_BIT
Use common CentOS commands to view the current linux version
more /etc/redhat-releasecat /etc/redhat-release
Use common CentOS commands to view the kernel version
uname -runame -a
Use common CentOS commands to view the current time
Date. The preceding section describes how to synchronize the time.
Use common CentOS commands to view hard disks and partitions
df -hfdisk -l
You can also view partitions.
du -sh
The occupied space is displayed.
du /etc -sh
The directory size is displayed.
Use common CentOS commands to view installed software packages and the software packages installed during system installation.
cat -n /root/install.logmore /root/install.log | wc -l
Check the software packages that have been installed.
rpm -qarpm -qa | wc -lyum list installed | wc -l
But it is strange that the number of installation packages I query through rpm and yum is not the same. No reason is found.
View the keyboard layout using common CentOS commands
cat /etc/sysconfig/keyboardcat /etc/sysconfig/keyboard | grep KEYTABLE | cut -f2 -d=
Use common CentOS commands to view selinux Information
sestatussestatus | cut -f2 -d:cat /etc/sysconfig/selinux
Use common CentOS commands to view ip addresses and mac addresses
In the ifcfg-eth0 file you can see mac, Gateway and other information.
ifconfig cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep IPADDR | cut -f2 -d= ifconfig eth0 |grep "inet addr:" |awk '{print $2}'|cut -c 6- ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'
View Gateway
cat /etc/sysconfig/network
View dns
cat /etc/resolv.conf
Use common CentOS commands to view the default language
echo $LANG $LANGUAGEcat /etc/sysconfig/i18n
Use common CentOS commands to check the time zone and whether UTC time is used
cat /etc/sysconfig/clock
View the host name using common CentOS commands
hostnamecat /etc/sysconfig/network
Modifying the host name is to modify this file, and it is recommended that you also modify the host file.
Use common CentOS commands to view the startup time
uptime09:44:45 up 67 days, 23:32, ...
It seems that this is indeed a problem with the network segment. I started the machine 67 days ago.
System resource usage
vmstat 1 -S m procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 233 199 778 0 0 4 25 1 1 3 0 96 0 0 0 0 0 233 199 778 0 0 0 0 1029 856 13 1 86 0 0
Common CentOS commands for file deletion rm
NO1. delete files in the current directory
[root@rehat root]# rm test.txt
NO2. force delete the file in the current directory. No prompt is displayed.
[root@rehat root]# rm -f test.txt
NO3. force Delete the entire directory, including deleting all directories and files. administrator permissions are required.
[root@rehat root]# rm -r -f test
Common CentOS commands used to delete folders: rmdir
NO1. delete an empty directory
[root@rehat root]# rmdir emptydir
NO2. delete a multi-level empty directory
[root@rehat root]# rmdir -p emptydir/d1/d11
Common commands for mounting a file system and detaching a file system using CentOS
Mount/umount
NO1. mount the optical drive
[root@rehat root]# mount -t iso9660 /dev/cdrom /mnt/cdrom
NO2. mount the optical drive, supporting Chinese Characters
[root@rehat root]# mount -t iso9660 -o codepage=936,iocharset=cp936 /dev/cdrom /mnt/cdrom
NO3. mount Windows partition and FAT file system
[root@rehat root]# mount -t vfat /dev/hda3 /mnt/cdrom
NO4. mount Windows partition, NTFS file system
[root@rehat root]# mount -t ntfs -o iocharset=cp936 /dev/hda7 /mnt/had7
No5. mount the ISO file
[root@rehat root]# mount -o loop /abc.iso /mnt/cdrom
NO6. attach a soft drive
[root@rehat root]# mount /dev/fd0 /mnt/floppy
NO7. mount a flash disk
[root@rehat root]# mount /dev/sda1 /mnt/cdrom
NO8. mount a folder shared by the Windows operating system
[root@rehat root]# mount -t smbfs -o username=guest,password=guest //machine/path /mnt/cdrom
NO9. display mounted file systems
[Root @ rehat root] # mount [root @ rehat root] # cat/etc/fstab shows the file system automatically loaded when the system starts [root @ rehat root] # cat/etc/mtab display the currently Loaded File System