Common Debian (Ubuntu) Commands Every User Should Know

Switch to superuser with sudo – i; using su –
root requires entering the root password

View CPU information: cat/proc/cpuinfo
View memory information cat/proc/meminfo
View hard disk information fdisk -l

Check CPU bitness: getconf LONG_BIT
ls   if there is a lib64 folder under root when running ls, it means the system is 64-bit

ls is a commonly used command for viewing file information. ls-la and ls -lla(ls
-llla) have the same effect; both display detailed file attributes, including the last edit date, creation date, size
View memory information: more /proc/meminfo
grep MemTotal /proc/meminfo

Installation: network installation
apt-get install package (package name)
ls –lh: observe the permission ownership and file sizes of directories created by the linuxsir user

Check Linux system version and system bitness: uname -a

x86_64 means you have a 64-bit kernel and are running a 64-bit system.
i386, i686 mean you have a 32-bit kernel and are running a 32-bit system

cat /proc/version
cat /etc/issue
lsb_release -a (suitable for all Linux operating systems)
Check gcc version gcc –v

The contents of /etc/group
include the user group (Group), group password, GID, and the users (User) contained in the group, with one record per group; the format is as follows:
group_name:passwd:GID:user_list
Each record in /etc/group consists of four fields:
First field: group name;
Second field: group password;
Third field: GID. Like UID, GID is a positive integer or 0. GID starts from 0, and the group with GID 0 is assigned by the system to the root group; the system reserves some lower GIDs for system virtual users
(also called pseudo-users); the reserved GIDs differ from system to system,
Fourth field: user list, with users separated by commas; this field may be empty; if the field is empty, it indicates the username corresponding to the group’s GID;
etc/gshadow is the encrypted information file for /etc/group
The format is as follows, with each user group occupying one line;
First field: user group
Second field: group password; this field may be empty or !, and if it is empty or contains !, it means there is no password;
Third field: group administrators; this field may also be empty, and if there are multiple group administrators, they are separated by commas;
Fourth field: group members; if there are multiple members, they are separated by commas;

View user information by checking the configuration files for users and groups: cat
/etc/passwd
Use the id and finger tools to obtain user information;
Usage of the id command: id options username
Usage of finger: finger options username1 username2 …
Query the groups a user belongs to with groups
User and group management tools (such as adduser, userdel, usermod
,userinfo, groupadd ,groupdel ,groupmod)

Managing users by modifying the User and Group configuration files — the process for adding a user:
1) Modify /etc/passwd and add a user entry; note that the UID
must not be duplicated;
Then run pwconv to synchronize /etc/passwd and /etc/shadow, and you can check
whether the contents of /etc/shadow have been synchronized;

2) Modify /etc/group
Run grpconv to synchronize /etc/group
and the contents of /etc/gshadow; you can confirm whether the group was added successfully by checking the changes in /etc/gshadow;

3) Create the user’s home directory, and copy the user startup files there as well;
4) Change the owner and permissions of the newly added user’s home directory;
Use the chown -r command to make the change
Change the ownership of /home/lanhaitun to the user lanhaitun;
[[email protected]
~]# chown -R lanhaitun:lanhaitun /home/lanhaitun
Check whether the owner has been changed to the user lanhaitun;
[[email protected]
~]# ls -ld /home/lanhaitun/
Set the permissions of the new user’s home directory so that only the user can read, write, and execute;
chmod 700 /home/lanhaitun/
5) Set the new user’s password using the passwd command;
6) Test whether the user was added successfully;
You can test by logging in with the new user, or by switching users with su;

Modify a user or user group by editing the User and Group configuration files
1) Modify user information;
lanhaitun:x:508:508::/home/lanhaitun:/bin/bash
Note: this is the initial record;
We can change it to
lanhaitun:x:508:508:lanhaitun wu,Office
Dalian,13000000000:/home/lanhaitun:/bin/bash
After the modification is complete, we need to run pwconv to synchronize, and use finger
to view the user’s information, etc.;
2) To modify the group a user belongs to, this can be done by editing /etc/group;
If we want to assign the user lanhaitun
to the root user group, we can also achieve this by modifying /etc/group
; find the line in /etc/group
that starts with root, and add lanhaitun according to its format;
root:x:0:root,lanhaitun
Run the grpconv command to synchronize the contents of the two files /etc/group
and /etc/gshadow
3) How to delete users and user groups
By deleting the corresponding user and user group records in /etc/passwd and /etc/group
, this goal can be achieved, or it can also be done with userdel
and groupdel to delete users and user groups;
If you delete a user by editing the user and user group configuration files, you only need to delete the corresponding records. If you do not want to keep the home directory, just delete it as well.
[[email protected]
~]# userdel lanhaitun
[[email protected]
~]# userdel -r lanhaitun
Note: you can use userdel to delete the user lanhaitun
. In the second example, we can see one extra parameter, -r
. The first example means only deleting the user lanhaitun, while its home directory and mail, etc. will still be kept; adding the -r
parameter deletes the home directory and mail, etc.; so operate carefully; when using userdel
to delete a user, its user group will also be deleted at the same time; we can check this through the changes in the contents of /etc/passwd
and /etc/group;

