Author: Vamei Source: http://www.cnblogs.com/vamei Welcome to reprint, please keep this statement. Thanks!
After understanding the Linux file management background , we can learn some commands to manage our files.
File operation related
There are commands that help us "prune" the file tree we saw earlier.
$touch a.txt
If a.txt does not exist, generate a new empty document a.txt. If a.txt exists, then only the time information for that document is changed. (This command is actually not widely used, but it can help us create an empty file to experiment with the following operations)
$ ls.
is short for list, which lists all file names in the current directory
$ls -l a.txt
List file details
$cp a.txt b.txt
cp is short for copy and is used to copy files. In the working directory, copy a.txt to the file b.txt
$cp a.txt ..
Copy a.txt to a.txt of the parent directory
$mv a.txt c.txt
mv is short for move and is used to move files. Move a.txt to c.txt (equivalent to rename rename)
$mv c.txt /home/vamei
Move c.txt to /home/vamei directory
$rm a.txt
rm is short for remove and is used to delete files. delete a.txt
$rm -r /home/vamei
Delete the entire subfilesystem down from /home/vamei. -r means recursive, which refers to the operation of repeated deletion, the /home/vamei folder is empty, and then delete the /home/vamei folder itself.
(Programmers are always interested in this command, $rm -rf / It will delete the entire file tree. The purpose of f is to tell rm to do it without any further confirmation... In general, no one should use this command .)
$mkdir /home/vamei/good
Create a new directory
$rmdir /home/vamei/good
delete an empty directory
file permissions
$chmod 755 a.txt
(You must be the owner of the file a.txt to run this command. Or run the command as superuser with $sudo chmod 755 a.txt.)
change mode Change the read, write and execute permissions of a.txt. Remember that each file has nine read, write and execute permissions (see Linux file management background knowledge ), divided into three groups, corresponding to the owner (owner), the user in the owner group (owner group) and all other users ( other). Here we also have three numbers, 755, corresponding to three groups. 7 is assigned to the owner, 5 is assigned to the owning group, and the last 5 is assigned to other users. Linux regulations: 4 is the right to read, 2 is the right to write, and 1 is the right to execute. The 7 we see is actually 4 + 2 + 1, indicating that the owner has three rights to read, write, and execute. (Think about what 5 means)
At this point, run $ls -l a.txt, and you should see that the nine-digit permissions have changed to rwxr-xr-x. According to your own needs, you can replace 755 with 444, 744, for example, to make the file have different permissions.
$sudo chown root a.txt
change owner Change the owner of the file to root user. This command requires superuser privileges to execute, so we add sudo before the command.
$sudo chgrp root a.txt
change group Change the owning group of the file to the root group
Linux filename wildcard expressions
(wild card, 也叫filename pattern matching)
The commands mentioned before, such as ls, mv, cp can accept multiple parameters, such as:
$ls -l a.txt b.txt c.txt
You can list all the information of these three files.
Sometimes, we want to list the information of all files ending with .txt in the working directory, we can use the following way:
$ls -l *.txt
*.txt is written using Linux wildcard expressions. It is similar to regular expressions, but the syntax is different.
Filename Pattern Matching corresponding meaning
* any number of arbitrary characters
? any character
[kl] character k or character l
[0-4] One of the digits 0 to 4 characters
[be] one of b to e characters
[^mnp] a character, this character is not m,n,p
Linux will find filenames that match the expression and pass those filenames as arguments to the command. Note, be careful when using rm. The following two commands, differing only by one space, have very different effects:
$rm * .txt
$rm *.txt
The first command will delete all files in the current directory!
Summarize
touch, ls, mv, cp, rm, mkdir, rmdir
chmod, chown, chgrp
wild card
Welcome to the series of articles on "Riding a Penguin to Pick Raspberry"