Linux: File and folder management

Source: Internet
Author: User
Tags comparison table file copy rsync

http://blog.csdn.net/pipisorry/article/details/39854265

View user's information

pika:~$ID Pika
uid=1000 (Pika) gid=1000 (Pika) groups=1000 (Pika), 4 (ADM), (CDROM), (sudo), (DIP), (Plugdev), 108 (lpadmin), 124 ( Sambashare), (Docker)

folders and Paths

CD: Transform Mesh 弽
PWD: Show 弽 front eye
mkdir: Create a new Folder

-M,--mode= mode. Set Permissions < mode > (similar chmod) instead of rwxrwxrwx minus Umask
-P,--parents can be a path name. In this case, if some folders in the path do not already exist, and with this option, the system will voluntarily set up those folders that do not already exist, that is, the ability to set up multiple folders at one time;
-V,--verbose displays information each time a new folder is created
RmDir: Delete an empty folder

Toggle Folder Command CD

CD [folder name]: Toggle the current folder to DirName (change of the present directory to DIR)
1. CD/Enter system root folder
2. CD: Return to the previous level folder
3. CD ~ or CD current user home folder
(Note: "Current user home folder" and "System root folder" are two different concepts)

4. CD-Return to the folder where you entered this folder

.         代表此层文件夹..        代表上一层文件夹-         代表前一个工作文件夹~         代表“眼下使用者身份”所在的主文件夹~account  代表 account 这个使用者的主文件夹(account是个帐号名称)

Phi Blog



file and folder management Delete and move: RM, MV

Rm-rf dir #删除文件夹下全部文件

RM-RF Cannot delete folders

#rm-RF Recommendation System 1/
Rm:cannot Remove ' recommended system 1/': Directory not empty

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center "width=" height= "Bayi"/>

When a folder is deleted, if a process is writing data to that folder, it is necessary to stop the process's services (or kill the process), so some of our shell code has the potential to fail when uninstalling or deleting a folder.


[The most Violent RM-RF command failed to delete the folder.] Why? ]

It's just more likely that the file system went wrong (LZ is, maybe it was canceled before the deletion was complete):

Apparently there is a corruption in the filesystem that is preventing me from deleting the directory. Here is the steps I performed. Your mileage may vary ...
Boot into ArchLinux live CD.
Btrfsck--repair/dev/sda1
Mount-t btrfs/dev/sda1/mnt
rm-rf/mnt/__active/home/$USER/.config/chromium~
Umount/mnt
Reboot
Warning:there is risks in performing the Btrfsck--repair command. I suggest backing up any essential data prior to running that command. Read the link provided by Rebootl above for more information on the risks.

In this case, it is best to check the disk when booting. If Windows is turned on, the settings check will be able to check for errors. This allows you to delete the folder.


