Selected systems from the Debian family
Selected systems from the Red Hat family
Selected systems from the Arch family
Listing the contents of the current directory
ls
Full listing of directory contents
ls -l
Full listing of directory contents including hidden entries
ls -la
Listing the contents of a directory using the full path as an argument
ls /boot
Listing the contents of a directory using options and an argument
ls -lh /boot
Quick help for the ls
command
ls --help
User manual for the ls
command
man ls
/ root directory of the entire file system hierarchy /bin essential binary command files /boot boot loader files /dev device files /etc system configuration files /home home directory for user files /lib shared libraries and kernel modules /media mount points for removable media /mnt temporary mount point for ordinary file systems /opt add-on application software packages /proc virtual file system providing process information /root home directory for the root user /run system information since the last boot /sbin essential system binaries /srv data for services provided by this system /tmp temporary files /usr secondary hierarchy for user data, containing binary and library files /var files that can change in size
Creating an empty file
touch system.txt
Creating a directory
mkdir linux
Deleting a file
rm system.txt
Deleting a directory with its contents
rm -r linux
Prepare files
mkdir linux files
touch system.txt
Copying a file to another existing directory
cp system.txt linux
Duplicating a file
cp system.txt system_copy.txt
Recursively copying a directory
cp -r linux linux_copy
Moving a file to another existing directory
mv system_copy.txt linux_copy
Moving a directory to another existing directory
mv linux_copy files
Renaming a file
mv system.txt os.txt
Listing the contents of directories in a tree format
sudo apt install tree
tree
--
.
├── files
│ └── linux_copy
│ ├── system_copy.txt
│ └── system.txt
├── linux
│ └── system.txt
└── os.txt
3 directories, 4 files
--
Renaming a directory
mv files/linux_copy files/copy
Prepare files
echo Linux > os.txt
echo Windows, Linux, macOS > new.txt
Searching for files and directories with a given name in the current directory
find . -name "os.txt"
Searching for files and directories with a given name in a specific directory
find / -name "os.txt"
Searching for files containing specific text
grep "Linux" new.txt
Displaying the content of a text file
cat os.txt
Displaying the content of a text file with line numbers
nl os.txt
Viewing the first few lines of a text file
head os.txt
Viewing the last few lines of a text file
tail os.txt
Displaying the content of a text file with a pager
less os.txt
Creating a compressed archive with the tar
command
tar -czvf archive.tar.gz os.txt
Extracting files from a compressed archive
tar -xzvf archive.tar.gz
Creating a compressed archive with the zip
command
zip archive.zip os.txt
Extracting files from a compressed archive
unzip archive.zip
Opening a text file in the ‘nano’ text editor:
nano os.txt
Replacing text in a file using ‘sed’
echo "Hello, World!" > greeting.txt
sed -i 's/Hello/Hi/' greeting.txt
Running a command and using its output as an argument for another command
ls -l /bin/$(which nano)
Defining and displaying a variable
MY_VAR="Hello, Shell!"
echo $MY_VAR
Displaying the contents of the .bashrc
file
cat ~/.bashrc
Editing the .bashrc
file
nano ~/.bashrc
Redirecting the output of a command to a file
ls -l > list.txt
Redirecting the output of a command and appending it to a file
ls -l >> list.txt
Redirecting the input of a command from a file
cat < os.txt
Listing file permissions
ls -l os.txt
Displaying the owner of a file
ls -l os.txt
Changing file permissions using absolute mode
chmod 644 os.txt
Changing file permissions using symbolic mode
chmod u+x os.txt
Changing the owner of a file
chown user1 os.txt
Changing the group of a file
chown :group1 os.txt
Viewing the current umask value
umask
Changing the umask value
umask 022
Changing the owner and group of a file
chown user1:group1 os.txt
Listing running processes
ps
Listing all processes
ps aux
Displaying information about a specific process
ps -p 1
Searching for processes by name
pgrep systemd
Viewing process states
man ps
Sending signals to processes
kill -9 1234
Stopping a process
killall process_name
Viewing the boot program configuration
cat /etc/default/grub
Updating the boot program configuration
update-grub
Viewing the current runlevel
runlevel
Changing the current runlevel
init 3
Viewing the system initialization configuration
ls /etc/rc*.d/
Displaying the status of a service
systemctl status ssh
Starting a service
systemctl start ssh
Stopping a service
systemctl stop ssh
Restarting a service
systemctl restart ssh
Adding a user account
adduser user1
Changing the password of a user
passwd user1
Deleting a user account
deluser user1
Enforcing password policies
cat /etc/security/pwquality.conf
cat /etc/security/pwquality.conf.d/common-password
Creating a group
groupadd group1
Adding a user to a group
usermod -aG group1 user1
Changing user account properties
usermod -s /bin/bash user1
Displaying user privileges
sudo -l
Connecting to a remote server using SSH
ssh user1@remote_server
Transferring files securely using SCP
scp file.txt user1@remote_server:/path/to/destination
Transferring files using rsync
rsync -avz source_directory/ user1@remote_server:/path/to/destination/
Viewing network interfaces
ifconfig
Viewing routing tables
route
Installing Apache web server
apt install apache2
Configuring the Apache web server
nano /etc/apache2/sites-available/000-default.conf
Displaying the firewall status
ufw status
Allowing traffic on a specific port
ufw allow 80/tcp
Displaying the HAProxy configuration
cat /etc/haproxy/haproxy.cfg
Displaying system information
top
Viewing memory usage
free -m
Listing running tasks
ps aux
Killing a task
kill -9 process_id
Viewing system logs
cat /var/log/syslog
Updating the package database
apt update
Upgrading installed packages
apt upgrade
bash
shell programmingCreating a shell script
nano my_script.sh
Running a shell script
./my_script.sh
Checking the exit status of a command
echo $?
Using conditional statements in shell scripts
if [ condition ]; then
# Code to run if the condition is true
else
# Code to run if the condition is false
fi
Defining and calling a function in a shell script
my_function() {
# Function code here
}
my_function # Calling the function