Common Commands
ls Display files or directories
-l List detailed file information l(list)
-a
List all files and directories in the current directory, including hidden ones a(all)
mkdir Create directory
-p Create directory; if the parent directory does not exist, create it p(parent)
cd Switch directory
touch Create empty file
echo Create a file with content.
cat View file contents
cp Copy
mv Move or rename
rm Delete file
-r Recursively delete; can delete subdirectories and files
-f Force delete
find Search for a file in the file system
wc Count lines, words, and characters in text
grep Search for a string in a text file
rmdir Delete empty directory
tree Display directories in a tree structure; the tree package must be installed
pwd Display current directory
ln Create link file
more、less Display text file contents page by page
head、tail Display the beginning and end of a file
ctrl+alt+F1 Command-line full-screen mode
stat
Display detailed information for the specified file, more detailed than ls
who Display logged-in users
whoami Display the current operating user
hostname Display hostname
uname Display system information
top
Dynamically display information about the processes currently consuming the most resources
ps shows the current process status ps -aux
du check directory size du -h
/home displays directory information with units
df check disk size df -h
displays disk information with units
ifconfig check network status
ping test network connectivity
netstat display network status information
man If you don’t know how to use a command, look it up with man, for example: man
ls
clear clear the screen
alias rename a command, for example: alias
showmeit=”ps -aux”
, and to remove it use unaliax showmeit
kill kill a process. You can first use the ps or
top command to check the process ID, and then use the kill command to terminate the process.
Packaging and Compression Commands
gzip:
bzip2:
tar: package and compress
-c archive files
-x extract files
-z compress files with gzip
-j compress files with bzip2
-v show the compression or extraction process v(view)
-f use file name
Example:
tar -cvf /home/abc.tar /home/abc
package only, no compression
tar -zcvf /home/abc.tar.gz /home/abc
package and compress with gzip
tar -jcvf /home/abc.tar.bz2 /home/abc
package and compress with bzip2
Of course, if you want to extract, simply replace the “c” in the commands above tar
-cvf / tar -zcvf / tar -jcvf with “x”
and that’s it.
Shut down / Restart the machine
shutdown
-r Shut down and restart
-h Shut down without restarting
now Shut down immediately
halt Shut down
reboot Restart
Use the standard output of one command as the standard input of another command. In other words, combine several commands together so that each subsequent command processes the result of the previous one.
Example: grep -r “close” /home/* | more
Search all files in the home directory, including those containing close, and display the output page by page.
dpkg (Debian
Package) management tool. Package names use the .deb suffix. This method is suitable when the system cannot connect to the Internet.
For example, to install the package for the tree command, first transfer tree.deb to the Linux system, then use the following command to install it.
sudo dpkg -i tree_1.5.3-1_i386.deb
Install software
sudo dpkg -r tree
Uninstall software
Note: There are many ways to transfer tree.deb to the Linux system, such as VMwareTool using a mounted method, or using tools like winSCP.
APT(Advanced Packaging
Tool)advanced package tool. This method is suitable when the system can connect to the Internet.
Still using tree as an example
sudo apt-get install tree
Install tree
sudo apt-get remove tree
Uninstall tree
sudo apt-get update
Update software
sudo apt-get upgrade
Convert a .rpm file to a .deb file
.rpm is the software package format used by RedHat. It cannot be used directly on Ubuntu, so it needs to be converted.
sudo alien abc.rpm
vim has three modes: command mode, insert mode, and edit mode. Use ESC, i, or : to switch modes.
In command mode:
:q Quit
:q! Force quit
:wq Save and quit
:set number Show line numbers
:set nonumber Hide line numbers
/apache Search for apache in the document
Press n to jump to the next one, shift+n for the previous one
yyp Copy the current line and paste it
h(move left one character ←), j(next line ↓), k(previous line ↑), l(move right one character →)
User and user group management
/etc/passwd Stores user accounts
/etc/group Stores group accounts
/etc/shadow Stores passwords for user accounts
/etc/gshadow Stores passwords for user group accounts
useradd username
userdel username
adduser username
groupadd group name
groupdel group name
passwd root Set a password for root
su root
su – root
/etc/profile System environment variables
bash_profile User environment variables
.bashrc User environment variables
su user Switch user and load the .bashrc configuration file
su – user
switch user, load the configuration file /etc/profile
, load bash_profile
Change the owner and group of a file
sudo chown [-R] owner[:group] {File|Directory}
For example: again using jdk-7u21-linux-i586.tar.gz. It belongs to user hadoop, group hadoop
If you want to change the owning user and group of this file, you can use the command.
sudo chown root:root jdk-7u21-linux-i586.tar.gz
Three basic permissions
R read represented numerically as 4
W write represented numerically as 2
X executable represented numerically as 1

As shown in the figure, the permissions of the jdk-7u21-linux-i586.tar.gz file are -rw-rw-r–
-rw-rw-r– has a total of ten characters, divided into four sections.
The first character “-” indicates a regular file; “l” may also appear in this position for a link; “d” indicates a directory
The second, third, and fourth characters “rw-” indicate the permissions of the current owning user.
So numerically this is 4+2=6
The fifth, sixth, and seventh characters “rw-” indicate the permissions of the current owning group.
So numerically this is 4+2=6
The eighth, ninth, and tenth characters “r–” indicate the permissions of other users.
So numerically this is 2
So the permissions for operating this file are represented numerically as 662
Change permissions
sudo chmod [u owning user g owning group o other users
a all users] [+ add permission – remove permission] [r w x]
directory name
For example: there is a file filename with permissions “-rw-r—-x”
, change the permission value to ”-rwxrw-r-x”, which is represented numerically as 765
sudo chmod u+x g+w o+r filename
The above example can be represented numerically as
sudo chmod 765 filename