Linux interview frequently asked commands

Reprinted from: https://blog.csdn.net/u010842515/article/details/72732106

1. What symbol is used for absolute path? What does the current directory and the upper directory represent? What is the main directory? What command is used to switch directories?

Absolute path: such as /etc/init.d

current directory and upper directory: ./  ../

home directory: ~/

switch directory: cd

2. How to check the current process? How to perform exit? How to check the current path?

View the current process: ps

execute and exit: exit

View the current path: pwd


3. How to clear the screen? How to exit the current command? How to perform sleep? How to check the current user id? What command to use to view the specified help

?

Clear the screen: clear

to exit the current command: ctrl+c to completely exit

the execution sleep: ctrl+z to suspend the current processfg restore the background to

view the current user id: "id": view the uid and gid of the currently logged in account and the

group .

View the specified help: such as man adduser, this is very complete and has examples; adduser --help this

tells you Some common parameters; info adduesr;

4. What function does the Ls command perform? What parameters can I take and what is the difference?

The function performed by ls: List the directories in the specified directory, as well as

the parameters and differences of the files: a All filesl Detailed information, including the size of bytes, read, write,

and executable permissions, etc.

5. Establish soft links (shortcuts), and commands for hard links.

Soft link: ln -s slink source

Hard link: ln link source

6. What command is used to create a directory? What command do you use to create the file? What command do you use to copy files?

Create a directory: mkdir

Create a file: typically touch, vi can also create a file, in fact, as long as the output to a non-existing file will create a file

copy file: cp 7. What command is used to modify file permissions? What is the format like?
Modification of file permissions: The chmod

format is as follows:

$ chmod u+x file adds the execution permission to the owner of the

file $ chmod 751 file assigns the permissions of read, write, and execute (7) to the owner of the file, and assigns the read, write, and execute

permissions to the group where the file is located , Execute (5) permissions, assign permissions to execute (1) to other users

$ chmod u=rwx,g=rx,o=x Another form of the above example

$ chmod =r file assigns read permissions to all users

$ chmod 444 file Same as above

$ chmod a-wx,a+r fileSame as the above example

$ chmod -R u+r directory recursively assigns read permissions to the owners of all files and subdirectories in the directory directory

8. What commands can be used to view the file contents?

vi filename #view in edit mode, you can modify

cat filename #display all file content

more filename #paginate display file content

less filename #similar to more, better is that you can page forward

tail filename #only view the tail , you can also specify the number of lines

head file name # view only the head, you can also specify the number of lines

9. Write file commands at will? How to output a string with spaces to the screen, such as "hello world"? Write a file command: vi

10. Which file under which folder is the terminal? Which command under which folder is the black hole file?

/dev/tty /dev/null

11. Which command is used to move files? Which command to use to change the name?

mv mv

12. Which command is used to copy files? What if you need to copy it together with the folder? If you need to have a prompt function?

cp cp -r  ? ? ? ?

13. Which command is used to delete a file? If you need to delete the directory and the files in the directory together? What command do you use to delete empty folders?

rm rm -rrmdir

14. What kinds of wildcards can be used in commands under Linux? What do they mean?

"?" can replace a single character. ·"*" can replace any number of characters. ·Brackets "[charset]" can replace any single character in charset set, such as [az], [abABC] 15. What command is used to count the content of a file? (line number, word count, byte count)
wc command -c count bytes.- l Count the number of lines. - w counts words.

16. What is the purpose of the Grep command? How to ignore case? How to find the line that does not contain this string?

is a powerful text search tool that can use regular expressions to search for text and print out the matching lines.

grep [stringSTRING] filename grep [^string] filename

17.What are the states of a process in Linux? What symbols are used in the information displayed by ps?

(1) Uninterruptible state: The process is in a sleep state, but at this moment the process is uninterruptible. Uninterruptible means that the process does not respond to asynchronous signals.

(2) Suspended state/tracking state: Send a SIGSTOP signal to the process, and it will enter the TASK_STOPPED state in response to the signal; when the process is being tracked, it is in the
special state of TASK_TRACED.

"being traced" means that the process is suspended, waiting for the process that traces it to act on it. (3), ready state: the state in the run_queue queue (4), running state: the state in the run_queue queue

(5), interruptible sleep state: the process in this state is waiting for the occurrence of a certain event (such as waiting socket connection, waiting for a semaphore), and is suspended
(6), zombie state (zombie): the father will release the child process's corpse (task_struct) by the way without passing the wait series of system calls

