Table of contents
Files
printing to system output
print file line by line
cat [file]
print file line by line (reverse order)
tac [file]
multiple files
cat [file1] [file2] [file3] ...
echo stdin to output (essentially a noop)
echo [message] | cat -
insert output from stdin between file contents
echo middle | cat [file+] - [file+]
cat as a multiline echo
cat << EOF
important message
blabla
more blabla
EOF
Copy
copy file
cp original destination
copy directory
cp -r directory destination
copy don't overwrite (useful for backups)
cp -n original destination
Move
move file
mv original destination
move file (verbose)
mv -v [source] [destination]
Soft link
create soft link (general form)
ln -s [existing target] [link to create]
concrete example
ln -s ~/.bashrc /tmp/bashrc
create links to files with their original name in a destination directory
ln -s ~/.b* .
get the destination of a link on the filesystem
readlink [existing_link]
rsync
copy directory
rsync -r [from] [to]
copy directory contents only (because of slash)
rsync -r [from]/ [to]
copy directory verbose
rsync -rv [from] [to]
delete missing files in destination
rsync -r [from] [to] --delete
copy files from source/data to destination/data without overwriting
rsync -r --ignore-existing source/data destination
move files (not links) from source/data to destination/data without overwriting
rsync -r --ignore-existing --remove-source-files source/data destination
same as above, but create hardcopies of links
rsync -r --ignore-existing --remove-source-files --copy-links source/data destination
unison (rsync alternative)
copy directory
unison -auto -batch [from] [to]
duplicate files
find duplicate files in a directory
fdupes [directory]
search nested directories also
fdupes -r [directory]
ask which duplicate files to delete
fdupes -d [directory]
auto delete all but first
fdupes -N [directory]
split a file into chunks
split a file into chunks of specified size
split --bytes 500M --numeric-suffixes --suffix-length=3 [input] [output file prefix]
line endings
the file command will report it when a file has CRLF line terminators (dos line endings)
file [file]
replace DOS style line endings with UNIX style line endings
dos2unix [file]...
replace UNIX style line endings with DOS style line endings
unix2dos [file]...