File and Directory Management
-
ls
: Show a list of files and directories in the current directory. This command allows you to view the contents of the current directory.Example:
ls
-
pwd
: Print the absolute path of the current directory. This command helps you know where you are in the file system.Example:
pwd
-
cd <directory>
: Change to the specified directory. By using this command, you can navigate between directories in your file system.Example:
cd /home/user/documents
-
touch <file>
: Create a new file or update the modification time of an existing file. If the file already exists, it will update the modification time.Example:
touch newfile.txt
-
cp <source> <destination>
: Copy a file or directory from the source location to the destination location. You can copy multiple files or directories by specifying multiple sources.Example:
cp file.txt /home/user/documents/
(copy a file)cp -r folder1 /home/user/documents/
(copy a directory)
-
mv <source> <destination>
: Move or rename a file or directory from the source location to the destination location. If the destination is a new name, it will rename; if it is a new path, it will move.Example:
mv file.txt /home/user/documents/file_new.txt
(rename a file)mv folder1 /home/user/documents/
(move a directory)
-
rm <file>
: Delete a file. Note that this command will delete the file without any confirmation, so use it carefully.Example:
rm file.txt
-
mkdir <directory>
: Create a new directory with the specified name.Example:
mkdir new_folder
-
rmdir <directory>
: Delete an empty directory. Note that you can only delete an empty directory with this command.Example:
rmdir empty_folder
Permission Management
-
chmod <permission> <file/directory>
: Change the access permissions of a file or directory according to the specified permission. Common permissions include "r" (read), "w" (write), and "x" (execute).Example:
chmod u+rwx file.txt
(add read, write, and execute permissions for the user) -
chown <user>:<group> <file/directory>
: Change the owner of a file or directory to the specified user and group.Example:
chown user1:group1 file.txt
(set owner and group for file.txt)
Process and Service Management
-
ps
: List running processes. This command displays a list of processes and their corresponding Process IDs (PIDs).Example:
ps
-
top
: Display running processes and system resources. This command provides an interactive interface to view running processes and monitor system resources such as CPU, RAM.Example:
top
-
kill <PID>
: Terminate a process with the specified Process ID (PID). This command sends a signal to stop the process, allowing it to exit or shut down.Example:
kill 1234
(terminate the process with PID 1234) -
systemctl start <service>
: Start the specified service. A service is a background program of the system, and this command starts it.Example:
systemctl start apache2
(start the Apache service) -
systemctl stop <service>
: Stop the specified service. This command stops the running service.Example:
systemctl stop apache2
(stop the Apache service) -
systemctl restart <service>
: Restart the specified service. This command stops and then starts the service.Example:
systemctl restart apache2
(restart the Apache service) -
systemctl status <service>
: Show the status of the specified service. This command displays whether the service is running or not and its status.Example:
systemctl status apache2
(show the status of the Apache service)
Package Management
-
apt-get install <package>
: Install a software package from the Ubuntu repository.Example:
apt-get install nginx
(install Nginx) -
apt-get update
: Update the information of all software packages from the repository. This command will fetch information about the latest packages from the repository.Example:
apt-get update
-
apt-get upgrade
: Upgrade all installed packages to the latest version.Example:
apt-get upgrade
-
apt-get remove <package>
: Remove an installed package from the system.Example:
apt-get remove nginx
(remove Nginx)
Network Management
-
ifconfig
: Display information about network devices and IP addresses of the system.Example:
ifconfig
-
ip addr
: Display information about network devices and IP addresses of the system. This command is similar toifconfig
.Example:
ip addr
-
ping <domain/IP>
: Check network connectivity to a specified IP address or domain name by sending packets and waiting for a response.Example:
ping google.com
-
curl <URL>
: Retrieve the content from a URL. This command is commonly used to download data from a website and display the result on the command line.Example:
curl https://www.example.com
Command History Management
-
history
: Show the history of previously executed commands. This command lists the commands that have been executed in the current session.Example:
history
These are some common and useful command line commands in Ubuntu. Depending on your needs and purposes, you can use these commands to manage your system and perform various basic tasks.