Linux files and folders
Copy and rename, prompt before overwriting
cp -i file dir1/file2
Move and rename
mv file dir1/file2
Recursively delete a folder and its contents
rm -rf /opt/folder/subfolder/
Only remove the contents of a folder
rm -rf /opt/folder/subfolder/*
Show the size of a file or folder
:~# du -hs /opt/tomcat/logs/
825M /opt/tomcat/logs/
Show disk space used
cd /
du -hs --block-size=M
Show disk space left
cd /
root@debian / # df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/md2 ext4 1.1T 866G 162G 85% /
udev devtmpfs 11M 0 11M 0% /dev
tmpfs tmpfs 3.4G 345M 3.1G 11% /run
tmpfs tmpfs 8.4G 8.2k 8.4G 1% /dev/shm
tmpfs tmpfs 5.3M 0 5.3M 0% /run/lock
tmpfs tmpfs 8.4G 0 8.4G 0% /sys/fs/cgroup
/dev/md3 ext4 1.9T 1.4T 466G 74% /home
/dev/md1 ext3 512M 55M 431M 12% /boot
Download a file from the internet
wget http://example.com/archive.tar.gz -P /target/folder
Pack and unpack a folder
Pack folder
tar -czf archive.tar.gz folder/
Unpack archive
tar -xzf archive.tar.gz
Unpack archive to target
tar -xzf /opt/tmp/archive.tar.gz -C /opt/target/
Monitor log files live
tail -f -n50 error.log
Use -f
for live output and -n50
to only print the last 50 lines.