There are plenty of information available online on linux command line, but I made myself a cheatsheet of things that I find using quite often.
Mainly I use this for backing up folders on my computer to my external hard drive
# -r for recursive
# -v for verbose (to see printout of progress)
rsync -rv /path/to/sync/from/ /path/to/sync/to/
Archive mode also available
“du” returns the “disk usage” of files/directories
# list file size of files in immediate direectory, and the subfolders
# (but not the files within them)
du .
# use -s (for summary) of size of directory
du -s .
# use -h (for human?) for more human-friendly file size units to be used
du -sh .
“df” returns disk usage of file systems
# Summary of all file systems (-h makes the file size units more human friendly)
df -h
“fdisk” is a partition table manipulator (will likely require sudo)
# list all partitions in system
fdisk -l
# To set partitions for hard drive, e.g sdb
sudo fdisk /dev/sdb
# d to delete partition, n to add new partition
# p primary, create, w to write changes
If exfat support is required, then install with:
sudo add-apt-repository universe
sudo apt-get update && sudo apt-get install exfat-utils
Format partitions:
# format partitions...the number, e.g. 1 for sdb1,
# is important or it will delete the partitions
mkfs.ext4 /dev/sdb1
To mount drive:
# if sdd1 is the partition to umount
mount /dev/sdd1 /directoryofchoice
To unmount drive (and power off if USB):
udisksctl unmount -b /dev/sdd1
udisksctl power-off -b /dev/sdd
To mount drive permanently:
sudo vi /etc/fstab
# e.g. add this line to map sdb1 to /my/directory:
/dev/sdb1 /my/directory ext3 defaults 0 0
# then exit, and run:
sudo mount -a
# might need rebooting if "mount point does not exist"
Every file on an ext filesystem has:
Use chmod to modify file/folder access rights (g+s to makes any new files/folders created inside directory have same chmod rights as parent)
chmod g+s /path/to/parent
If setting rwx group permissions on a file, only the owner group of that file can read/write/execute it. You can, though, change user and owner with:
chown username file1 file2 ...
chown -R username somedir
chgrp groupname file1 file2 ....
chgrp -R groupname somedir
chown username:groupname file1 file2 ...