linux for file operation command set - turn

2011-04-01  来源:本站原创  分类:OS  人气:113 

Original Address:

1 Create a directory


NO1. Create a directory in the current path

[Root @ rehat root] # mkdir test

NO2. In the current directory path to create multi-level

[Root @ rehat root] # mkdir-p mytest/test1/test1_1

NO3. Create a new directory at the same time to assign permissions to the directory

[Root @ rehat root] # mkdir-m 777 testmod

So that no one has any rights to this directory

(2) copy files and folders


NO1. Copy the files to the specified directory the current directory, and rename

[Root @ rehat root] # cp ~ /. Bashrc bashrc_bak

NO2. Mandatory copy the files to the specified directory the current directory, regardless of whether the current directory containing 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 /.

Both effects, as in replication directory, the last level of the source directory path all the copy in the past, including itself.

NO3. Copy the file specified directory to the specified directory

[Root @ rehat root] # cp ~ /. Bashrc / bak / .bashrc

NO4. When copying all the properties of the source file is also copied. If not specified, the target file and source file properties may be inconsistent.

[Root @ rehat root] # cp-a ~ /. Bashrc / bak / .bashrc

NO5. If the two folders to ensure synchronization, a file change, the change also followed another file, but to ensure that two files are up to date.

[Root @ rehat root] # cp-u / src / .bashrc / bak_src / bashrc

3 to link documents, including hard links and soft links


NO1. The establishment of similar to Windows shortcuts

[Root @ rehat root] # ln-s test.txt test.txt_slnk

NO2. When you want to back up a file, but the space is not enough, you can create a hard link for the file. Thus, even if the original file is deleted, as long as the

Link file is not deleted, the storage space is not deleted.

[Root @ rehat root] # ln-l test.txt test.txt_hlnk

4 Delete the file


NO1. Delete the current directory files

[Root @ rehat root] # rm test.txt

NO2. Forced to delete the current directory of the file, not the pop-up tips

[Root @ rehat root] # rm-f test.txt

NO3. Forcibly remove the entire directory, including directory and delete all the files, you need administrator rights

[Root @ rehat root] # rm-r-f test

rm [options] [list of files and directories]

Table 4-5 shows commonly used options.

Table 4-5 rm command is commonly used options

Meaning of commonly used options
Forcibly remove the specified mode. Typically, delete the file permissions will be prompted to meet the rm. Forced to remove the sign, without prompting, on acid-i flag is also used when processing invalid
Prompted to delete files
Delete the file directory specified in the list, if not delete the directory without the logo
Recursive directory delete, delete all the subdirectories of the directory machine
Echo the file name before deleting
The end of all the options specified. Language delete a file name and an option to the same file. For example: Suppose accidentally created a file called-f, also intends to remove it, the command rm-f has no effect, because-f is interpreted as a sign rather than the file name; the rm command can delete files successfully

By default, rm will remove the specified file, but can not remove a directory, but when given the-r or-R option, the specified directory under the directory tree will be removed (and through " rm-r "to remove the tree depth is no limit).

Note that when only part of the end of the file path "." And "..", the command execution error.

Rm command can also delete multiple files to delete files and directory listings can be separated by spaces.

5. Delete a folder


NO1. Delete an empty directory

[Root @ rehat root] # rmdir emptydir

NO2. Delete empty directories multi-level

[Root @ rehat root] # rmdir-p emptydir/d1/d11

6 Mount the file system and unmount the file system

mount / umount

NO1. Mount drive

[Root @ rehat root] # mount-t iso9660 / dev / cdrom / mnt / cdrom

NO2. Mounted drive, support for Chinese

[Root @ rehat root] # mount-t iso9660-o codepage = 936, iocharset = cp936 / dev / cdrom / mnt / cdrom

NO3. Mount the Windows partition, FAT file system

[Root @ rehat root] # mount-t vfat / dev/hda3 / mnt / cdrom

NO4. Mount the Windows partition, NTFS File System

[Root @ rehat root] # mount-t ntfs-o iocharset = cp936 / dev/hda7 / mnt/had7

No5. Mount ISO file

[Root @ rehat root] # mount-o loop / abc.iso / mnt / cdrom

NO6. Mount floppy drive

[Root @ rehat root] # mount / dev/fd0 / mnt / floppy

NO7. Mount flash drive

