1

I need to browse root directory in linux mint from command.

I tried

sudo cd /root

It says sudo cd command not found.

cd /root

says permission denied.

Also I need to list the files starting with "abc" inside root directory. When listing files I must not include sub directories of /root.

Can anyone help?

1
  • 3
    First off, you can't use sudo with cd. if you need a root propmt, either execute the shell as root, or run sudo -i to run a series of commands as root. second, the root dir is / , not /root. or better yet, use sudo ls .... /root to run your list command as root. – Frank Thomas Jan 23 '14 at 16:14
3

First of all, the root directory is /, not /root. /root is the home directory of the root user. Also, you don't need sudo to list its contents. Just do:

ls /

To list all files (and directories) starting with abc, you want

ls /abc*

To move into the root directory, just run cd /.


The command ls /abc* treats files and folders differently. The glob is expanded by your shell (bash) to all files and folders beginning with abc. ls will list the contents of any directories you give it. For example:

$ ls -l
total 4
-rw-r--r-- 1 terdon terdon    0 Jan 23 20:25 dfile.txt
drwxr-xr-x 2 terdon terdon 4096 Jan 23 20:25 dir1
$ ls dir1
-rw-r--r-- 1 terdon terdon 0 Jan 23 20:25 file2.txt

So, I have a directory called dir1 and a file called dfile.txt. The directory contains another file, file1.txt. Now, if I run ls d*, it will list the file dfile.txt and the contents of the directory dir1:

$ ls d*
dfile.txt

dir1:
file2.txt

If you don't want ls to list the contents of directories, run it with the -d option. As explained in man ls:

   -d, --directory
          list  directory entries instead of contents, and do not derefer‐
          ence symbolic links

So, for example:

$ ls -d d*
dfile.txt  dir1

To list all files and directories beginning with abc in / without listing dirctory contents, run this:

$ ls -d /abc*

Alternatively, if you want only files, use find:

$ find / -maxdepth 1 -type f -name "abc*"

From man find:

   -maxdepth levels
          Descend at most levels (a non-negative integer) levels of direc‐
          tories below the command line arguments. 
   -name pattern
          Base of  file  name  (the  path  with  the  leading  directories
          removed)  matches  shell  pattern  pattern.
   -type c
          File is of type c:

          d      directory
          f      regular file
1
  • @techfun see updated answer. – terdon Jan 23 '14 at 19:31
3

Root directory (the whole directory structure) is "/", not "/root".

If you do

sudo cd /

You will run a subshell that will change directory to / then exit. You are still where you were.

You can explore "/" simply by changing to it

cd / 

and you'll be able to read the files that your user or group has the right to. Better than doing that as superuser... very dangerous.

I would hearthily advise you to have a look around here: http://www.tutorialspoint.com/unix/unix-getting-started.htm

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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