In this example I will use the sources.list file that contains a list of the repositories from which we can get packages.
results in a "Permission denied error". This is because the >> /etc/apt/sources.list redirection is processed by your shell before spawning sudo, so it is trying to open the file with your (ordinary) user privileges, not root privileges.
Ways around this:
The shell spawned by sudo reads its command from the string after the -c switch, so the redirection is done in a process which is already running as root.
The 'tee' command reads from standard input and the -a switch appends it to the file. Again, the file is opened by the process spawned by sudo, which is running as root.