- Change directory:
cd /path/to/directory - Go to the home directory:
cd ~ - Go to the previous directory:
cd - - List files and directories:
ls - List detailed file info:
ls -l - List hidden files:
ls -a
- Copy files:
cp source destination - Copy directories:
cp -r source_dir destination_dir - Move or rename files:
mv source destination - Delete files:
rm file.txt - Delete directories:
rm -r directory_name - Create a new file:
touch file.txt - Create a new directory:
mkdir directory_name - Remove an empty directory:
rmdir directory_name
- Display file content:
cat file.txt - View file content one page at a time:
less file.txt - Display the first 10 lines of a file:
head file.txt - Display the last 10 lines of a file:
tail file.txt - Follow a file in real-time:
tail -f file.txt
- Edit files using
nano:
nano file.txt - Edit files using
vim:
vim file.txt
- Change file permissions (e.g.,
rwx):
chmod 755 file.txt - Change directory permissions recursively:
chmod -R 755 directory_name
- Change file owner:
chown user file.txt - Change file owner and group:
chown user:group file.txt - Change ownership recursively:
chown -R user:group directory_name
- Search for a file by name:
find /path -name "filename" - Search for files by extension:
find /path -name "*.txt"
- Search for text in a file:
grep 'pattern' file.txt - Search recursively in a directory:
grep -r 'pattern' /path
- Check disk space usage:
df -h - Check directory or file size:
du -sh /path
- Display system information:
uname -a - Show current logged-in users:
who - Display memory usage:
free -h - Show running processes:
top - Display detailed process list:
ps aux
- Display IP address:
ip addr - Test network connectivity:
ping example.com - Display open network ports:
netstat -tuln
- Copy files between systems:
scp file.txt user@remote:/path - Download files using
wget:
wget http://example.com/file.zip
- Show current running processes:
ps aux - Kill a process by PID:
kill PID - Kill a process by name:
pkill process_name
- Run a command in the background:
command & - List background jobs:
jobs - Bring a background job to the foreground:
fg %job_number
- Add a new user:
sudo useradd username - Change a user's password:
sudo passwd username - Add a user to a group:
sudo usermod -aG groupname username
- Switch to another user:
su - username - Execute a command as another user:
sudo command
- Create a
.tararchive:
tar -cvf archive.tar file_or_directory - Create a compressed
.tar.gzarchive:
tar -czvf archive.tar.gz file_or_directory
- Extract a
.tararchive:
tar -xvf archive.tar - Extract a
.tar.gzarchive:
tar -xzvf archive.tar.gz
- Update package list:
sudo apt update - Upgrade all packages:
sudo apt upgrade - Install a package:
sudo apt install package_name - Remove a package:
sudo apt remove package_name
- Install a package:
sudo yum install package_name
sudo dnf install package_name - Remove a package:
sudo yum remove package_name
sudo dnf remove package_name
- Update package list:
sudo pacman -Sy - Upgrade all packages:
- Install a package:
sudo pacman -S package_name - Remove a package:
sudo pacman -R package_name- Search for a package:
pacman -Ss search_term
- Install a package:
yay -S package_name - Remove a package:
yay -R package_name - Search for a package:
yay -Ss search_term
- Assign a variable:
variable_name="value" - Print a variable:
echo $variable_name - Run a shell script:
bash script.sh
-
Example
forloop:for i in {1..5}; do echo $i done
-
Example
ifstatement:if [ condition ]; then echo "Condition met" fi
- Show command history:
history - Create a command alias:
alias ll='ls -la'
- Display current working directory:
pwd - Change the hostname:
sudo hostname new_hostname