Comprehensive Guide to CentOS VPS: Features,
CentOS VPS (Virtual Private Server) is a widely preferr...
Linux is a powerful and widely used operating system, especially in server environments. Mastering basic Linux commands is essential for system administrators, developers, and anyone working with Linux servers. This guide introduces you to the most important Linux commands, explains what they do, and provides simple usage examples.
pwd
- Print Working DirectoryThe pwd
command shows the current directory you are working in.
Example:
pwd
Output:
/home/user
This indicates that you are in the /home/user
directory.
ls
- List Files and DirectoriesThe ls
command lists all files and directories in your current location.
Example:
ls
You can also use options like -l
for detailed output and -a
to show hidden files:
ls -la
cd
- Change DirectoryThe cd
command allows you to move between directories.
Example:
cd /home/user/Documents
To return to the previous directory, use:
cd ..
To go to your home directory:
cd ~
touch
- Create New FilesThe touch
command creates an empty file.
Example:
touch newfile.txt
This will create an empty file called newfile.txt
in the current directory.
cp
- Copy Files and DirectoriesThe cp
command copies files from one location to another.
Example:
cp file1.txt /home/user/Documents/
This copies file1.txt
to the /home/user/Documents/
directory.
mv
- Move or Rename FilesThe mv
command moves or renames files.
Example (Move):
mv file1.txt /home/user/Documents/
Example (Rename):
mv oldname.txt newname.txt
rm
- Remove Files and DirectoriesThe rm
command deletes files or directories.
Example (Delete a File):
rm file1.txt
Example (Delete a Directory):
rm -r /home/user/old_folder
⚠️ Be cautious when using
rm
, as it permanently deletes files.
cat
- View File ContentThe cat
command displays the contents of a file.
Example:
cat file1.txt
To view large files, use less
or more
for better navigation.
nano
and vim
- Edit Text Filesnano
: A beginner-friendly text editor.vim
: A more advanced editor with powerful features.Example (Edit file with nano):
nano file1.txt
After editing, press Ctrl + O to save and Ctrl + X to exit.
Example (Edit file with vim):
vim file1.txt
To enter edit mode, press i. To save and exit, press Esc, type :wq
, and press Enter.
chmod
- Change File PermissionsThe chmod
command changes file permissions.
Example (Make a File Executable):
chmod +x script.sh
Example (Set Permissions Using Numbers):
chmod 755 file1.txt
Here, 755
represents read, write, and execute permissions for the file owner, and read and execute permissions for others.
chown
- Change File OwnershipThe chown
command changes the owner of a file.
Example:
chown user:group file1.txt
This sets user as the file owner and group as the group owner.
top
- View Running ProcessesThe top
command shows system processes, CPU usage, and memory usage.
Example:
top
To exit, press q.
ps
- View Active ProcessesThe ps
command shows currently running processes for the current user.
Example:
ps aux
This shows a detailed list of all running processes.
df
- Disk Space UsageThe df
command displays available disk space.
Example:
df -h
The -h
option shows human-readable file sizes (KB, MB, GB).
du
- Disk Usage of Files and DirectoriesThe du
command shows the disk space used by specific files and directories.
Example:
du -sh /home/user/Documents
This displays the total size of the /home/user/Documents
directory.
ping
- Test Network ConnectivityThe ping
command checks if a host is reachable.
Example:
ping google.com
This sends ICMP packets to Google's server and reports the response time.
ifconfig
or ip
- View Network InterfacesThe ifconfig
or ip
command shows network interface information.
Example (Ifconfig):
ifconfig
Example (IP command):
ip a
netstat
- View Network ConnectionsThe netstat
command shows active network connections.
Example:
netstat -tuln
This shows TCP and UDP connections and the ports they are using.
whoami
- Display Current UserThe whoami
command shows the name of the currently logged-in user.
Example:
whoami
adduser
and useradd
- Create New UsersThe adduser
and useradd
commands create new users.
Example (adduser):
adduser newuser
Example (useradd):
useradd newuser
passwd
- Change PasswordThe passwd
command changes a user's password.
Example:
passwd newuser
apt-get
- Install, Update, and Remove PackagesFor Debian/Ubuntu systems, apt-get
is used to manage packages.
Update Package Lists:
sudo apt-get update
Upgrade Installed Packages:
sudo apt-get upgrade
Install New Package:
sudo apt-get install package_name
Remove Package:
sudo apt-get remove package_name
shutdown
- Shut Down the SystemTo shut down the system immediately:
sudo shutdown now
To schedule a shutdown after 10 minutes:
sudo shutdown +10
reboot
- Restart the SystemTo reboot the system:
sudo reboot
tar
- Archive FilesThe tar
command creates and extracts archives.
Create a .tar.gz Archive:
tar -czvf archive.tar.gz /path/to/files
Extract a .tar.gz Archive:
tar -xzvf archive.tar.gz
zip
and unzip
- Compress and Extract ZIP FilesCreate a ZIP File:
zip archive.zip file1.txt file2.txt
Extract a ZIP File:
unzip archive.zip
If you want a powerful Linux server to practice and master these commands, consider SurferCloud. SurferCloud offers Linux VPS with high performance, stable uptime, and global data centers. Whether you're a developer, student, or system administrator, SurferCloud's VPS can help you build and manage your projects efficiently.
CentOS VPS (Virtual Private Server) is a widely preferr...
Connecting to a Virtual Private Server (VPS) from a Mac...
Changing the default SSH port on Ubuntu is an effective...