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
sudo
withcd
. if you need a root propmt, either execute the shell as root, or runsudo -i
to run a series of commands as root. second, the root dir is / , not /root. or better yet, usesudo ls .... /root
to run your list command as root.