[Root @ rehat root] # mount / dev/sda1 / mnt / cdrom

NO8. Windows operating system to mount the shared folder

[Root @ rehat root] # mount-t smbfs-o username = guest, password = guest / / machine / path / mnt / cdrom

NO9. Show mounted file system

[Root @ rehat root] # mount

[Root @ rehat root] # cat / etc / fstab show boot auto-mounted file systems

[Root @ rehat root] # cat / etc / mtab shows the currently loaded file system

7 Check disk space


NO1. Shows all storage space usage, and display the type of file system storage system s

[Root @ rehat root] # df-aT

NO2. Displays the file system space usage

[Root @ rehat root] # df-t ext3

NO3. User-friendly display of storage space

[Root @ rehat root] # df-ah

NO4. Sometimes mount a network file system, if we only want to see the local file system with the following command

[Root @ rehat root] # df-ahlT

NO5. View a file system disk usage

[Root @ rehat root] # df-h / dev / cdrom

8 Check that the directory space


NO1. See the size of the current folder

[Root @ rehat root] # du-sh

NO2. View the current file and the file size contained in subfolders

[Root @ rehat root] # du-ch

NO3. Check file size

[Root @ rehat root] # du-h test1.txt

NO4. View multiple file size

[Root @ rehat root] # du-h test1.txt test2.txt

9. Disk Defragmenter

Basically, do not defrag under linux, it will automatically organize from time to time

10 Creating / changing the file system

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

11 to change the file or folder permissions


NO1. Make your own notes to see only their own

[Root @ rehat root] # chmod go-rwx test.txt


[Root @ rehat root] # chmod 700 test.txt

NO2. Permissions to edit multiple files

[Root @ rehat root] # chmod 700 test1.txt test2.txt

NO3. To modify a directory of rights, including its subdirectories and files

[Root @ rehat root] # chmod 700-R test

12 to change the file or folder owner

chown only root can use the command

NO1. Change a file's owner

[Root @ rehat root] # chown jim: usergroup test.txt

NO2. To change the owner of a directory, and contains subdirectories

[Root @ rehat root] # chown jim: usergroup-R test

13. View the contents of a text file


NO1. Look at the file, and in front of each line with line number

[Root @ rehat root] # cat-n test.txt

NO2. Look at the file, not the air in front of the line with line number

[Root @ rehat root] # cat-b test.txt

NO3. Merge the contents of two files

[Root @ rehat root] # cat test1.txt test2.txt> test_new.txt

NO4. And two full contents of the file, and recover to a file

[Root @ rehat root] # cat test1.txt test2.txt>> test_total.txt

NO5. Empty the contents 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 end of the entry

14. Edit file files


NO1. Create a new archive

[Root @ rehat root] # vi newfile.txt

NO2. Modify archives

[Root @ rehat root] # vi test.txt test.txt already exists

NO3. Vi of two modes: command mode, edit mode

NO4. After entering vi command mode, press the button to enter edit mode Insrt

Press ESC to enter command mode, command mode can not be edited, only enter the command

NO5. Command mode commonly used commands

: W save current document

: Q to exit vi

: Wq save and exit first

15 path operations

cd pwd

NO1. Display the current path

[Root @ rehat root] # pwd

NO2. Back to the user's home directory

[Root @ rehat root] # cd

NO3. To change to another path

[Root @ rehat root] # cd / etc

NO4. Back to the parent directory

[Root @ rehat root] # cd ..

NO5. Back to the root directory

[Root @ rehat root] # cd /

16. Check file or folder


NO1. Find the current user's home directory all files

[Root @ rehat root] # find ~

NO2. So that the current directory the file owner has read, write permissions, and the file belongs to the group and other users have read access to files;

[Root @ rehat root] # find.-Perm 644-exec ls-l {} \;

NO3. In order to find all the files in the system's normal file length of 0, and list the full path;

[Root @ rehat root] # find / size 0-type f-exec ls-l {} \;

NO4. Find / var / logs directory, change the time 7 days before the general file and ask before deleting them;

[Root @ rehat root] # find / var / logs-mtime +7-type f-ok rm-i {} \;

NO5. For / to find all the system files belong to root group;

[Root @ rehat root] # find /-group root-exec ls-l {} \;

NO6. Find command will be deleted when the directory access time in seven days since the file contains a number suffix admin.log

