Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to create a file using cat > list but each time it shows me "Permission denied".

xyz@jaishreeram:/home$ sudo cat > list
bash: l: Permission denied
xyz@jaishreeram:/home$ sudo cat > list
bash: l: Permission denied
share|improve this question
5  
Do you want to make a file called "list"? –  PeppeDAlterio Sep 29 '13 at 7:58
3  
It's difficult to tell what is being asked here. This is vague and cannot be reasonably answered in its current form. Please be a little bit more specific or detailed about what you're trying to accomplish, or take a look at What kind of questions should I not ask here? –  minerz029 Sep 29 '13 at 8:15
add comment

4 Answers 4

AFAIK you can't make a file using cat. You have to use echo instead. So just run this to make a file called "list":

echo > list

If you need root privileges you first have autenticate as root using
su -
now you can echo > list
now you can logout as root using logout

This because the redirect is done before sudo starts, that's why you get "permission denied" without being asked for password.


cat is used to concatenate files and print on the standard output.
echo is used to display a line of text, using the "> file_name" you will redirect that line of text to "file_name" and if "file_name" doesn't exist, the file will be created.

PS: There are tons of method to make a new file using the command line but, in my opinion, this's the faster and easier to remember.

share|improve this answer
    
xyz@jaishreeram:/home$ echo > list bash: list: Permission denied –  abhinay Sep 29 '13 at 8:09
    
My bad, if you need root privileges, you have to use echo as root, because the redirect is done before sudo starts –  PeppeDAlterio Sep 29 '13 at 8:16
2  
Side note: You can write into files using the way the question has been posted, the problem is something else. –  i08in Sep 29 '13 at 8:19
add comment

The location you are writing into required super user privileges. However, the way you are writing into the file does not assume this. For this either log in as root using su and then write using cat > list or do sudo vi list.

share|improve this answer
add comment

The reason is simple, you don't have permissions to write into the /home directory since it owned by root.

/home$ ls -la .
total 36
drwxr-xr-x.  6 root          root           4096 Apr 19 05:03 .
drwxr-xr-x. 22 root          root           4096 Sep 24 09:49 ..

You should use the same command but in "your home" directory. Your home directory is the user directory under /home:

/home$ ls -la .
total 36
drwxr-xr-x.  6 root          root           4096 Apr 19 05:03 .
drwxr-xr-x. 22 root          root           4096 Sep 24 09:49 ..
drwxr-xr-x. 70 braiam        braiam         4096 Sep 29 10:06 braiam

You have several ways to go to your home directory:

  • Run cd without any parameter.
  • Run cd ~ or cd $HOME
  • Open another new terminal
  • Use cd /home/yourusername to go to your personal directory.
share|improve this answer
add comment

try

sudo bash -c 'cat file1 >> file2'

or

cat file1 | sudo tee -a file2

read here in ubuntuforums

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.