Linux partial file operation command usage summary

  
 

This is a list of things that I didn't know before, but I have ignored them.

locate——Find files

Usage: locate zh_CN List all included “zh_CN” String files and directories. Since the locate command searches for a file from a database that saves files and directory names in the system, although the system periodically updates the database, files or directories that have just been added or deleted may still be inaccessible because the database has not been updated. You can run the updatedb command update as root, and the contents of this database are correct.

grep——search string ****

The grep command can search for specific strings and display them. It is generally used to filter previous results and avoid displaying too many unnecessary ones. information. An example is as follows: grep text .conf //Search for files with the extension .conf in the current directory and containing the string of text & rdquo;. If you are running with a user with general privileges, the output of the above example will contain a lot of error messages such as "rejecting non-conforming operations", which can be eliminated with the -s parameter. Grep –s text
.conf

tar——package file

Parameter description:

-c:Create a new tar file;-v: Display operation process information; -f: in: specify the file name; -z: call gzip compression command to perform compression; -j: call bzip2 compression command to perform compression; -t: see compressed file content; -x: unpack tar file. 

Common usage:

tar cvf data.tar * ← Package all files in the directory into data.tartar cvf data.tar.gz * ← Package all files in the directory into data.tar and use Gzip command to compress tar tvf data.tar * ← Check which files are included in the data.tar file tar xvf data.tar * ← unpack data.tar 

find—— find files

Syntax: find path options [-exec command {} \\;]

Parameter Description:

-name ’String & rsquo; Find all files whose filename matches the given string, word The wildcard characters *, ?, [ ] are available in the string. -lname & rsquo;String & rsquo; Finds all symlink files whose filename matches the given string. The wildcards *, ?, [ ] are available in the string. -gid n Finds all files belonging to the user group with ID number n. -uid n Finds all files belonging to a user with ID number n. -group ’String & rsquo; Find all files belonging to the user group named string. -user ’String & rsquo; Find all files belonging to the user name given by the string. -empty Finds a directory or file of size 0. -path ’String & rsquo; Find all files whose path name matches the given string. The wildcard characters *, ?, [ ] are available in the string. -perm +/-mode Finds files and directories with the specified permissions, which can be represented as 711,644. - Explain that all 1 bits of the mode must match, and + indicates that the mode can be matched as long as there is one. -size n[bckw] Finds the file of the specified file size. The characters after n represent the unit. The default is b, which represents a block of 512 bytes. -type x finds a file of type x, x is one of the following characters:

b block device file c character device file d directory file p named pipe (FIFO) f normal file l symbolic link file (symbolic links )s socket file

-xtype x is basically the same as -type, but only looks for symbolic link files.

Search by time:

-amin n Find all files that have been accessed n minutes ago. -atime n Find all files that have been accessed n days ago. -cmin n Finds all files whose file status has been modified n minutes ago. -ctime n Finds all files whose file status has been modified n days ago. -mmin n Finds all files whose file contents have been modified n minutes ago. -mtime n Finds all files whose contents have been modified n days ago. -print: Outputs search results to standard output.

Example:

1. In root and subdirectory lookup does not include directory /root/bin, greek user, file type is ordinary file, named test- 3 days ago Find.c file, and output the structure, find command is as follows:

find /-name "test-find.c" -type f -mtime +3 -user greek -prune /root/bin - Print

2. Find all files in the current directory that start with main and display the contents of these files:

find . - name ‘main*’ - exec more {} \\;

3. Delete all a.out or *.o files that have not been accessed in the current directory for all weeks:

find . (- name a.out - o - name ‘ *.o’)> - atime +7 - exec rm {} \\;

Note:

1. The “.” in the command indicates the current directory, at which point find Starting from the current directory, find files in their subdirectories one by one that meet the conditions specified later. 2.“\\(” and “\\)” means parentheses (), where “\\” is called an escape character. The reason for this is that for the Shell, (and) has a different meaning, not the purpose for combining conditions here. 3. The last \\ in the first line of the above command is a continuation character. When the command is too long to write in one line, you can enter a \\ and the system will display a > to instruct the user to continue entering the command.

Detailed parsing: use of Find command in linux


scp——file copy between Linux

Linux scp command for Linux Copying files and directories from local to remote, from remote to local is two ways to use it.

1. Copy from local to remote

(1) Copy files:

scp local_file remote_username@remote_ip:remote_folderscp local_file remote_username@remote_ip:remote_filescp local_file remote_ip:remote_folderscp local_file remote_ip :remote_file Note: The first and second specify the user name. After the command is executed, the password needs to be entered again. The first one only specifies the remote directory, the file name does not change, the second specifies the file name; the third and fourth No user name is specified, the user name and password are required after the command is executed, the third directory only specifies the remote directory, the file name is unchanged, and the fourth file name is specified. 

Examples (corresponding to the above):

scp /home/space/music/1.mp3 [email protected]:/home/root/others/musicscp /home/space /music/1.mp3 [email protected]:/home/root/others/music/001.mp3scp /home/space/music/1.mp3 www.cumt.edu.cn:/home/root /others/musicscp /home/space/music/1.mp3 www.cumt.edu.cn:/home/root/others/music/001.mp3

(2) Copy directory:

scp -r local_folder remote_username@remote_ip:remote_folderscp -r local_folder remote_ip:remote_folder Note: The first user name is specified, the password needs to be entered after the command is executed; the second user name is not specified, and the user name and password are required after the command is executed; p> example (corresponding to the above): 
scp -r /home/space/music/[email protected]:/home/root/others/scp -r /home/space /music/www.cumt.edu.cn:/home/root/others/

2, copy from remote to local

as long as the last two parameters of the command copied from the local to the remote are changed. You can:

scp [email protected]:/home/root/others/music /home/space/music/1.mp3scp -r www.cumt.edu.cn:/home/root/others//home/space/music/
Copyright © Windows knowledge All Rights Reserved