[Root @ rehat root] # find.-Name "admin.log [0-9] [0-9] [0-9]"-atime -7-ok rm {} \;

NO7. To find the current file system directory and sort all

[Root @ rehat root] # find.-Type d | sort

NO8. In order to find all of the rmt tape system devices

[Root @ rehat root] # find / dev / rmt

17 display the file / folder list

ls / dir

NO1. Show all files, including. At the beginning of the hidden files

[Root @ rehat root] # ls-a

NO2. Display file details

[Root @ rehat root] # ls-l

NO3. Displays the current directory and all subdirectories Information

[Root @ rehat root] # ls-Rl

NO4. Sort of time show catalog, which is useful to find the latest file

[Root @ rehat root] # ls-tl

NO5. To sort file size

[Root @ rehat root] # ls-Sl

NO6. Displays the file size, sort according to size

[Root @ rehat root] # ls-s-l-S

18. Move or change the file / folder name

mv and cp commands use similar

NO1. If you move the target file already exists, to move before you back up the original catalog file

[Root @ rehat root] # mv-b test.txt test2 /

This will have two under the test2 file test.txt and text.txt ~

One test.txt ~ is a backup file, test.txt is a new file

NO2. If you move the target file already exists, but do not want to overwrite the pop-up prompts, direct coverage

[Root @ rehat root] # mv-f test.txt test2 /

NO3. When the source and target have the same file, if the new source file than the target is moving, or does not move

[Root @ rehat root] # mv-u test.txt test2 /

NO4. Change the file name

[Root @ rehat root] # mv test.txt test2.txt

NO5. Change the directory name

[Root @ rehat root] # mv / test2 / test2_2

19.gzip compressed file

gzip command for compressing files. The command format is commonly used command options are as follows:

# Gzip [options] [list of files and directories]
Common options
Extract the compressed files
For each compressed file, compressed file shows the size of the uncompressed file size, compression ratio and uncompressed file name and other details
Recursively to find the specified directory and compress all the files compressed or three solutions
Test to check whether the compressed file integrity
For each compression and decompression of files, file name and compression ratio

For example, if you want to ye.txt file compression, used the following command:

[Root @ localhost root] # gzip ye, txt

This can compact the file and the file name followed by the gz extension into the file ye.txt.gz.

Unzip the file gzip-d command can be used to achieve:

[Root @ localhost root] # gzip-d ye.txt.gz

This will decompress the file and delete the gz extension. In addition you can also use the gunzip command to unzip the file, with the effect of using gzip-d command.

20. Tar files are packaged

tar command was originally used to create a tape backup system is widely used to package files. The command format is commonly used command options are as follows:

