Linux basic commands-Files and directories

Source: Internet
Author: User
Tags system log touch

Reference: "Bird's-brother Linux private Cuisine" The first seven chapters, 17/12/5 review

    • File permissions

Rwx421;-r recursion; user, user group, other

Umask View default directory: 0002, that is, the other took off the W permission, can also be directly umask-s

Chgrp

Chown Zuo:zuo passwd

chmod +664 testfile//-rw-rw-r--

chmod U=RWX,GO=RW testfile

chmod +x testfile

+ number is add permission, no plus sign directly specify permissions

For the directory: R printable, W can modify any file in the directory, X can enter into a working directory

    • Directory Configuration

FHS Standard

Third-party software generally in/USR/SRC or/opt

Kernel source code in/USR/SRC

/ Root

/bin -user binary files
In single-user mode, the common Linux commands you need to use are located in this directory. The commands used by all users of the system are set here.
For example: PS, ls, ping, grep, CP8

/sbin

It is usually used by system administrators to maintain the system. Example: Iptables, reboot, Fdisk, ifconfig, swapon commands

/ etc -configuration file

Hosts: The resolution of the device name (or domain name) to the IP address, equivalent to the local presence of DNS functionality.

/ Dev -device files
These include terminal equipment, USB or any device connected to the system. For example:/dev/tty1,/dev/usbmon0

/proc -Process information
This is a virtual file system that contains information about the processes that are running. For example: The/proc/{pid} directory contains information related to a specific PID.

/ var -variable file
This directory allows you to find files that may grow in content. Includes-System log files (/var/log), Package and database files (/var/lib), e-mail (/var/mail), print queue (/var/spool), lock file (/var/lock), and multiple restarts of required temporary files (/var/tmp);

/ tmp -temp file
Contains system and user-created temporary files. When the system restarts, the files in this directory will be deleted.

/ usr -unix software Resourse
Source code that contains binaries, library files, documents, and level two programs.
The/usr/bin contains a binary file of the user program. If you can't find the user binaries in/bin, go to the/usr/bin directory to see. For example: At, awk, CC, less, SCP.
The/usr/sbin contains the system administrator's binaries. If you can't find the system binaries in/sbin, go to the/usr/sbin directory to see it. For example: ATD, Cron, sshd, Useradd, Userdel.
The/usr/lib contains the libraries used by/usr/bin and/usr/sbin.
The user program installed from the source is included in the/usr/local. For example, when you install Apache from the source, it will be in/usr/local/apache2.

/home Directory
All users use the home directory to store their personal files.
For example:/home/john,/home/nikita

/ boot -boot loader files
The kernel's initrd, vmlinux, and grub files are located under/boot. Example: Initrd.img-2.6.32-24-generic

/lib -System Library
Contains library files that support binary files located under/bin and/sbin.
The library file is named LD or Lib. So.* for example: ld-2.11.1.so,libncurses.so.5.7

/opt -Optional add-on application
Contains additional applications from individual vendors.

/mnt -Mount Directory
A temporary installation directory where the system administrator can mount the file system.

/media -removable media devices
A temporary directory that is used to mount removable devices.
For example, the/media/cdrom,windows attached to the CD-ROM is also usually hung here

/srv -Service data
Contains data related to server-specific services.
For example,/srv/cvs contains CVS-related data.

    • Directory Operations

Cd

Pwd

Mkdir:-p Recursive Creation-m Specify permissions

RmDir

Ls:-r list all files recursively;-s press from large to small;-t time from new to old;-R reverse

Cp:-p copy property;-r recursive copy;-d copy link file;-a equivalent to pdr;-u new copy;-L create hard link,-s soft link

RM-RF/

    • File contents

Cat:-n line number;-a displays invisible characters

Tac

nl

More

Less: most commonly used

Head-n 10;-10 only print excluding the following 10 lines

Tail-n 10;-10 excluding the previous 10 lines

