Index

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 source/data to destination/data
rsync -v -a source/data destination
copy files from source/data to destination/data without overwriting
rsync -v -a --ignore-existing source/data destination
move files (not links) from source/data to destination/data without overwriting
rsync -v -a --ignore-existing --remove-source-files source/data destination
same as above, but create hardcopies of links
rsync -v -a --ignore-existing --remove-source-files --copy-links source/data destination

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]

convert line terminators

replace DOS style line endings with UNIX style line endings
dos2unix [file]...
replace UNIX style line endings with DOS style line endings
unix2dos [file]...