Linux commands, files and directories (Cp,pwd,mkdir,rmdir;ls,cp,rm,mv,basename,dirname;cat,tac,more,less,head,tail,touch,umask,chattr, File,which,locate,find)

Source: Internet
Author: User

1. Directory Operations:

(1) CD (Switch directory)

CD ~ Back to home directory

CD Back to home directory

Cd.. Back to top directory

CD-Go back to the directory just now

Cd/var/spool/mail Absolute Path

Cd.. /mqueue relative Path (written by/var/spool/mail to/var/spool/mqueue)

(2) PWD (show current directory)

PWD Displays the current directory

PWD-P Displays the current directory (does not display the data for the connected file, but displays the correct full path)

(3) mkdir (Create a new directory)

Mkdir-p Test1/test2/test3 Creating a multi-tiered catalog

MKDIR-M 777 test2 New Permissions 777 Directory

(4) RmDir (delete an empty directory)

RmDir Test Delete empty folder test

Rmdir-p TEST1/TEST2/TEST3 Delete Test1/test2/test3

2. File and Directory Management

(1) View file directory (LS)

Ls-a list all files, including hidden files

LS-A lists all files, including hidden files, not included. With the. Two directories

LS-D lists only the directory itself, not including the file data

LS-L lists long strings of data, including file attributes and permissions

Ls-r Sort by File size

Ls-t Sorting by Time

LS--color=never not display color (always display color, Auto automatically judge)

LS--full-time output in full time mode

(2) Copy, delete and move (CP,RM,MV)

Cp-a/var/log/wtmp wtmp_test Copy all of the file's features past

Cp/var/log/wtmp. Copy to current directory

Cp-i if the target file exists, the overwrite asks for the action

Cp-p is copied along with the file attributes

Replication of the Cp-r directory

cp-d If the source file is a property of a connection file, copy the connection file properties, not the connection file itself

Cp-s copy becomes a symbolic connection file

Rm-i Interactive mode, ask the user whether to operate before deleting

Rm-f ignore files that do not exist, no warning message appears

Rm-r Recursive deletion

Mv-f if the destination file exists, it will not be queried and overwritten directly

Mv-i if the destination file exists, ask whether to overwrite

Mv-u if the destination file exists and the source is newer, overwrite

(3) Get path file name and directory name

Basename/etc/systemd/network get the last file name (network)
Dirname/etc/systemd/network Get directory name (/ETC/SYSTEMD)


3. Document Content Review
(1) View the contents of the file directly
Cat starts displaying content from the first line

Cat-a full display with special characters

Cat-b List line numbers (blank lines do not mark line numbers)

Cat-n Print travel numbers (including blank lines)

TAC reverse display, contrary to cat

NL Add line number print

Nl-b A prints travel numbers (including blank lines), similar to Cat-n

Nl-b T If there is a blank line, the line number is not listed in the empty row

Nl-n Ln Row number on screen sitting side display

Nl-n RN line number is displayed to the right of the field without adding 0

Nl-n RZ line number appears to the right of the field, plus 0

Nl-w 3 line Number Default field changed to 3-bit

(2) Can flip view

More/etc/manpath.config View file information (Space page, enter key scroll down one line,/String down query,: F immediately display the file name and the current number of lines displayed, B back page, Q left)

Less/etc/manpath.config View file information (space/pageup up, pagedown down,/String down query,? query string up, n repeat query, n reverse repeat, Q left)

(3) Data selection

Head-n 10/etc/manpath.config Display the first 10 rows (without the-n 10 is also the default display of the first 10 lines)

Head-n -10/etc/manpath.config Display all previous lines, excluding the following 10 rows

Tail-n 20/etc/manpath.config Show last 20 rows

Tail-n +20/etc/manpath.config shows all subsequent lines, excluding the first 20 rows

Tail-f continuously detects the number of rows until CTRL + C is pressed

(4) Non-text files

Od-t a default character output

OD-T C ASCII character output

Od-t d decimal output (f floating point, o octal, x hex)

Od-t occ/etc/issue octal list of stored values and ASCII tables

(5) Modify the file time or create a new file

Touch test Create a new file test

Touch-a Modifying access times

Touch-c only modifies file time and does not create a new file if the file does not exist

Touch-m modifying Mtime

touch-d "2 days ago" test test file date adjusted to two day ago

TOUCH-T 1503151820 test test file time adjusted to 2015.3.15 18:20

4. Default permissions and Hidden permissions

Umask 002 Default Permissions Remove the W permission for other people's permissions

Chattr +i Test Sets the hidden properties of the test file (cannot be deleted, renamed, written to add data, only the root user can set)

Chattr +a Test Sets the hidden properties of the test file (only data can be added, cannot be deleted, modified, only the root user can set)

Chattr-a test cancels the hidden properties of the test file

LSATTR test show test File hidden properties

File Test View Files type

5. Command-and-file queries

Which ifconfig find the full file name of the Ifconfig command

Whereis ifconfig Looking for ifconfig this file

Locate ifconfig looking for files related to Ifconfig

Find/etc-mtime 3 3 days before the day the document was changed

Find/etc-mtime-3 documents changed within 3 days (excluding 3rd day)

Find/etc-mtime +3 3 days ago (excluding the 3rd day)

FIND/ETC-NEWER/ETC/PASSWD looking for/etc under passwd date new file and list

Find/-nouser Find files that are not owned by anyone in the system

Find/home-user root looking for files that belong to root under/home

Find/etc-name Test Search/etc file named Test

Find/-size +100k find files larger than 100k in the system

Find/-size +100k-exec ls-l {} \; List the files found above with Ls-l

Linux commands, files and directories (Cp,pwd,mkdir,rmdir;ls,cp,rm,mv,basename,dirname;cat,tac,more,less,head,tail,touch,umask,chattr, File,which,locate,find)

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.