echo "Hello World" # Print to screen
date # Display current date and time
cal # Display calendar
clear # Clear terminal screen
exit # Exit terminal
man <command> # Display manual for command
ls # List files and directories
ls -l # List with detailed information
ls -a # List including hidden files
cp file1 file2 # Copy file1 to file2
mv file1 file2 # Move or rename file1 to file2
rm file # Remove file
rm -r dir # Remove directory and contents
touch file # Create empty file or update timestamp
cat file # Display file contents
less file # View file contents page by page
head file # Display first 10 lines of file
tail file # Display last 10 lines of file
grep pattern file # Search for pattern in file
pwd # Print working directory
cd dir # Change directory to dir
cd .. # Move up one directory
cd ~ # Change to home directory
mkdir dir # Create directory
rmdir dir # Remove empty directory
chmod 755 file # Change file permissions
chown user file # Change file owner
chgrp group file # Change file group
uname -a # Display system information
df -h # Show disk usage
free -h # Show memory usage
top # Display running processes
ps aux # List all running processes
ps # Display your currently active processes
kill pid # Kill process with id pid
killall proc # Kill all processes named proc
bg # Lists stopped or background jobs
fg # Brings the most recent job to foreground
ping host # Ping host
wget url # Download file from url
curl url # Get contents of url
ssh user@host # Connect to host as user
scp file user@host:path # Copy file to remote host
cut -d: -f1 /etc/passwd # Cut out fields from file
sort file # Sort lines in file
uniq file # Remove duplicate lines from file
sed 's/foo/bar/g' file # Replace foo with bar in file
awk '{print $1}' file # Print first field of each line
#!/bin/bash # Shebang line
# This is a comment
echo "Hello, World!"
NAME="John" # Declare variable
echo $NAME # Access variable
readonly NAME # Make variable read-only
unset NAME # Remove variable
if [ "$a" -eq "$b" ]; then
echo "a is equal to b"
elif [ "$a" -gt "$b" ]; then
echo "a is greater than b"
else
echo "a is less than b"
fi
case "$variable" in
"$condition1" ) command1;;
"$condition2" ) command2;;
* ) default command;;
esac
for i in 1 2 3 4 5
do
echo "Welcome $i times"
done
while [ $counter -le 10 ]
do
echo $counter
((counter++))
done
until [ $counter -gt 10 ]
do
echo $counter
((counter++))
done
function_name() {
echo "This is a function"
}
function_name # Call the function
function func_with_params() {
echo "First parameter: $1"
echo "Second parameter: $2"
}
func_with_params param1 param2
echo "Enter your name:"
read name
echo "Hello, $name"
# Redirect stdout to file
echo "Hello" > output.txt
# Append stdout to file
echo "World" >> output.txt
# Redirect stderr to file
ls /non_existent_directory 2> error.log
# Redirect both stdout and stderr to file
ls /non_existent_directory &> output_and_error.log
command & # Run command in background
jobs # List background jobs
fg %1 # Bring job 1 to foreground
bg %1 # Send job 1 to background
ctrl-z # Suspend current job
ctrl-c # Terminate current job
2024 © All rights reserved - buraxta.com