[

id=185824 ">[solved] rm:cannot remove directory:directory not empty]

[Cannot delete file with RM-RF]

Mv

mv [-fiu] source destination

mv [options] source1 source2 source3 .... directory

选项与參数:-f  :force 强制的意思,假设目标文件已经存在。不会询问而直接覆盖;-i  :若目标文件 (destination) 已经存在时。就会询问是否覆盖!-u  :若目标文件已经存在,且 source 比較新,才会更新 (update)

file copy and backup CP

CP [-ADFILPRSU] source file (source) destination file (destination)

such as Sudo cp a a.$ (date +%y-%m-%d)

CP [Options] Source1 source2 source3 .... directory

Options and number of references:

-a  :相当于 -dr --preserve=all 的意思。至于 dr 请參考下列说明;(经常使用)-d  :若来源文件为链接文件的属性(link file),则复制链接文件属性而非文件本身;-f  :为强制(force)的意思,若目标文件已经存在且无法打开,则移除后再尝试一次;-i  :若目标文件(destination)已经存在时,在覆盖时会先询问动作的进行(经常使用)-l  :进行硬式链接(hard link)的链接文件创建,而非拷贝文件本身;-p  :连同文件的属性(权限、用户、时间)一起复制过去,而非使用默认属性(备份经常使用);-r  :递回持续复制。用于文件夹的复制行为;(经常使用)-s  :复制成为符号链接文件 (symbolic link)。亦即“捷径”文件;-u  :destination 比 source 旧才更新 destination,或 destination 不存在的情况下才复制。--preserve=all :除了 -p 的权限相关參数外,还增加 SELinux 的属性, links, xattr 等也复制了。

最后须要注意的。假设来源文件有两个以上,则最后一个目的文件一定要是“文件夹”才行!

Rsync for file backup synchronization

rsync-axs/var/lib/docker/. DIR

-A,--archive archive mode. Represents a recursive transfer of a file. And keep all file attributes

[Linux rsync command specific collation]

[Rsync for file backup synchronization]
Gets the file name and folder name of the file

Basename/etc/sysconfig/network
Network gets the last file name.


Dirname/etc/sysconfig/network
/etc/sysconfig Gets the folder name.

can also be run in scripts with the. /.. /$ (basename $DIR)

Phi Blog



File Content LookupBasic instructions

    • Cat starts with the first line showing the contents of the file
    • The TAC starts from the last line and is able to see that the TAC is backwards written by cat!
    • NL display, the output line number!
    • More page-by-page display file contents
    • Less is similar to more, but better than more, he is able to page forward!
    • Head's just a few lines.
    • Tail just look at the tail a few lines
    • OD reads the contents of the file in a binary way!
Cat starts with the first line showing the contents of the file

Cat (CONCATENATE)
Options and number of references:
-A: Equivalent to-vet integration options. You can list some special characters rather than blanks.
-B: Lists line numbers and displays only line numbers for non-blank lines. Blank lines are not marked with line numbers.
-E: Displays the end of the break character $;
-N: Prints the travel number. Along with the blank line there will also be line numbers. Different from-B options;
-T: Displays the [tab] key in ^i.
-V: Lists some special characters that can't be seen

The invisible characters in the Note:linux are: ^i represents a tab character. $ represents a carriage return character, ^m$ represents the carriage return line character under Windows.

View file header 10 and tail 10 lines at the same time

Cat File| (Head && tail)

[How to read first and last line from cat output?]


Vim usage considerations viewing file types and encoding files
$ file-i 500,000. csv
Article 500,000. Csv:text/plain; Charset=iso-8859-1
[Email protected]:~/files/datasets/shenzhen card data $ file-i 500,000 article 1.csv

500,000 article 1.csv:text/plain; Charset=utf-8

Language encoding Conversion Iconv

Iconv options
-F,--from-code= name original text encoding
-T,--to-code= name output encoding
-L,--list enumeration of all known character sets
-C ignores invalid characters from output
-O,--output=file output file
-S,--silent off warning
--verbose Printing Progress Information

Recursive conversions (including subfolders)
Find Default-type d-exec mkdir-p utf/{} \;
Find Default-type f-exec iconv-f gbk-t UTF-8 {}-o utf/{} \;

[linux-using iconv Batch conversion GBK file to UTF-8 encoding method]

DOS vs. Linux break characters

In the Note:unix system, there is only "< line >" At the end of each line. That is, "\ n". Windows system inside. The end of each line is "< Enter >< line >", i.e. "\ r \ n"; Mac system. The end of each line is "< Enter >". A direct consequence is. The Unix/mac system file opens in Windows. All the text will become a line. If the files in Windows are opened under Unix/mac, a ^m symbol may be found at the end of each line.

To install: sudo apt-get install-y Dos2unix

dos2unix [-kn] file [newfile]
$ unix2dos [-kn] file [newfile]选项与參数:-k  :保留该文件原本的 mtime 时间格式 (不更新文件上次内容经过修订的时间)-n  :保留原本的旧文件。将转换后的内容输出到新文件。如: dos2unix -n old new
Turn man_db.conf into a Linux break character. And keep old files, new files on Man_db.conf.linux

$ dos2unix-k-N man_db.conf man_db.conf.linux

default command to open a file

To open the All Files method:
Under Ubuntu, when you need to open other format files, we usually go to the folder where the files are located. Double-click to open, very affect efficiency. In fact, the ability to open these format files via command xdg-open, even Web pages, is as simple as opening a file.

Xdg-open will select the appropriate program to open the specified file. Same as double-click to open the effect.

$ xdg-open filename &
$ Xdg-open ***.mp3
$ Xdg-open http://baidu.com
Specific actions such as the following:
Xdg-open {File | URL}
Xdg-open {--help |--manual |--version}
With the shortcut key ctrl+alt+t can open the SHELL,F11 can display full screen (alt+f9 minimized form, ALT+F10 maximize/restore form), supplemented by Xdg-open command, greatly reduced the mouse operation, also greatly improved the efficiency.

Open a. doc docx. xls. xlsx. ppt. pptx
LibreOffice FileName &

Open PDF file
Evince Filename.pdf &

Note: Forget to play & can Ctrl + Z, and then hit BG carriage return; The file name contains spaces to be called ' \ '

Create a new File command touch

Touch MyProject / Settings /{__init. py , Dev . py , prod . py , Test . py }

Note: {...} Ability to create multiple files

Phi Blog



command-and-file queries

Below Linux there are also pretty good search commands!

Usually find is not often used. Because of the slow speed. Also very hard drive! In general, we use Whereis or locate to check it first. Suppose you really can't find it. Search by Find!

Why is it? Because Whereis only look for files below certain folders in the system. Locate uses the database to search for file names. Of course, the two are quite high speed. And there is no actual search for the file system status in the drive

Which (looking for "executable files")

# which [-a] command-a :将全部由 PATH 文件夹中能够找到的指令均列出,而不止第一个被找到的指令名称

Whereis (Find file name in some specific folders)

# whereis [-bmsu] 文件或文件夹名选项与參数:-l    :能够列出 whereis 会去查询的几个主要文件夹而已-b    :仅仅找 binary 格式的文件-m    :仅仅找在说明文档 manual 路径下的文件-s    :仅仅找 source 来源文件-u    :搜寻不在上述三个项目当中的其它特殊文件# whereis passwd     # 全部的文件名称通通列出来!# whereis -m passwd  # 仅仅有在 man 里面的文件名称才抓出来!

Locate/updatedb

# locate [-ir] keyword options and parameters:-I  : ignores uppercase and lowercase differences.  -C: does not output file name. Calculate only the number of files found-l  : outputs only a few lines of meaning. For example, the output of the five lines is-l 5-s  : Output Locate the database file used by the relevant information, including the database records of the number of files/folders, etc.  -r: Can be followed by the form of the display mode

Find File Lookup command

[Linux Find command]

Phi Blog



default permissions and hidden files and folders
Linux file properties

After you have logged into Linux as root, release ls-al to see it. Will look at the bottom of a few:

[Email protected] ~]# ls-al

