[Cygwin] common cygwin commands and find commands

Source: Internet
Author: User
Cygwin is a software used to simulate the Linux environment on Windows.

With cygwin, you can use Linux programs in a Windows environment. tools such as find and tar can also be used in windows, so that you can conveniently manage files.

I. Some common problems in cygwin:
1. FAQs;
A. drive letter problems;
In the cygwin command line, "/cygdrive/C" is equivalent to "C :/".
B. Change the default cygwin path;
Create an environment variable "home". The variable value is the default path when cygwin is enabled (for example, set it to "/cygdrive/D ").

2. Common commands;
PWD displays the current path
Cygpath-DM "'pwd'" shows the current full path (that is, the path in Windows format)
CD changes the current path. If no parameter exists, enter the home directory of the corresponding user.
Ls to list files in the current directory. This command has n multiple parameters, such as LS-Al
PS: list the current system process
Kill to kill a process
Create a directory using mkdir
Rmdir Delete directory
Rm delete file
Renamed the MV file or directory
Man online help
Less: displays the last few lines of a file.

-----------------------

Ls # display the current directory file list by default
Ls-A # Show all files, including hidden files
Ls-L # display file attributes, including size, date, symbolic connection, read/write, and executable
Ls-color = never *. So> OBJ # The text color is not displayed, and all so files are recorded in the OBJ file.

-----------------------

CD dir # Switch to the Dir directory under the current directory
CD .. # Switch to the upper-level directory
CD.../... # Switch to the upper-level directory
Cd ~ # Switch to the user directory. For example, if it is a root user, switch to/root.

-----------------------
RM file # delete an object
Rm-fr dir # Delete the entire directory named dir in the current directory

-----------------------
CP source target # copy the file source to target
CP/root/source. # copy the file source under/root to the current directory.
CP-AV soure_dir target_dir # copy the entire directory. The two directories are identical.
CP-fr source_dir target_dir # copies the entire directory in non-link mode. When the source directory contains symbolic links, the two directories are different.

-----------------------
MV source target # rename the file source to target

-----------------------

2. Example of the find command;
1. Find all. java files whose modification date is closer to your test. Java file in the current directory and subdirectory;
Find.-Name '*. Java'-newer test. Java-print

2. Find all the Java code you modified today in the current directory and subdirectory;
Find.-Name '*. Java'-mtime 0-print

3. Which AWT libraries are used in the above files;
Find.-Name '*. Java'-mtime 0-print | xargs grep 'java. awt'

4. Find all files except the "C:/Windows" folder under "C :/".
Find/cygdrive/C-path "/cygdrive/C/Windows"-prune-o-print

5. Find all the files ending with ". Jar" in the above file.
Find/cygdrive/C-path "/cygdrive/C/Windows"-prune-o-name "*. Jar"-print

6. Find the ". Class" file under the current src directory and delete them;
Find Src-name '*. class' | xargs RM
PS: before deleting the file, you 'd better check the file to confirm the find Src-name '*. class' | xargs LS-l

7. Delete All ". SVN" folders under the current src directory;
Find Src-name '. SVN' | xargs Rm-R


III,
Find command Description :-----------Link: SEARCH Command find, xargs details------------
1. The common form of the find command is;

find pathname -options [-print -exec -ok ...]


2. Parameters of the find command;

Pathname:Find command to find the directory path. For example, use "." To represent the current directory, and use "/" to represent the root directory of the system.
-Print:
The find command outputs matching files to the standard output.
-Exec:
The find command executes the shell command given by this parameter on the matching file. The corresponding command is in the form of 'command' {} ";, note the space between {} and.
-OK:
The role of-exec is the same as that of-exec, but the shell command given by this parameter is executed in a safer mode. A prompt is displayed before each command is executed, let the user determine whether to execute.


3. Find Command Options

-Name

Search for files by file name.

-Perm
Find the file according to the file permission.

-Prune
This option can make the find command not to be searched in the specified directory. If the-depth option is used at the same time,-prune will be ignored by the find command.

-User
Search for files by file owner.

-Group
Find the file according to the file group.

-Mtime-N + n
Find the file according to the file change time.-N indicates that the file change time is less than N days from now, and + N indicates that the file change time is earlier than N days from now. The find command also has the-atime and-ctime options, but they both have the-M time options.

-Nogroup
Find the file with no valid group, that is, the group to which the file belongs does not exist in/etc/groups.

-Nouser
Find a file without a valid owner, that is, the owner of the file does not exist in/etc/passwd.

-Newer file1! File2
Find the file whose modification time is newer than file1 but earlier than file2.

-Type
Find a type of file, such:
B-
Block device files.
D-
Directory.
C-
Character device file.
P-
MPs queue file.
L-
Symbolic Link file.
F-
Common file.

-Size N: [c]Search for files with a length of N blocks. If a file contains C, the file length is measured in bytes.
-Depth:
When searching for a file, first find the file in the current directory and then find it in its subdirectory.
-Fstype:
Search for files in a certain type of file system. These file system types can be found in the configuration file/etc/fstab, this configuration file contains information about the file system in the system.

-Mount:
When searching for a file, it does not span the mount point of the file system.
-Follow:
If the find command encounters a symbolic link file, it will trace the file to which the link points.
-Cpio:
Use the cpio command to back up the files to the tape device.

In addition, the following three differences:

-Amin n
Find the files accessed in the last n minutes of the system

-Atime n
Find the last n * 24 hours of files in the system

-Cmin n
Find the file whose status is changed in the last n minutes in the system

-Ctime n
Find the file whose status is changed in the last n * 24 hours in the system.

-Mmin n
Find the file whose data is changed in the last n minutes in the system

-Mtime n
Find the file whose data has been changed for the last n * 24 hours in the system.
Http://www.blogjava.net/Man/archive/2010/08/11/328574.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.