One, view directory and file commands
- CD Change Directory
(1) Cd/usr/bin
(2) Cd. (.: current directory,...: top-level directory )
(3) CD/
(4) Cd ~ ( user home directory )
2.ls Listing Directory contents
Contents: Blue, plain file: Black, executable: Green grass, link file: Light blue
(l) Ls-a display of all files, including implied files
(2) Ls-l viewing various properties of a file
(3) Ls/etc/init.d/ view content in a directory
3.dir and vdir Listing directory contents
(1) dir has less function than ls , and the others are the same
dir/etc/init.d/
(2) VDir equivalent to ls-l
4.cat and more view text files
(1) cat-n stack.h-n Display line number
(2) More: can be a page by page to display the content, Press the space to flip a page, press Enter to scroll down one page,Q exit
Eg:more Fstab
5.head and tail reading the beginning and end of a file
(1) Head-n 2 day weather-n: Show line number
(2) Tail-n 2 day weather
6.less Better text reading tools
(1) less/boot/grub/grub.cfg
space: Turn down one page B: Turn up one page
/ Find: Find to continue looking for the same content: just re-enter /, and press Enter to go.
Q: Exit
7.grep Find File Contents
(1) grep un day finds un rows in File day
- find files within the specified range
(1) Find/usr/bin-name zip-print find the zip command in the /usr/bin directory
(2) Find/etc-name Init.d-type d-print Find the directory named init.d in the/ etc Directory
The -type option for the Find command is available with parameters:
B: block device file c: Character device file d: directory file f: normal file p: Named pipes L: Symbolic Links
8.locate faster positioning of files
(1) Locate *.doc
9.firefox running program from Terminal (Firefox)
10.whereis Finding specific programs
(1) Whereis find
Find:/usr/bin/find/usr/share/man/manl/find.l.gz
(2) Whereis-b find only the binary executable file for this program
Find:/usr/bin/find
11.who,whomi,uname-a,uname-r User version Information view
12.man ask for help
(1). Mans find
The man command shows the less program when the manual page is displayed . J: Down,K: To the Sky: Flip one Page Down Q: Exit
13.pwd Show current directory
14. Wildcard Characters
Tab(one complement, two lists all)
* : Used to match a string of any length in the file name
? : Matches only one character
[]: used to match all occurrences of a character in square brackets, or to specify a character set range
II: File Directory Management
Linux System main directory and its contents
/bin commands required to build a minimal system ( most commonly used commands )
/boot kernel and boot files
/dev various device files
/etc System software startup and configuration files
home directory for user
/lib C compiler's library
/media mounting point for removable media
/opt Optional application package (rarely used)
image of the/proc process
/root superuser root home directory
/sbin commands related to system Operation
/tmp temporary file storage point
/usr non-system programs and commands
/var system-specific data and configuration files
Linux file Types
Normal file:- directory:D character device file:C block device file: b local domain socket: s
Famous pipe:p Symbolic Link:l
1. sudo groupadd workgroup Create a new user group named workgroup
sudo useradd-g workgroup Lucy new Lucy member joins workgroup
sudo passwd lucy sets the login password for the user Lucy
sudo useradd-g workgroup Lewis
sudo passwd Lewis
first , create a directory called work in the/home directory as the working directory for this group.
Cd/home
sudo mkdir work
Now anyone can access this new directory, and only the root user has write access to the directory. Now you want the members of the workgroup Group to have read and write access to this directory, and to prevent other unrelated users from viewing the directory
sudo chgrp workgroup work/ take Ownership of the work directory to the workgroup Group
sudo chmod g+rwx work/ add workgroup Group to work directory read, write, execute permissions
sudo chmod o-rwx work/ Revoke other user 's Read, write, execute permissions on the work directory
Next we need to give this directory to a leader Lewis(now The owner of the work directory or the root user)
sudo chown Lewis work/
now all members belonging to this group can access and modify the contents of this directory, while other unauthorized users (except root) cannot see the content. For example,Lewis creates an empty file named test under the/home/work directory , and users of the same group Peter If you think that this file is not necessary, you can delete it.
Su Lewis
Cd/home/work
Touch test
Su Peter
Cd/home/work
RM Test
- mkdir Building a directory
(1) CD ~
Mkdir doucument Picture
(2) mkdir ~/picture/temp
(3) Mkdir-p ~/tempx/job Mkdir will first create the tempx directory and then create the job. This option is useful when you need to create a directory structure.
2.touch Creating an empty file
(1) Touch Hello
The 3.touch command can also update the build date and time of a file
4.MV Move and rename (mv can rename files and directories while moving them )
(1) MV hello/bin/move the file Hello to the bin directory
(2) Mv Photos/ Desktop / Move the Photos directory to the desktop
(3) mv-i Hello test/ ask before overwriting
(4) Mv-b Hello test/
CD test/
Ls
Hello hello~
(5) MV hello~ hello_bak Rename
5. CP copy files and directories
(1) CP test.php test/
As with the MV command,theCP overwrites the file with the same name in the destination directory by default. You can use the- i option to prompt for this situation, or you can use the- b option to rename a file with the same name and then copy it, using the same two options as the command in MV.
(2) Cp-i test.php test/
(3) Cp-b test.php test/
(4) The CP command will automatically skip the directory when copying is performed. For example:
Cp-r test/ Desktop /
CP: Skip Directory "test/"
(5) Cp-r test/ Desktop /
6.rmdir and rm Delete directories and files
The rmdir command is used to delete directories , rmdir can only delete empty directories, so the files and subdirectories under this directory are removed before using rmdir
(1) mkdir remove
Rmdir Remove
RM command can delete one or several files at a time
(1) RM test/*.php
(2) rm-i Test/hello Tips
(3) for read-only files, This is also indicated by theRM command, even if the-I optionis not added
You can use the-f option to avoid such interactive operations
Rm-f Hello_bak
(4) rm-r photos/ Delete all files and subdirectories in the directory recursively
5. File and Directory Permissions
3 types of privileges include: Owner, group, other person
permissions to set:R ( read ), W ( write ), X ( execute )
(1) Viewing the properties of files and directories
Ls-l/bin/login file Properties
ls-ld/etc/ Directory Properties
(2) Change of file ownership:chown and chgrp
sudo chown lewis:root days to Change The owner of the file days to Lewis, the group to the root Group
(3) sudo chown guest days only changes the owner
(4) sudo chown:nogroup days change the genus group to Nogroupandretain the master setting
(5) sudo chown-r Lewis iso/ will iso/ and all of its files to the user Lewis
(6) Linux provides a single command chgrp to set the genus of the file
sudo chgrp nogroup days sets the genus Group of days to nogroup Group
sudo chgrp-r root iso/
Change file permissions:chmod
(1) chmod u+x days
(2) chmod a-x days
(3) chmod ug=rw,o=r days
(4) chmod o=u days
(5) Octal representation of file permissions
Rwx=4+2+1=7 r-x=4+0+1=5
rwxr-x--x=751
chmod 711 Prog
- File type
(1) View file types
Ls-l
(2) establishing a connection:ln
Ln-s target Link_name symbolic connection (soft connection) takes an alias to the destination file name link_name
ln days hard_days Hard Connection
2. Input and output redirection and piping
(1) Output redirection
ls > ~/ls_out
Uname-r > Ls_out
Uname-r >> date_out not covered
(2) Input redirection
Cat < days get input from File
(3) Piping |
ls | grep ay Find a file in the file list that contains a specific string in the filename
Linux basic commands