# Tar [options] [list of files and directories]
For example, if you want in the current directory suffix ". C" of files into cfile.tar file can be used the following command:
[Root @ localhost root] # tar-cvf cfile.tar * c
If you want to browse cfile.tar contents of the document, c option can be turned into t, use the following command:
To remove the contents of the document, the c option into x. If you want to cfile.tar The contents of the document to the directory "/ root / sl", the following commands available:
[Root @ localhost root] # tar-xvf cfile.tar-C/root/sl
Previous versions of tar command does not compress the document, available gzip compression. Direct access to the new version of tar and gzip compressed tar archives and build, as long as the tar command with-z option on it. For example:
[Root @ localhost root] # tar-czvf txtfile.tar.gz *. txt
Generate compressed document txtfile.tar.gz.
[Root @ localhost root] # tar-xzvf txtfile.tar.gz .*. txt
Show archive txtfile.tar.gz
[Root @ localhost root] # tar-xzvf txtfile.tar.gz .*. txt
The command is executed, it will remove the archive ye.tar.gz contains content.

  • linux for file operation command set - turn 2011-04-01

    Original Address: 1 Create a directory mkdir NO1. Create a directory in the current path [Root @ rehat root] # mkdir test NO2. In the current directory path to create multi-level [Root

  • linux file operation command entry 2011-10-05   Linux file copy, delete and move commands       cp command in the command's function is to copy the given file or directory to another file or directory under MSDOS co

  • linux delete file / directory command 2011-06-14

    Name: rm Access: All users use: rm [options] name ... Description: Removes files and directories. Parameters:  -I asks for confirmation before deleting them one by one. -F even if the original file attributes set to read, also directly deleted witho

  • Several commonly used Linux operating file folder command 2011-06-26

    Recently with Dotcloud, a cloud services platform supports multiple, often need to log into remote host, there are a few commands are used most frequently, concluded the following: Copy: cp-rf ** des / / current directory recursively copy all files a

  • Linux File Find command find, xargs details 2010-04-22

    Linux File Find command find, xargs details <! - Begin content -> Summary: zhy2111314 From: LinuxSir.Org Order: North South North Abstract: This paper is a detailed description of the command find, valuable is for the parameters cited many instances

  • Several file transfer command under Linux sz rz sftp scp 2011-09-15

    Several file transfer command under Linux sz rz sftp scp Recently deployed systems at the touch of some file transfer commands, respectively, make a brief record: 1.sftp Secure Ftp is a security protocol based on SSH file transfer management tools. B

  • Linux File Find command find, xargs details (transfer) 2010-11-04

    Linux File Find command find, xargs details Summary: zhy2111314 From: LinuxSir.Org Order by: North South North Abstract: This article is a detailed description of the command find, valuable is for the parameters cited many instances, a large number o

  • I used the Linux command sftp - Secure file transfer command line tool 2011-04-03

    I used the Linux command sftp - Secure file transfer command line tool This link: (reproduced please indicate the source) Use Description sftp command via ssh to upload and download files, is commonly used

  • Linux file access and control (turn) 2011-08-12

    From Linux file access and control We have said before, the file system to achieve the protection of the file, it is how to achieve it? It is mainly through the user access control. Now we look at

  • linux copy file command in the remote (scp) Xiangjie 2010-03-08

    Linux systems use scp command. scp is the secure copy of the shorthand, used to remotely copy files under linux commands, and it has a similar command cp, cp, but only in the copy machine can not cross-server. Sometimes we need a file on a remote ser

  • Linux file transfer command scp 2010-05-25

    Linux file transfer command SCP (Secure Copy) scp SSH command is the most convenient and useful commands Just think, in the transfer files directly between two servers only use scp command is completely resolved. You can be a server On to run as root

  • linux compression (decompression) command Depth - turn 2011-04-01

    Original Address: One. Tar command tar files and directories can be created for the files. Use tar, you can create a file for a specific file (backup file), you can also change the file i

  • linux file system implementation of (turn) 2010-11-26

    Two articles collated before the linux virtual file system structure, and the linux file reading and writing process. Some of the specific type of file system is not the place to achieve further described, but said this is a specific file system to a

  • Crash Analysis Tool using the Linux dump file 2010-04-05

    Preface Linux kernel (the core) is a process not associated with a particular feature set, the kernel code is difficult to easily perform in the debugger and track. Developers that the kernel if an error occurs, it should not continue to run. Thus th

  • JAR file jar command packet and explain 2009-09-10

    Note that the creation of the JAR file need to include a complete package and the package with the Java program structure of the corresponding directory structure, just like the above example. The Main-Class specified type, it must be complete, inclu

  • linux for chmod, chown command Xiangjie 2010-02-09

    I Taobao shop Command name: chmod Permissions: means all users: chmod [-cfvR] [- help] [- version] mode file ... Description: Linux / Unix file access rights are divided into three levels: the file owner, group, other.

  • Achieved using samba linux, windows file sharing between 2010-03-30

    Often need to use under linux file under windows, but the files uploaded via ftp to the linux on and very time-consuming and a waste of disk space, it is difficult to ensure synchronization of files on two machines, if able, like windows as directly

  • Linux copy file copy cp. Delete and move commands 2010-06-09

    cp command The command function is to copy the given file or directory to another file or directory, just like the DOS copy command under the same very powerful. Syntax: cp [options] source file or directory target file or directory Description: The

  • Linux Quick Start of command 2010-07-08

    1. # Express permission users (eg: root), $ that ordinary users the boot prompt: Login: user name password: enter the password the user is registered with the system after the user successfully login, you can enter the appropriate user environment. E

  • Linux kernel and driver programming - Linux Proc File System reveal the mystery of 2010-10-12

    Abstract This paper introduces the Linux proc file system in some detail. Proc file system, first introduced the basic concept / stored / read time / loading, and then describes how to use the proc file system reads the system / kernel in a variety o