Linux basic commands

Source: Internet
Author: User
Tags parent directory touch command file permissions

1 Traversing a directory
Cd:change dicrectory abbreviation. Or./represents the current directory,.. Or.. /represents the previous table of contents, CD-Represents the last directory entered.
2 List of files and directories
Ls:list, the file under the directory is displayed. Usage: ls [-LAFR] [dir], where-F indicates the addition/representation of the directory after the table of contents,-R is recursive display.
3 Working with files 3.1 creating a file Touch

Command format:

Touch  [-ACDFMRT]  file

Command parameters:

-A or--time=atime or--time=access or--time=use only changes the access time-C or the--no-create does not establish any documents-D uses the specified datetime instead of the current time-F This parameter ignores the non-    Compatibility issues with BSD version touch directives-M  or--time=mtime or--time=modify only change the change time.    -R Sets the date and time of the specified document or directory to the same date and time as the reference document or directory. -T uses the specified date time instead of the current time

Command function:

Touch command parameter to change the date and time of a document or directory, including access time and change time

  

Examples of Use:

Instance:

       Touch text.py   # Create a nonexistent file    
       Touch A.log B.log  set up two log files at a time    
3.2 Copying Files CP

Command format:

CP [-IPRU] [File/dir]

Command parameters:

       -I before overwriting the file, ask the-p to retain the source file or directory properties, including the owner, group, permissions and time-r recursive processing, the specified directory of files and subdirectories are processed together, usually used as the replication directory-u Use this parameter, only after the source file modification time (modif Ication time) When the destination file is updated or the name does not exist for each other, the file is copied    

Command function:

CP can be used for copies of files or directories

Examples of Use:

[[email protected] data]# cp-p ett.xtx tte.txt   reserved file attribute copy and renamed to Tte.txt
3.3 Moving or renaming files mv

Command format:

MV [-bfiut] [File/dir]

Command parameters:

-F Force mandatory meaning, if the target file already exists, will not ask and directly overwrite-i if the destination file (destination) already exists, will ask whether to overwrite-u if the target file already exists, and the source is newer, the update (update)

Command function:

The MV command can be used to modify the name of a file or directory

Examples of Use:

[[Email protected] data]# mv Tte.txt changename.txt Modify Tte.txt's name
3.4 Deleting a file rm

Command format:

        RM [-IRF]  [File/dir]

Command parameters:

-I must first confirm-F Force Delete-R recursive delete before any delete operation

Command function:

RM is used to delete files, which are commonly used with find, which we'll talk about in the find usage.

Examples of Use:

[Email protected] data]# RM-FR test/
4 Working with Directory 4.1 creating a directory MkDir

Command format:

        mkdir [-MPV] [dir]    

Command parameters:

-m mode, specifying access permissions for the directory, similar to chmod-P if the directory already exists, there is no error message. If the parent directory does not exist, the parent directory will be created.    This option is commonly used to create cascading catalogs. -V displays a message for each directory

Command function:

Create a single directory or cascading directory.

Examples of Use:

[[email protected] data]# mkdir-p Blog/{bin,lib,var/{etc,doc,logfile}} [[email protected] data]# tree blog/blog/ ├──bin├──lib└──var├──doc├──etc└──logfile
4.2 Deleting a directory RmDir
By default, the RmDir command is used only to delete empty directories, and the deletion of non-empty directories requires RM-FR to be removed recursively, so the risk is very high, so it is commonly used in conjunction with find.
5 Viewing files 5.1 cat commands

Command format:

        Cat [-NBT] [file]

Command parameters:

-N adds line number to all lines-B only adds line number to text-T does not display tab, use ^i instead

Command function:

View entire file contents

  

5.2 more/less

Command function:

Page display, more convenient than cat.

  

5.3 Viewing some files

5.3.1 Tail command

Command parameters:

-N Displays the last number of rows of information

Command function:

Display Trailer XXX line information

Examples of Use:

[[email protected] data]# Tail-n 3 a.txt 18 19 20

5.3.2 Head Command

Command parameters:

With tail

Command function:

Show Header xxx line information

Examples of Use:

[[email protected] data]# head-n 3 a.txt 1 2 3
6 Find Lookup commands

Command format:

        

Command parameters:

-name finds files by file name. Find/data-name filename  finds the file named filename under the/data directory and its subdirectories find.-name "*.sh" in the current directory and its subdirectories (with "."          Find any file with the extension "sh"-perm follow the file permissions to find the file. Find.          -perm 755  Find files with file permission bit 755 in the current directory-prune Use this option to have the Find command not be found in the currently specified directory, and if the-depth option is used at the same time, then-prune will be ignored by the Find command. Find/apps-path "/apps/bin"-prune look for files in the/apps directory, but do not want to find/apps/bin in the-user directory find files by file owner finds ~-user root in $    Find files in home directory The owner of the file is Sam-group files to the group to find the file-mtime follow the file change time to find files + 7:7 days ago-7: Last seven days 7: Seventh Day     -type Find B-block device files by file type D-Directory C-character device file P-pipe file L-Symbolic link file F-normal file -size N:[c] Find files with a file length of n blocks, with C indicating the length of the file in bytes
Find and Xargs

When a matching file is processed using the-EXEC option of the Find command, the Find command passes all matching files to exec execution. However, some systems have a limit on the length of the command that can be passed to exec so that an overflow error occurs after the Find command runs for a few minutes. The error message is usually "parameter column too Long" or "parameter column overflow". This is where the Xargs command is used, especially with the Find command.

The find command passes the matched file to the Xargs command, and the Xargs command takes only a subset of the files at a time instead of all, unlike the-exec option. This allows it to first process a portion of the file that was first fetched, then the next batch, and so on.

In some systems, the use of the-EXEC option initiates a corresponding process for processing each matching file, not all of the matching files are executed once as parameters, so that in some cases, there are too many processes and degraded system performance, so the efficiency is not high , while using the Xargs command, there is only one process. In addition, when using the Xargs command, whether to get all the parameters at once, or to obtain the parameters in batches, and each time the number of parameters obtained will be based on the options of the command and the corresponding tunable parameters in the system kernel to determine

find delete [[email protected] home]# find. -type f-name "*.txt" | Xargs rm-f (Recommended delete) find+sed [[email protected] data]# find. -type f-name "*.sh" | Xargs sed ' s/oldboy/oldgirl/g '

  

Linux basic commands

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.