Interview Questions: common linux commands and common linux commands
Command for displaying directories and files
Ls: Command Used to view all folders.
Dir: command Tree used to display the specified folder and Directory: list the directory content in a Tree chart
Du: displays the directory or file size.
Modify directory, file permissions, owner, and array commands
Chmod: command used to change the permission of a specified file.
Chown: a command used to change the attributes of a file.
Chgrp: command used to change the file group.
Chattr: used to set the permission to delete and modify files.
Lsattr: used to display hidden properties of files or directories.
Create and delete directory commands
Mkdir: used to create a directory
Rmdir: Used to delete an empty directory.
Rm-f: Used to delete directories that are not empty.
Commands for creating, deleting, renaming, and copying files
Touch: Create a new file
Vi: Create a new file
Rm: delete a file or directory
Mv: Command for renaming or Moving Files
Cp: Copy command
Command for displaying file content
Cat: displays all contents of a specified file.
More: display the content of a specified file in the form of pagination
Less: displays the content of a specified file in pagination mode. The difference is that the Operation keys used for more and less paging are different.
Head: used to display the first n rows of the file.
Tail: used to display the last n rows of the file.
Tail-f: displays n rows of data after a file that is automatically refreshed.
SEARCH Command
Find: Find the specified file.
Whereis: Find the specified file source and binary files and manuals.
Which: Used to query the location of a command or Alias.
Locate: quickly finds the specified content in the system database.
Grep: Find the matching strings in the file.
Commands for shutting down and restarting a computer
Shutdown:-r restarts immediately after Shutdown
-K does not actually shut down, but only sends a warning message to all users.
-H: Do not restart after Shutdown
Poweroff: Used to shut down and power off
Init: changes the system running level
Level 0 is used to shut down the system
Level 1 for Single User Mode
Level 2 is used for multi-user usage (without network functions)
Level 3 is used for multi-user usage (with full network functionality)
Level 4 for user-defined use modes
Level 5 indicates the mode when xwindows is enabled
Level 6 is used to restart the system
Reboot: used for computer restart
Halt: Used to shut down the computer system
Compression and Packaging Commands
Tar: Used to package multiple files or directories without compressing them. It also uses commands to unpackage.
Gzip: the extension name ends with .gz.
Gunzip: Used to decompress the gzip compressed file.
Bzip2: Used to compress and decompress files or directories.
Bzcat: used to display the content of the compressed file.
Compress/uncompress: Compress/decompress the. Z File
Zcat: view the compressed file content ending with z or gz.
Gzexe: compresses executable files
Unarg: extract the. arj File
Zip/unzip: decompressed. Zip file
User operation commands
Su: Switch USER commands
Sudo: execute commands as a system administrator
Passwd: used to change the user's password
Change the Directory and view the current directory command
Cd: Enter the working directory
Cd .. : Will return to the upper-level command
Pwd: displays the current user's working directory location
File connection command
Ln: Creates a connection for the source file. If you do not copy the source file, the occupied space is small.
It can be divided into software connection and hard link.
Soft connection: Also known as symbolic connection, which creates a shortcut for a file or directory.
Hard link: place more than one name on a file in different directories for your convenience.
The Ln command parameters are as follows:
-F: when creating a connection, delete the file or directory with the same name as the target object.
-D: allows system administrators to hard-link their directories.
-I: Ask the user before deleting a file or directory with the same name as the target object.
-N: when creating a soft connection, the target object is treated as a normal file.
-S: Creates a soft connection, that is, a symbolic connection.
-V: The file or directory name is displayed before the connection.
-B: Back up the files that will be overwritten or deleted during connection.
Help Command ----- man
Other commands
Who: displays the users in the system.
-The ami displays the current user.
-U: displays the user's actions/work
-S: Display in short format
-V: displays the program version.
Free: view the memory usage of the current system
Uptime: displays how long the system has been running.
Ps: displays the status of transient processes
Top: displays processes dynamically
Pstree: displays all processes in a tree
Date: displays or sets the Date and time of the system.
Last: displays the monthly login system user information
Kill: Kill specific processes.
Logout: exit the system
Useradd/userdel: add or delete a user
Clear: Clear screen
Passwd: Set the User Password
Vi Editor
First, run the vi command to open a file.
Last line mode command:
: N, mwpath/filename Save the specified range document (n table start row, m Table end row)
: Q! Force exit after modifying the file
: Q has not modified the file and exits.
Wq or x save and exit
Dd deletes the row where the cursor is located.
: Set number: displays the row number.
: N jump to n rows
: S replacement string: s/test/test2/g Global replacement/can also be replaced by %
/Search for strings
Common commands for network communication
Arp: network address display and Control
Ftp: File Transfer
Lftp: File Transfer
Mail: Send/receive emails
Mesg: Allows or denies other users from sending messages to their terminals.
MuttE-mail Management Program
Ncftp: File Transfer
Netstat: displays network connection. Route table and network interface information.
Pine: send and receive emails and browse newsgroups
Ping: used to check whether the network is connected smoothly
Ssh: remote login in Safe Mode
Telnet: Remote Logon
Talk: Dialog with another user
Traceroute: displays the path to a host and the time it is used.
Wget: Automatically downloads files from the network
Write: Write information to other user terminals Rlogin: Remote Login
Today, I am asked a linux question when I go out for an interview, and the project will be sent to linux after I enter uat. Therefore, it is necessary to know a few linux commands.
First, it is also the most useful one:
Man looks at the command details. As long as he thinks the command is unclear, man can.
Man ls
Ln create link file
Ln-s sourceName destName
Ls to list objects
-L: displays detailed attributes row by row
-A: lists all objects, including hidden objects starting ".".
Ls-lqt/bin
Cat reads text content
-N: displays the row number.
-B: the row number is displayed and empty rows are ignored.
Cat-n 1.txt
Wc: Count
-L: number of rows
-W: Number of words
-C: number of characters
Wc-l file1 file2... multiple files can be counted
Cp copy file directory
-I: interaction mode. If the target file exists, check whether the file is overwritten.
-R: Copy directory
Cp file1 file2 file3. .. dir indicates copying file1, file2. .. to dir
Cp-r dir1 dir2 dir3. .. dirn copy dir1, dir2, dir3. .. To dirn
View file Types
File test. sh
Move the music video file and change the file name.
-I: interaction mode. If the target file exists, check whether the file is overwritten.
-R: Move the Directory and change the directory name.
Rm delete file
-I: interaction mode. Ask whether to delete it.
Rm-r dir1 dir2 dir3. you can delete multiple
Mkdir create directory
-P: parent. If the parent directory does not exist, the parent directory is created.
Mkdir-p test/test
Rmdir Delete directory
Equivalent to rm-r
Rmdir dir1 dir2 dir3 ....
Rm-r dir1 dir2 dir3 ....
Chmod permission change
Chmod-R 777 DIR changes the permission of all files in the directory to 777, which must be-R
Permission-rwxrwxrwx
421421421
Prefix-indicates that the file type is normal.
The next three digits indicate the owner permission.
The next three digits indicate group permissions.
The last three digits indicate other user permissions.
If a permission is not assigned, use. -Rwxr -- rwx indicates that the group has no write and execution permissions.
The file can be run at night, but indicates whether to allow searching for files in this directory
Chown changes owner
Chgrp Change Group
Command &
Add & to the end of the command to run the command in the background
Find.-name "*. sh "&
Fg puts background processes on the foreground
Fg % 1 place the first job in the background to the foreground
Bg
Put the foreground process in the background
Jobs
Display Background or suspended Processes
Ps
Show all processes
Ps-f displays complete information, including cpu usage time and start time...
Kill
-9 Force end
More: display text content. Press space to continue each screen.
Find/-name "*. sh" | more
Tail displays the following content from the specified position
Tail-f server. log is used to run and view logs on the server.
Tail-10 dos2unix. sh: Check the last 10 lines
Head
Corresponds to tail
Sort sorting
-R Reverse Order
-D dictionary order
Ls | sort-r
Tr character replacement
-D: Delete the specified character ls | tr-d 'log'
Ls | tr 'D' G' converts d to g
At time date job
Regular Scheduling
Compress
-F: compressed file
-V shows the compression ratio.
Compress-vf project.tar: delete project.tar.zand project.tar
Uncompress
-F. decompress the file
-V shows the compression ratio.
Uncompress project.tar. Z deletes project.tarand project.tar. Z.
Tar
-C create a new document
-X unpack
-V: displays the file name being processed.
-F replaces the default file name
Tar-cvf project.tar project/* package all files in the project directory
Tar-xvf project.tar
Crontab
Permission: All Users
Usage:
Crontab [-u user] file
Crontab [-u user] {-l |-r |-e}
Crontab specifies that the user executes the program at a fixed time, that is, the user's time table. -U user is used to set the time table of the specified user. The premise is that you must have the permission (for example, root) to specify the time table of another user. If-u user is not used, the time table is set.