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
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
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
.
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.
echo
as root, because the redirect is done before sudo starts
Sep 29, 2013 at 8:16
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:
cd
without any parameter.cd ~
or cd $HOME
cd /home/yourusername
to go to your personal directory.