In Debian, uninstalling software is divided into two methods: keeping configuration files and completely removing them:
aptitude install foo bar-

Install the foo package and remove the bar package.

aptitude remove bar

Remove the bar package, but keep its configuration files.

aptitude purge bar

Remove the bar package and all of its configuration files.

Search for and install gvim
apt-cache search gvim
apt-get install gvim

Detailed usage of the df command — this is common across Linux platforms
a: display all file systems and the disk usage of each partition
i: display i-nodes usage
k: show sizes in k (default)
t: display the disk usage of all partitions for a certain file system
x: display the disk usage of all partitions that are not of a certain file system
T: display the file system name for each partition
-h
means using “Human-readable” output, that is, showing file system sizes in
easy-to-read formats such as GB and MB.

Common command: df -hi

Detailed operation guide

Quote
The df command can display the maximum available space and usage status of all current file systems

free -k: view system memory usage

grep ‘^Memory’ /var/log/dmesg
: view the exact size of physical memory

du view the exact size of a folder

How to open tar.gz2? Command format: tar -xjvf tar.gz2 filename

Change Debian default encoding
Configure your locale by running dpkg-reconfigure locales
and select the locale you want to use.

Check the status of a port: (common on Linux)
netstat-an|grep port or lsof -i:port number
Open a port: nc -lp port number

 

To open rar files on Debian, download rar and unrar, then install with make and make
install
If you get an error like libstdc++.so.6 not found while using the rar command, it is recommended to delete it first, then
download an older version. If after installation libstdc++.so.5 cannot be found, run apt-get
install  libstdc++.so.5
You can also use ldd -v the absolute path of rar to view the related dynamic library information ;
If after reinstalling the problem still remains, and libstdc++.so.6 already exists in the /usr/lib and /usr/local/lib directories,
then just copy rar from /usr/bin to /usr/local/bin

Change Debian default encoding
Configure your locale by running dpkg-reconfigure locales
and select the locale you want to use,
for example: en_US.UTF-8 zh_CN.GB2312 zh_CN.UTF-8 zh_CN.GB18030
zh_CN.GBK ,

Commands to view detailed CPU information
Check how many logical cores the system has: cat /proc/cpuinfo | grep
“processor” | wc -l
Check the number of physical CPU cores in the system: cat /proc/cpuinfo | grep “cpu
cores” | uniq
Check whether CPU hyper-threading is enabled on the system: cat /proc/cpuinfo | grep -e
“cpu cores” -e “siblings” | sort |
uniq
Example output:
cpu cores : 6
siblings : 6
If the number of cpu
cores is the same as the number of siblings, then hyper-threading is not enabled; otherwise, hyper-threading is enabled.
Check the number of CPUs in the system: cat /proc/cpuinfo | grep “physical
id” | sort | uniq | wc -l

By using the command cat
/proc/cpuinfo, you can view detailed CPU information. Below is an explanation of some specific parameters:

processor
: The number of a logical processing core in the system. For a single-core processor, it can be regarded as the CPU number; for a multi-core processor, it can refer to a physical core or a logical core virtualized using hyper-threading technology
vendor_id : CPU manufacturer
cpu family : CPU product family code
model : The code indicating which generation within its family the CPU belongs to
model name: The CPU name, model number, and rated clock speed
stepping : The CPU’s revision version
cpu MHz : The CPU’s actual operating clock speed
cache size : CPU L2 cache size
physical id : The ID number of a single CPU
siblings : The number of logical physical cores of a single CPU
core id
: The number of the current physical core within the CPU it belongs to; this number is not necessarily consecutive
cpu cores : The number of physical cores in the CPU where this logical core resides
apicid
: A number used to distinguish different logical cores. This number must be different for each logical core in the system and is not necessarily consecutive
fpu : Whether it has a floating-point unit (Floating Point Unit)
fpu_exception : Whether floating-point exception handling is supported
cpuid level
: The value in the eax register before executing the cpuid instruction. Depending on the value, the cpuid instruction returns different content
wp : Indicates whether the current CPU supports write protection for user space in kernel mode (Write
Protection)
flags : Features supported by the current CPU
bogomips : The CPU speed roughly estimated during system kernel startup (Million Instructions
Per Second)
clflush size : The unit size for each cache flush
cache_alignment : Cache address alignment unit
address sizes : Number of bits in the address space that can be accessed
power management
: Support for power management, including the following optional features:

