Commands related to files and directories

Commands related to files and directories

1.ls: List the names of the current files and folders

grammar:

 ls [-alrtAFR] [name...]

Parameters :

  • -a show all files and directories ( hidden files starting with . are also listed)
  • -l In addition to the file name, it also lists the file type, permissions, owner, file size and other information in detail
  • -r display files in reverse order (original alphabetical order)
  • -t list files in order of creation time
  • -A Same as -a, but do not list "." (current directory) and "…" (parent directory)
  • -F Add a symbol to the list of file names; for example, "*" for executables, "/" for directories
  • -R If there are files in the directory, the following files are also listed in sequence

ls -a: Display the names of all files and folders (including hidden ones such as .book)
ls -l=ll: Display detailed information of files and folders
drwxr-xr-x 1 root root 4096: The beginning of d is the file Folder, folders are all 4096 size
ls -R: recursively display the
directory

[root@localhost ~]# ls -ahl
total 28K
dr-xr-x---.  2 root root  135 Dec 16 02:34 .
dr-xr-xr-x. 17 root root  224 Dec 14 01:38 ..
-rw-------.  1 root root 1.3K Dec 14 01:38 anaconda-ks.cfg
-rw-------.  1 root root 1.2K Dec 16 02:34 .bash_history
-rw-r--r--.  1 root root   18 Dec 28  2013 .bash_logout
-rw-r--r--.  1 root root  176 Dec 28  2013 .bash_profile
-rw-r--r--.  1 root root  176 Dec 28  2013 .bashrc
-rw-r--r--.  1 root root  100 Dec 28  2013 .cshrc
-rw-r--r--.  1 root root  129 Dec 28  2013 .tcshrc

Please add image description

As you can see from the above, each row has 7 columns, which are:

  1. **The first column** has a total of 10 digits,

Please add image description

The first digit indicates the document type, d indicates a directory, - indicates a file, l indicates a linked file, c indicates a device with random access, such as a U disk, etc., and c indicates a one-time read device, such as a mouse, keyboard, etc.
The last 9 digits correspond to the permissions possessed by the three identities in turn, 1-3 digits: owner (the owner of the file), 4-6 group (users in the same group of the owner), and 7-9 digits: The
order of permissions for others (other users) is: r stands for read, w stands for write, and x stands for execute.
For example: -r-xr-x—means that the current document is a file, readable and executable by the owner, readable and executable by users in the same group, and others without any permission .

  1. The second column represents the number of links, indicating how many files are linked to the inode number.
  2. The third column represents the owner
  3. The fourth column represents the group you belong to
  4. The fifth column indicates the size of the document, in bytes
  5. The sixth column represents the last modification time of the document. Note that it is not the creation time of the document.
  6. The seventh column represents the document name. Documents starting with a dot (.) are hidden

2.mkdir: create a new directory

mkdir test: Create a folder named test
mkdir test01 test02 test03: Create folders named test01, test02, and test03 respectively
mkdir -p: Directly create all directories (including the upper-level directory) recursively
mkdir - p test04/test04-01/test04-01-01

3.rmdir: delete empty directories

rmdir test: delete the folder named test (the contents of the folder are empty)
rmdir -p test/test01: directly delete the test folder, including the empty directory test01. (If there are files in test01, the deletion is unsuccessful)

4.cd change directory

(1) Absolute path

Path writing, starting from the root directory/: cd /root/test1/test2

(2) Relative path

Click the tab key to automatically complete the file/folder name
Double-click the tab to list all files in the current directory, the folder
path is not written from /: in the root directory cd test1/test2 or ./ (current directory)
cd ~Enter User home directory
cd …return to the upper level
cd …/…return to the upper level
cd / Enter the root directory

5.pwd: Display the absolute path of the current folder

6.vi: Text editor

vi today: open today, if the file does not exist, create a new today

model

(1) Insert edit mode (click on the keyboard insert, or i, a, o) the sign is -INSERT- in the lower left corner
(2) Esc command mode (click on the keyboard Esc, the sign is in the lower left corner -INSERT- disappears)
:q: Exit program; :w: save file
: wq: save exit
: wq! : Force save and exit
:q! : Force quit
u: Undo the last input
G: Skip to the last line of text
gg: Skip to the first line of text
? bcbx: find bcbx, press n to find next
/ bcbx: find bcbx, press n to find previous
crtl+c: terminate
ctrl+b: page up
ctrl+f: page down
dd: delete current line ( the line where the cursor is located)

7.cat: View the content of the file (without entering the content, the knowledge shows the content) (displayed from the first line)

cat -n sey: display the line number where sey is located

8.cp: Copy a file or directory

cp source file target file path (absolute path is recommended)
cp /root/fuyao /root/modaozushi
cp -r: recursive continuous replication, used for the entire folder replication behavior. Such as: cp -r source folder destination folder: cp -r /root/day /root/modaozushi
create a copy cp 0001 0002 (non-existing file name): created a copy of 0001 0002 (non-existing file name)

9.rm: delete a file or directory

rm source file name (prompt "whether to delete the XX file, this command cannot directly delete the folder")
rm -r source file name: delete folder
rm -f: force delete file
rm -rf: force delete file or folder

10.mv Move or rename files and folders

mv source file/folder target folder/file (rename if target folder/file does not exist)
mv source file/folder target folder (move a file or folder to a folder)

11.find finds a folder or file under the specified file and prints the absolute path

find path -name "folder or file name" (part of the name plus *, wildcard)
know the full name of the name: find / -name "ylem-hadse"
only know the beginning of the name: find / -name "ylem-h
"
only know the name Ends : find / -name " em-hades"
doesn't know the middle part: find / -name "yle
des"
knows only the middle part: find / -name " em-ha "

12.tar compresses or decompresses files

Compression: tar -cvf Compressed package name (recommended to end with .tar for easy identification) The file you want to compress

tar -cvf ylem.tar / bcbx22 / kingrealhart

Unzip: tar -xvf the name of the compressed package (unzip the compressed package to the current folder)

tar -xvf ylem.tar

13.tail view the following lines of the file (default 10 lines)

tail filename (view the last 10 lines of the file)
tail -n filename (view the last n lines of the file)
tail -f filename (dynamically keep viewing the file until you press ctrl+c to exit)

14 echo command

Used to view the value of the environment variable after echoing characters on the display screen (equivalent to printing out print)
echo content to be displayed
echo test→test
echo 'file content' >> file path: echo 'goodman' >> /root/ bcbx22/kingrealheart/hades04/test
echo 'file content' > file path:

15.touch create file

touch test01: Create a file named test01
touch test01 test02 test03: Create
files

If there is any infringement, please contact by email, I am sorry.
This is only for learning personal notes, and if there is any reprint, please indicate the source.
Contact email: [email protected] Let’s
learn to test and open the penguin group together (chat, water group, advertising do not disturb): 826471103

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324327659&siteId=291194637