OD-A: Default read, C, D,o,x,ascii, decimal, octal, 16 binary

File View Files Type

    • File time

Mtime content Changes

CTime state changes, such as permissions, properties

Atime file contents are read

Viewing time: ll--time=ctime filename; default is Mtime

Change time: touch-m/a Change the modification time, the access time is the current time

-D "2 days Ago"

-T specify time, [[CC]YY]MMDDHHMM[.SS]

    • File Hidden Properties

Chattr + a filename, can only add content; +i, cannot be censored

Lsattr

    • File Special Permissions
  1. SetUID

-rwsr-xr-x 1 root root 27832 Jun 10 2014 /usr/bin/passwd

When s appears on the file owner's X-permission, called Suid

Valid only for binaries, performer requires x permission, temporary owner privilege

  1. Set GID

When s appears on the user group's X-rights, called Sgid

Can be used for directory; the performer needs x permission; Temporary support for user groups

  1. Sticky Bit

drwxrwxrwt 9 root root 4096 Dec 5 01:46 /tmp

When T appears on other X-rights

only for directories; only this user and root can delete the file

Chmod can be used to set the above three permissions, 421, the other capital S or T indicates that the user has no X permission, that is, empty

    • Environment variables

Echo $PATH

Path= "$PATH":/opt/typora

    • Find
  1. which

Find execution files based on path

  1. Whereis

Finding files in the database

  1. Locate

updatedb updating database; fuzzy matching;-I ignoring case;-R regular matching

  1. Find

Find | path| | option| |file|

  • Time parameters

The day-mtime n,n days ago

-mtime +n,n days ago (n days not included)

Within-mtime-n,n days (including n days)

-newer file, newer than file

  • User-related

-user Name

-group Name

-nouser

  • Permission name related

-name filename

-size +/-100c;c for Bytes,k to kb,m for Mb,g GB

-type Type;type has the following types: F generic file, b/c device file, D directory, L link file, s socket, p pipeline

-perm mode; The file with the right mode;-mode superset, must all include a subset of Mode;+mode, including any mode

-exec plus other commandsfind /tmp -newer test1 -exec ls -l {} \;

Exercise: Build two accounts TMP1 and TMP2, support the same user group project, need to co-own the development rights of the/srv/ahome directory, and the directory does not allow other users to access

//Create users and user groups[Email protected]/]# Groupadd project [[email protected]/]# useradd-g project Tmp1[[email protected]/]# Useradd- G Project TMP2//Set up directory and Permissions[Email protected]/]# cd/srv [[email protected] srv]# mkdir./ahome[[email protected] srv]# chgrp project/srv/ahome[[ Email protected] srv]# chmod770Ahome[[email protected] srv]# ll-d ahomedrwxrwx---2Root Project4096Dec5  to: $Ahome//tmp1 Create file But TMP2 cannot access[[email protected] srv]# su tmp1[[email protected] srv]$ CD Ahome/[[email protected] ahome]$ Ls[[email protected] ahome]$ Touch Testfile[[email protected] ahome]$ su rootpassword: [[email protected] ahome]# su tmp2[[email protected] ahome]$ ll testfile-rw-rw-r--1TMP1 TMP10Dec5  to: -Testfile//Note TMP2 users are equivalent to other, only R permissions//Add Sugid permissions[email protected] ahome]$ su rootpassword: [[email protected] ahome]# chmod2770/srv/ahome//Verification[[email protected] ahome]# su tmp1[[email protected] ahome]$ touch File[[email protected] ahome]$ lltotal0-rw-rw-r--1TMP1 Project0Dec5  to: theFile//Note User groups become project[email protected] ahome]$ su rootpassword: [[email protected] ahome]# su tmp2[[email protected] ahome]$ ll Total0-rw-rw-r--1TMP1 Project0Dec5  to: theFile

Linux basic commands-Files and directories

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.