Linux Shell Cheatsheet


ls -lah path (lists directory content, -l = long listing, a=all (show .files), h=file sizes in human readable format)

cat filename (output a text file)

df -h (show free disk space, -h = human readable format)

lsblk (list block devices like drives, etc.)

lspci (list pci devices)

lsusb (list usb devices)

arp -a list devices in local network

Network troubleshooting

Permissions & Ownership

chown -R user:group filename (-R = recursive, changes file ownership to user & group)

change file permissions

Permissions: r=read, w=write, e=execute

Owners: u=user, g=group, o=other

chmod -R u=xrw,g=xrw,o=xrw filename (-R = recursive, assign xrw to user and xrw to other, wipe previous permissions set for user and other)

chmod -R u-x filename (recursively removes x for user)

chmod -R u+x filename (recursively adds x for user)

chmod -R +x filename (recursively adds x for all, means user+group+other)

chmod 664 filename (change permission to 644)

1st digit = owner, 2nd digit = group, 3rd digit = others

number = sum of the following permission values: 0: no permissions, 1: execute, 2: write, 4: read


Backup stuff

tar -cvf backup_file.tar /pathtofiles1 /pathtofiles2 ... (puts pathtofiles1 etc. into one tar file named backup_file.tar)

gzip -v9 * (zip all files in current directory with best but slowest compression, output what gzip is doing. The original file is removed after compression.)

rsync -raz --progress source target sync source to target, keep attributes/archive (-a), do it recursively (-r) and remove files at target that do not exist at source any more (-z)


sudo mkfs.ext4 -vccL MyLabel /dev/sdX1 format partition sdX1 as ext4, label it "MyLabel" (-L) and check for bad sectors extensively using read&write (-cc) and verbose (-v) the stuff

Screen recording

scrcpy --crop 1080:2288:0:112 -r ~/Dokumente/location1.mp4 --record-format mp4 screen record a device with 1080x2400 resolution, cropping the status bar

ffmpeg -i location1.mp4 -vf crop=1080:2150:0:0 location2.mp4 crop the softkeys on the bottom

scrcpy --crop 1080:1832:0:88 -r ~/Dokumente/location1.mp4 --record-format mp4 screen record a device with 1080x1920 resolution, cropping the status bar