(7), exit status

D Uninterruptible (usually IO)

R is running, or the process

S in the queue is dormant

T stopped or tracked

Z Zombie process

W Enter memory swap (invalid since kernel 2.6)

X Dead process

18. How to make a command run in the background?

&

19. How to use ps to display all processes? How to use ps to view the information of a specified process?

ps -ef (system v output) ps -aux bsd format outputps -ef | grep pid

20. Which command is used to view background tasks? job -l
21. What command is used to transfer a background task to the foreground for execution? What command is used to execute a stopped background task in the background?

fg

For example: #jobs

[1]+ Running /root/bin/rsync.sh &

#fg 1 bg Similar

22. What command is used to terminate the process? What parameters are there? kill -9 pid

23. How to check all the signals supported by the system? kill -l

24. What command is used to search for files? What is the format? find dir -name "string*"
25. What command is used to check who is currently using the host? What command is used to find the terminal information where you are?

w user name; the user's machine name or tty number; the remote host address; the time the user logged into the system; idle time (not very useful); the time spent by processes attached to the tty (terminal) (JCPU time); the time spent by the current process (PCPU time); the command the user is currently using.
who username, tty number, time and date, host address

whoami,id -un command is used to display the logged in username

last command can be used to display the history of a specific user's login to the system (last jason ): user name; tty device number; historical login time and date; logout time and date; total working time.
Find your terminal information: who am i

26. What command to use to view the list of used commands? history
27. What command to use Check disk usage? What about free space? df -hl
Filesystem

Size Used Avail Use% Mounted on /dev/hda2 45G 19G 24G 44% /
/dev/hda1 494M 19M 450M 4% /boot

28. What command to use to check whether the network is connected ?

netstat

29. What command is used to view ip address and interface information? ifconfig

30. What command is used to view various environment variables? View all env
and view a certain one, such as home: env $HOME

31. What command is used to specify the command prompt? \u Display the current user account\h Display the current host name
\W Only Display the last directory of the current path\w Display the current absolute path (the current user directory will be replaced by ~) $PWD Display the current full path\$ Display the command line '$' or '#' symbol\#: The number of commands issued

\ d : Represent date, the format is weekday month date, for example: "Mon Aug 1"

\t : Display time is in 24-hour format, such as: HH:MM:SS \T : Display time is in 12-hour format\A : Display time is 24-hour format: HH: MM \v : BASH version information
such as export PS1='[\u@\h \w\#]\$ '

32. Where to find the executable file of the search command? How to find it To set and add? whereis [-bfmsu][-B <directory>...][-M <directory>...][-S <directory>...][file...]

Supplementary note: the whereis directive will look for eligible files in a specific directory. The content of these files should belong to source code, binary files, or help files.

-b Find only binary files.

-B <directory> Look for binary files only in the set directory. -f Do not display pathnames before filenames.
-m Find only documentation.

-M <directory> Look for documentation only in the specified directory. -s Find only raw code files.
-S <directory> Look for source code files only in the set directory. -u Find files that do not contain the specified type.
The which command searches for the location of a system command in the path specified by the PATH variable and returns the first search result.

-n Specifies the filename length, which must be greater than or equal to the longest filename among all files.

-p is the same as the -n parameter, but here includes the path to the file. -w Specifies the width of the column on output.
-V Display version information

33. What command is used to find the execution command?

which can only check executable files whereis can only check binary files, documentation, source files, etc.
34. How to take aliases for commands?

alias la='ls -a'

35. The definition of du and df, and the difference? du Display the size of a directory or file
df Display information about the file system where each <file> is located. The default is to display all file systems.

(The file system allocates some of these disk blocks to record some of its own data, such as inodes, disk map, indirect blocks, super blocks, etc.

This data is invisible to most user-level programs and is often referred to as Meta Data. ) The du command is a user-level program that does not consider Meta Data, while the df command looks at the filesystem's disk allocation
map and considers Meta Data.

The df command gets real filesystem data, while the du command only looks at part of the filesystem.

36. Awk detailed explanation.

awk '{pattern + action}' {filenames}

#cat /etc/passwd |awk -F ':' '{print $1"\t"$7}' //-F means ': 'separate root /bin/bash

daemon /bin/sh search /etc/passwd for all lines with root keyword

#awk -F: '/root/' /etc/passwd root:x:0:0:root:/root:/bin/bash


Guess you like

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