Linux Query Manual

There is a Linux command repository on github, Click to visit

or click here make an inquiry

The following are the common commands that I have collected in my daily use

content

1. Unzip

7z

1. Install p7zip-full

apt install p7zip-full

2. Compression

7z a -t7z -r ../test.7z PIE-master/*

The meaning of each parameter:

  • a represents adding a file (folder) to the archive
  • -t is the specified compression type, which is specified as 7z here. Note that there is no space after t. In fact, you can not specify when the compression is 7z, because the default compression type is 7z. In addition, compression types such as .tar.bz2 are also supported.
  • -r means to recursively compress all subfolders,
  • ../test.7z is the compressed package name
  • PIE-master/* is the file to be compressed

3. Unzip

7z x a.7z -r -o./

The meaning of each parameter:

  • x represents the decompressed file, and it is decompressed according to the original directory tree (there is also a parameter e which is also an decompressed file, but it will decompress all files to the root instead of its own original folder)
  • a.7z is the file to be decompressed
  • -r means to recursively extract all subfolders
  • -o is the specified directory to decompress. There is no space after -o, and the directory is directly connected. This needs attention.

bz2

Unzip 1: bzip2 -d FileName.bz2 
Unzip 2: bunzip2 FileName.bz2 
compression: bzip2 -z FileName 
.tar.bz2 
Unzip: tar jxvf FileName.tar.bz2 #Show the detailed decompression process       or tar --bzip xvf FileName.tar.bz2 #Does not display the detailed decompression process
 compression: tar jcvf FileName.tar.bz2 DirName

zip

zip all.zip *.jpg   #Compress all .jpg files into a zip package

unzip all.zip    #Unzip all files in all.zip into the current directory

unzip all.zip -d all #Unzip all files in all.zip into the all folder in the current directory

zip -r hy.zip hy  #Compress the hy folder in the current directory to hy.zip

zip -r hy.zip hy 123.txt  #Compress the hy folder and 123.txt in the current directory into hy.zip

2. Number of statistical files

  • Count the number of files in a directory
ls -l |grep "^-"|wc -l
  • Count the number of directories in a directory
ls -l |grep "^d"|wc -l
  • Count the number of files in a folder, including subfolders
ls -lR|grep "^-"|wc -l

3. After modifying the .bahsrc file, remember to use source to update the system variables

source ~/.bashrc

4. The bash file written under Windows reports an error under Linux

After writing the sh file under Windows, an error will be reported when running under Linux: bash: $'\r': command not found.
This is because Windows systems use \r\n for file wrapping, while Unix systems use \n

Solution: use vim Open sh Script to reformat the file
: set ff Then press Enter and reset the file format:
: set ff=unix then save and exit
: wq! Enter

5. GPU Memory Usage is full but GPU-Util is 0

The situation I have encountered is that although the python program ends, the process does not end, resulting in the memory usage of the graphics card.

Solution:

step1:fuser -v /dev/nvidia* View the process that occupies the graphics card (if you want to exit the container first in the container)
step2:kill -9 PID1 PID2 ... kill process

gpustat can monitor gpu usage per second:

watch -n1 --color gpustat

6. Linux Subsystem under Windows

The directory of the ubuntu Linux subsystem is in this directory

C:\Users\username\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs

The windows disk is mounted under /mnt and can be accessed directly

cd /mnt

The user directory of Window10 is under /mnt/c/Users/xxx, you can create a shortcut to access win10 in the WSL environment

$ ln -s /mnt/c/Users/xxx ~/win10 

So, go directly to the home directory of win10 through the following command under ubuntu

$ cd win10

Tags: Linux

Posted by daneth1712 on Wed, 25 May 2022 11:56:41 +0300