Common Linux commands and interview questions

Common Linux commands

1. File operations 📂

cd		# Enter Directory
cd ..	# Return to the previous directory
pwd 	# Show working paths 
ls 		# View files in the current directory
ls -a	# Hidden files can be displayed
ls -l	# View file details
ls -la 	# View all file details
cat		# View the entire contents of the file
vim		# Edit file: [i] Enter edit mode; Enter [:q] after [ESC] Exit [:wq] Save Exit [:wq!] Force Save Exit
more
less
tail
mkdir   # Create directory
rmdir	# Delete Directory
touch	# create a file
rm		# Delete Files
rm -rf  # Delete directory and all files inside (delete library run)

mv dir1 new_dir 	# Rename/move a directory

cp file1 file2 		# Copy a file 
cp dir/* . 			# Copy all files in a directory to the current working directory 
cp -a /tmp/dir1 . 	# Copy a directory to the current working directory 
cp -a dir1 dir2 	# Copy a directory 

2.Linux Find Files 🔍

find / -name file1 	#Enter the root file system from'/'to search for files and directories 
find / -user user1 	# Search for files and directories belonging to user'user1' 
find /home/user1 -name \*.bin  # Search the directory'/ home/user1'for a'. Files at the end of bin' 
find /usr/bin -type f -atime +100 # Search for executables that have not been used in the past 100 days 
find /usr/bin -type f -mtime -10 # Search for files that have been created or modified in 10 days 
find / -name \*.rpm -exec chmod 755 '{}' \; # Search with'. File at the end of rpm'and define its permissions 
find / -xdev -name \*.rpm # Search with'. Files at the end of rpm', ignoring removable devices such as CD drives, shortcuts 
locate \*.ps 	# Find with'. File at ps'- Run the'updatedb' command first 
whereis halt 	# Display the location of a binary, source, or man 
which halt		# Displays the full path of a binary or executable file 

3. Permission Operations 🔐

chmod: modify permission command, add permission with + sign, delete permission with - sign, execute permission with x, read permission with r, write permission with w

chmod +x	#Add Execution Permissions on behalf

Another way to write it is to use numbers to authorize it, because r=4, w=2, x=1, execute the command chmod 777 file name normally, which is the highest privilege.

The first number 7=4+2+1 represents the owner's rights, the second number 7 represents the rights of the group to which they belong, and the third number represents the rights of others.

A common permission number is 644, with the owner having read-write permissions, others having read-only permissions, and 755 having read-only and execute permissions on behalf of others.

chown: Used to modify the owner and group of files and directories. General usage chown user files are used to modify the file owner. chown user:user files modify the file owner and group, with the colon preceded by the owner and followed by the group.

4. Compression and decompression đŸ“Ļ

zip			# Compressed File
zip -r		# Compress directory
unzip		# Unzip the zip file
unzip -d 	# Unzip to specified directory
gzip		# compress
gzip -d 	# decompression
tar -x		# Unpacking
tar -c 		# Pack
tar -f 		# Specify compressed package file name
tar -v		# Show the packaging file process
tar -cvf xx.tar # Common Packaging Instructions
tar -xvf xx.tar # Common decompression commands

# Packaging and compressing Linux is a separate operation

tar -zcvf xx.tar.gz	#	Pack and Compress
tar -zxvf xx.tar.gz # decompression

5.Linux factory interview questions (problem solving)

1. What is the difference between CPU load and CPU utilization?

CPU Load Rate: The sum of the number of processes currently running and waiting to run on the system
CPU utilization: refers to the percentage of real-time CPU usage by currently running processes. It is a statistic of CPU usage over a period of time.

uptime		# View cup load
top			# View cup load and usage

cat /proc/cpuinfo | grep "model name"	# View the CPU
cat /proc/cpuinfo | grep "cpu cores"	# View the number of cores in the CPU

2. What should I do if the CPU load is high and the utilization rate is low?

For example, a high load rate means there are many queues and a low utilization rate means there are few people doing business. To solve this problem, you need to know why they are queuing instead of doing business.

This typically occurs in IO-intensive tasks

  1. First observe the change of load rate through top command
  2. Then, the ps-axjf command checks to see if there is a process with a state of D+ (D+ state is an uninterrupted sleep state process that can only be resolved by restoring dependent resources or restarting the system)

3. What if the load is low and the utilization rate is high?

For example: low load means no one is queued, high utilization means someone has been doing business and is standing in a pit. 💩īŧŒ To solve this problem, just find out this man and check him for any anomalies.

This happens mainly in computationally intensive tasks

  1. View CPU usage through top command
  2. Find thread ID with high CPU threads through top-Hp PID
  3. Convert the ID from step 2 to hexadecimal using the ID found in step 2 of printf "0x%x\n"
  4. Hexadecimal number from jstack 163|vim+/Step 3 - Find the problem code

Keywords: Linux

Added by Brian on Sun, 20 Feb 2022 04:29:58 +0200