Total 156drwxr-x---4 root root 4096 Sep 8 14:06. drwxr-xr-x root root 4096 Sep 8 14:21.  -RW-------1 root root 1474 Sep 4 18:27 anaconda-ks.cfg-rw-------1 root root 199 Sep 8 17:14 . bash_history-rw-r--r--1 root root 6. bash_logout-rw-r--r--1 root root 191 J An 6. bash_profile-rw-r--r--1 root root 176 Jan 6. bashrc-rw-r--r--1 root root 1 6. CSHRCdrwx------3 root root 4096 Sep 5 10:37. gconf      <= Sample Description Officedrwx------2 root root 4096 Sep 5 14:09. gconfd-rw-r--r--1 root root 42304 Sep 4 18:26 install.log <= Sample Description Office-rw-r--r--1 root root 5661 Sep 4 18:25 Install.log.syslog[1] [2] [3] [4] [5] [6] [7] [access] [link] [owner] [Group] [Document capacity] [change Date] [archive name] ]

    • The first character indicates that the file is " folder, file, or linked file , etc.":

      • When [ D ] is a folder. For example, the previous table is named ". GConf" of the line;
      • When [ - ] is the file, for example, the previous table is named "Install.log" the line.
      • If [ l ] is indicated as a link file (link file).
      • If [ b ] is indicated as a storage interface device (a random access device) in the device file;
      • If [ C ] is indicated as a serial port device in the appliance file. such as keyboard, mouse (disposable reading device).

    • In the following characters, a group of three and a combination of three parameters are all "rwx". , [R] stands for readable (read), [W] stands for writable (write), [x] stands for Run (execute). Note that the location of the three permissions does not change, assuming there are no permissions. There will be a minus sign [-].

      • The first group is " permissions for file owners ". Take the file "Install.log" for example, the owner of the file can read and write. but not run;
      • The second group is " permission of the same group ";

