Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

How to browse root directory in linux mint?

Writer Mia Lopez

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

2 Answers

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

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:

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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