Skip to content

Basic Commands

  • ls , pwd , cd

  • mkdir, rmdir, rm -r → remove non-empty dirs

  • touch , cat > file.ext → overrides, cat >> file.ext → appends, cat file.ext → prints

  • find <dir/path> -name “expression” → expression is CASE SENSITIVE

    image.png

    • use iname for IGNORE CASE SENSITIVE..

      image.png

  • find <dir/path> -type <f/d> -name “exp” → f for files, d for dirs

  • more find commands - https://www.tecmint.com/35-practical-examples-of-linux-find-command/

    • find all .txt files and remove them..
      • find . -type f -name "*.txt" -exec rm -f {} \;
    • Find Directories with 777 Permissions and chmod to 755
      • find / -type d -perm 777 -print -exec chmod 755 {} \;
    • find / -type f ! -perm 777 - files without having 777 permissions
    • Find Last 50 Days Modified Files - find / -mtime 50
    • Find Last 50 Days Accessed Files - find / -atime 50
    • 50 to 100 - find / -mtime +50 –mtime -100
    • find / -mmin -60 - modified in last
      • accessed - find / -amin -60
  • man → manual

  • mv [source_directory] [destination_directory] - also works for files..

  • cp -r [source_directory] [destination_directory] - just remove -r to work with files

image.png

image.png

image.png

image.png

image.png

[server@epam .ssh]$ sudo netstat -tunlp | grep “:80” tcp6 0 0 :::80 :::* LISTEN 6216/httpd

[server@epam .ssh]$ sudo netstat -tunlp | grep “:22” tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 5833/sshd: /usr/sbi tcp6 0 0 :::22 :::* LISTEN 5833/sshd: /usr/sbi

CommandLogic / One-Line Working
netstat -tunlpShows TCP, UDP, Numeric IPs, Listening ports, and PIDs.
ss -atpLists all active TCP connections and the programs using them.
ss -ntlpgrep :80`
netstat -rnDisplays the Kernel Routing Table (shows your gateway).
ss -sDisplays a summary of socket statistics (how many established, closed, etc.).
netstat -iDisplays a table of all Network Interfaces and error/packet counts.
CommandOne-Line Working
tcpdump -i eth0Captures all traffic flowing through the eth0 interface.
tcpdump -c 5 -i anyCaptures exactly 5 packets from all interfaces and then exits.
tcpdump -n -i anyDisables DNS resolution to show raw IP addresses instead of hostnames.
tcpdump port 22Filters and shows only traffic related to SSH.
tcpdump src 10.0.0.10wCaptures only packets coming from the specific IP 10.0.0.10.
tcpdump -w capture.pcapSaves the captured traffic to a file to be opened later in Wireshark.
tcpdump -A -i anyPrints the packet content in ASCII (useful for reading HTTP/unencrypted data).
tcpdump icmpFilters and shows only Ping (ICMP) traffic.
CategoryCommandPurpose
Monitoring/InfolsblkList block devices and their tree structure.
pvs / vgs / lvsQuick summary of PVs, VGs, or LVs.
pvdisplay / vgdisplay / lvdisplayDetailed metadata for PVs, VGs, or LVs.
watch -n 2 df -hContinuously monitor disk space every 2 seconds.
blkid <path>Get the UUID of a block device (needed for fstab).
Physical Volumespvcreate <disk>Initialize disk for LVM use.
pvremove <disk>Wipe LVM metadata from a disk.
Volume Groupsvgcreate <name> <pv>Create a new pool from physical volume(s).
vgextend <name> <pv>Add a new physical disk to an existing pool.
vgremove <name>Delete a volume group.
Logical Volumeslvcreate -L 5G -n <name> <vg>Create a new logical volume.
lvextend -L +5G <lv_path>Increase LV size by 5GB.
lvextend -l +100%FREE <lv> -rUse all free VG space AND automatically resize filesystem.
lvreduce -L 5G <lv_path>Shrink LV size to 5GB (Shrink FS first!).
lvchange -an <lv> / -ay <lv>Deactivate (-an) or Activate (-ay) an LV.
lvremove <lv_path>Delete a logical volume.
Filesystemsmkfs.ext4 <lv_path>Format the LV with the ext4 filesystem.
mount <lv_path> <mount_dir>Mount the filesystem to a directory.
umount <mount_dir>Unmount the filesystem.
mount -aTest /etc/fstab configuration to ensure safe reboots.
resize2fs <lv_path>Expand/shrink ext4 filesystem to match LV size.
e2fsck -f <lv_path>Force check filesystem for errors (required before shrinking).
Snapshotslvcreate -s -L 1G -n <name> <lv>Create a 1GB point-in-time snapshot.
lvconvert --merge <snap_path>Rollback the original LV to the snapshot’s state.
Testing/Utilscat /dev/zero > <file>Fill a file with zeros to test 100% disk usage.
truncate -s 0 <file>Empty a file instantly to free space.
apt cleanClear local package cache to free emergency space.