Changing file properties and Permissions

CHGRP: Change the group to which the file belongs

Chown: Changing the file owner

chmod: Features that change file permissions, SUID, SGID, Sbit, and so on

Note:chgrp, Chown, and other instructions may require the ability to handle root. And can not through-R to change the soft link folder under All file permissions , be sure to use the actual folder.

Chown

[[email protected] ~]# Chown [-r] Account name file or folder
[[email protected] ~]# Chown [-r] Account name: Group name file or folder
Options and number of references:
-R: Continuous change of recursion (recursive), that is, all files under the sub-folder are changed

Note: The user must be an existing account in the system, that is, the record in /etc/passwd This file username said talent change.

For example, replication behavior (CP) replicates the properties and permissions of the runner, so the copied file is still owned by root (assuming root is the owner before). This way, even if you take the file to the bin user, he still can't change it (see Properties/Permissions to know it). So you have to change the owner and the group of the file.


Example

pika:~ $sudo chown-r pika:pika/usr/local/hadoop-2.6.4

Change the owner of the Install.log to the bin account:
[Email protected] ~]# Chown bin Install.log
[Email protected] ~]# ls-l
-rw-r--r--1 bin users 68495 June 08:53 Install.log

Change the owner and group of the Install.log back to root:
[Email protected] ~]# chown root:root Install.log
[Email protected] ~]# ls-l
-rw-r--r--1 root root 68495 June 08:53 Install.log

chmod

Number types Change file permissions

The permission character of the file is: "-rwxrwxrwx", these nine permissions are three three groups of each. Of We can use numbers to represent individual permissions, and the score comparison table for each permission is as follows:

R:4 W:2 x:1

Each identity (owner/group/others) of the respective three permission (r/w/x) score is required to accumulate, such as when the permission is: [-rwxrwx---] score is:

Owner = rwx = 4+2+1 = 7 Group = rwx = 4+2+1 = 7 others=---= 0+0+0 = 0

# chmod [-r] XYZ file or folder
Options and number of references:
XYZ: is the permission attribute of the number type just mentioned, which is the sum of the numeric values of the Rwx property.


-R: Continuous change of recursion (recursive), that is, all files under the sub-folder will be changed

Symbol Type Change file permissions

We are able to represent three identities (1) User (2) group (3) Others by means of u, g, O ! In addition a represents all and all identity!

Then the permission to read and write can be written as R, W, x!

# chmod U=rwx,go=rx. BASHRC
# Watch out!

The U=RWX,GO=RX was linked together. There's no space in the middle!
[Email protected] ~]# ls-al. BASHRC
-rwxr-xr-x 1 root root 395 Jul 4 11:45. BASHRC

Permissions Mask

The settings for the permission mask are digital. The same first number indicates the permission mask for all, the second number represents the group's permission mask, and the third number indicates the permissions of the other user mask

Assuming umask=000, it means that no matter what the user's permissions, that is, all users have read, write and run permissions, such as fmask=033, it means that all the documents have read, write and run permissions, and the group and other users only have Read permissions.

[LINUX umask specific explanation ]

Problems with Windows partition permissions

[Linux system mount Windows partition error ]

Phi Blog

from:http://blog.csdn.net/pipisorry/article/details/39854265

Ref:


Linux: File and folder management

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.