ts: temperature sensor

fid: frequency id control

vid: voltage id control

ttp: thermal trip

tm:

stc:

100mhzsteps:

hwpstate:

 

Meanings of the various flags in the CPU information:

fpu: Onboard (x87) Floating Point Unit
vme: Virtual Mode Extensions
de: Debugging Extensions
pse: Page Size Extensions
tsc: Time Stamp Counter: support for RDTSC and WRTSC
instructions
msr: Model-Specific Registers
pae: Physical Address Extensions: the ability to access 64GB of
memory; however, only 4GB can be accessed at a time
mce: Machine Check Architecture
cx8: CMPXCHG8 instruction
apic: Onboard Advanced Programmable Interrupt Controller
sep: Sysenter/Sysexit Instructions; SYSENTER is used for
jumps to kernel memory during system calls, and SYSEXIT is
used for jumps back to user code
mtrr: Memory Type Range Registers
pge: Page Global Enable
mca: Machine Check Architecture
cmov: CMOV instruction
pat: Page Attribute Table
pse36: 36-bit Page Size Extensions: allows mapping 4 MB
pages into the first 64GB of RAM, used with PSE.
pn: Processor Serial Number; only available on Pentium 3
clflush: CLFLUSH instruction
dtes: Debug Trace Store
acpi: ACPI via MSR
mmx: MultiMedia Extension
fxsr: FXSAVE and FXSTOR instructions
sse: Streaming SIMD Extensions. Single instruction, multiple
data. Lets you perform the same operation on different
pieces of input in a single clock cycle.
sse2: Streaming SIMD Extensions-2. More of the same.
selfsnoop: CPU self-snoop
acc: Automatic Clock Control
IA64: IA-64 Itanium processor.
ht: Hyper-Threading. Introduces an imaginary second
processor that doesn’t do much but lets you run threads in
the same process a bit faster.
nx: No Execute bit. Prevents arbitrary code from running via
buffer overflows.
pni: Prescott New Instructions, aka SSE3
vmx: Intel Vanderpool hardware virtualization technology
svm: AMD “Pacifica” hardware virtualization technology
lm: “Long Mode,” which means the chip supports the AMD64
instruction set
tm: “Thermal Monitor” Thermal throttling with IDLE
instructions. Usually hardware-controlled in response to CPU
temperature.
tm2: “Thermal Monitor 2” Reduces speed by lowering the
multiplier and vcore.
est: “Enhanced SpeedStep”

Based on the above, we can easily determine information about the current system’s CPU, the number of CPU cores, and whether CPU hyper-threading is enabled.

Check port status: lsof (lsof -i:port number) or netstat (netstat
-an|grep port number)
netstat -a: view all connections
View all open ports: ss
netstat -tanp
t stands for TCP socket connections; besides t, there are also u (UDP), w (RAW), and x (UNIX) sockets.
a stands for all; this “all” includes ports that are currently being listened on. At any given moment, some open ports are transmitting data, while others are only listening.
n: display port numbers directly, instead of showing the service names corresponding to the ports based on “/etc/server”
p: display the process occupying the port number.
l: display ports that are being listened on.

Use chkconfig to view service status
chkconfig
–list: view services (or programs) that can start automatically at different runlevels
If you want to change the auto-start options, the command format is:
chkconfig –level x name on/off
You can also view the file /etc/services to find the service corresponding to a port

Start the Apache service: /etc/init.d/apache2 start
Stop the Apache service: /etc/init.d/apache2 stop
Kill the Apache server: killall apache2
Install Apache: aptitude install apache2 apache2-utils

Update the system time: apt-get -y install ntpdate;ntpdate
0.us.pool.ntp.org
View the system time: date

View the startup path of a process
Use lsof -i:port number to get the pid
ls -al /proc/pid/exe

Create a command alias: add alias
alias=’command’ to the end of /etc/bash.bashrc
source /etc/bash.bashrc to make it take effect immediately

The source command is often replaced with “.”; source executes commands in the current bash environment, while scripts start a child shell to execute commands. Therefore, if commands for setting environment variables (or aliases, etc.) are written into scripts, they will only affect the child shell and cannot change the current BASH. So when setting environment variables through a file (command line), you should use the source
command.

Automatically run programs at startup: edit the /etc/rc.d/rc.local
file, add the startup command at the end of the file, and after booting it can directly enter that command or process

Leave a Comment

Your email address will not be published. Required fields are marked *

中文 EN
🚀

RedGate VPN

免费节点太挤太慢?
升级高速稳定专线

立即体验 →

告别卡顿

RedGate VPN
全球高速节点

免费下载 →
Scroll to Top