The following are commonly used commands in Ubuntu, prioritized according to the commands that are most likely to be forgotten, the top 50:
-
sudo
: Command to execute commands with administrator privileges in Ubuntu. Example: To edit a file with administrator privileges/etc/hosts
:sudo nano /etc/hosts
. -
apt-get
: Commands for installing, upgrading, and removing packages in Ubuntu. Example: installnginx
package:sudo apt-get install nginx
. -
grep
: A command for finding matching text in files or standard input, supporting various regular expressions and options. Example:example.txt
Findhello
lines in the file that contain the string:grep "hello" example.txt
. -
ps
: The command used to display the system process, supports various options and formats. For example: Display all process information of the current user:ps -u $USER -o pid,cmd,%cpu,%mem
. -
top
: A command used to monitor system processes and resource usage in real time, and supports interactive operations and multiple options. For example: real-time monitoring of system processes and resource usage:top
. -
df
: The command used to display the disk space usage of the file system, supports various options and formats. For example: display disk space usage:df -h
. -
du
: A command used to display the disk space usage of files or directories, supporting various options and formats. For example: Display the disk space usage of all files and subdirectories under the current directory:du -h
. -
ls
: The command used to display the list of files and directories in the current directory, supports multiple options and formats. For example: display a list of all files and directories under the current directory:ls -al
. -
cd
: The command used to switch the current working directory. For example: switch to/home/user
directory:cd /home/user
. -
mkdir
: The command used to create a new directory, supports various options.new_dir
For example: Create a new directory called: under the current directorymkdir new_dir
. -
rm
: A command to delete a file or directory, supporting various options and formats. For example: deletefile.txt
the file named in the current directory:rm file.txt
. -
mv
: Commands for moving or renaming files or directories, supporting various options and formats. For example: move the filefile.txt
to/home/user
the directory and rename it tonew_file.txt
:mv file.txt /home/user/new_file.txt
. -
cp
: Command for copying files or directories, supports various options and formats. Example:file.txt
copy the file to/home/user
chown
: Used to change the owner of a file or directory. A user with superuser privileges can change the owner and group of any file or directory.- Example:
sudo chown user1:group1 file.txt
, tofile.txt
change the owner of the file touser1
and the group togroup1
.
parameter:-R
: Recursively change the owner of a folder and its contents.--from=currentOwner:currentGroup
: Only change the owner and group of files or directories whose current owner and group match the specified values.--preserve-root
: Avoidchown
recursive change operations on the root directory by the command.
chmod
: Used to change the permissions of a file or directory. Permissions can be represented by numbers or symbols.
Example:chmod 755 file.txt
,file.txt
give the owner of the file read, write, and execute permissions (7), and the group and other users respectively give read and execute permissions (5).
parameter:-R
: Recursively change the permissions of a folder and its contents.u/g/o/a
: Indicates user (owner), group, other users, and all users, respectively.+/-=
:+
Indicates to add permissions,-
to delete permissions,=
to set specified permissions.r/w/x
: Indicates read, write, and execute permissions.
find
: Used to search for files or directories under the specified directory.
Example:find /home -name "*.txt"
,/home
find all.txt
files with the extension in the directory.
parameter:-name pattern
: Search for files or directories by name pattern.-type type
: Search for files or directories by type, such asf
for files ord
directories.-mtime n
: Search for files or directories by modification time, such as-mtime -1
to search for files modified within the last day.-size n
: Search for files or directories by size, for example,-size +10M
means to search for files whose size is greater than 10MB.
grep
: Used to search for the specified text pattern in the file.
Example:grep "error" log.txt
,log.txt
finds lines containing the text "error" in the file.
parameter:-i
: Search regardless of case.-n
: Displays the line number of the matching line.-v
: Inverts the match, showing the unmatched lines.-E
: Enable extended regular expressions, eggrep -E "pattern"
.
sed
: Used for string replacement and editing in text streams.
Example:sed 's/old/new/g' file.txt
, replacefile.txt
all occurrences of in the file with . parameter:old
new
-i
: Edit directly in the original file.-e
: multiple edit commands
-
curl
: Used to transfer data on the command line. Example:curl -o example.html https://www.example.com
, which means to downloadhttps://www.example.com
the content of the website and save it asexample.html
a file. -
tar
: Used to pack and compress files or directories in Linux. Example:tar -cvzf archive.tar.gz /path/to/directory
, means to/path/to/directory
package the files in the directory intoarchive.tar.gz
a compressed file. -
grep
: Used to search for a specified string or pattern in a text file. Example:grep 'example' file.txt
, which meansfile.txt
to search for lines containing the string in the fileexample
. -
sed
: Used to edit and convert text. Example:sed 's/old/new/g' file.txt
, means to replacefile.txt
allold
strings in the file withnew
. -
awk
: Used to process text files and generate reports. Example:awk '{print $1}' file.txt
, means tofile.txt
print the first word of each line in the file. -
ps
: Used to view the status of the current process. Example:ps aux
, means to display the detailed information of all processes in the current system. -
top
: Used to dynamically display the activity of the current process in the system. Example:top -u username
, which means to displayusername
the process with the user name . -
netstat
: Used to display network connection and statistics. Example:netstat -an
, which means to display the status of all network connections. -
traceroute
: Used to trace the path a packet takes from a computer to a destination address. Example:traceroute www.example.com
, which means to trackwww.example.com
the routing path accessed by . -
iptables
: Used to configure network firewall rules for Linux. Example:iptables -A INPUT -p tcp --dport 80 -j ACCEPT
, to allow TCP connections through port 80. -
ssh
: Used to remotely log into another computer and execute commands. Example:ssh [email protected]
, which means connecting to192.168.0.100
the computer with IP address anduser
authenticating with username . -
scp
: Used to copy files between a local computer and a remote computer. Example:scp file.txt [email protected]:/path/to/destination
, means to copy the localfile.txt
file to/path/to/destination
the directory of the remote computer. -
rsync
: Used to synchronize files and directories between local and remote computers. Example:rsync -avz /path/to/source [email protected]:/path/to/destination
, means to synchronize the local/path/to/source
directory to the remote computer's/path/to/destination
directory. -
find
: Used to find files and directories. Example:find /path/to/search -name "filename"
, means/path/to/search
to search for a file named under the directoryfilename
. -
locate
: Used to quickly find files and directories. Example:locate filename
, which means to find files containing in the file namefilename
. -
htop
: Used to dynamically display the activity of the current process in the system. Similar totop
the command, but provides more interactive features and information. Example:htop
, which startshtop
the program. -
ifconfig
: Used to configure and display the status of network interfaces. Example:ifconfig eth0
, which means to displayeth0
the status of the network interface named . -
route
: Used to view and configure the network routing table. Example:route -n
, means to display the routing table in the current system. -
ping
: Used to test the connectivity of the network connection. Example:ping www.example.com
, which means to testwww.example.com
the network connection to . -
chmod
: Used to modify the access permissions of a file or directory. Example:chmod 755 file.txt
, which meansfile.txt
set the permission of the file torwxr-xr-x
. -
gzip
: Used to compress files. Example:gzip file.txt
, which means tofile.txt
compress the file intofile.txt.gz
a file. -
gunzip
: Used to decompress files. Example:gunzip file.txt.gz
, means tofile.txt.gz
decompress the file intofile.txt
a file. -
zip
: Used to pack and compress files and directories. Example:zip archive.zip /path/to/directory
, means to/path/to/directory
package and compress the directory intoarchive.zip
a file. -
unzip
: Used to decompress files. Example:unzip archive.zip
, meansarchive.zip
extract the file to the current directory. -
curl
: Used to send HTTP requests on the command line. Example:curl http://www.example.com
, means towww.example.com
send an HTTP GET request to and display the response content. -
wget
: Used to download files from a web server. Example:wget http://www.example.com/file.txt
, which means to downloadhttp://www.example.com/file.txt
the file. -
history
: Used to display the history of previously executed commands. Example:history
, means to display all the commands executed before. -
grep
: Used to search for the specified text pattern in the file. Example:grep "pattern" file.txt
, which means to search for lines of textfile.txt
containing in the file .pattern
-
chown
: Used to modify the owner and group of a file or directory. Example:chown user:group file.txt
, means tofile.txt
set the owner of the file touser
and the group to which it belongsgroup
. -
tar
: Used to pack and compress files and directories. Example:tar -czvf archive.tar.gz /path/to/directory
, means to/path/to/directory
package and compress the directory intoarchive.tar.gz
a file. -
crontab
: Used to set up scheduled tasks. Example:crontab -e
, means to edit the scheduled task of the current user.