Find root directory in linux

How to browse root directory in linux mint?

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?

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.

2 Answers 2

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:

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

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 

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

Alternatively, if you want only files, use find :

$ find / -maxdepth 1 -type f -name "abc*" 
 -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 

Источник

How to find the disk where root / is on in Bash on Linux?

Question: how to find the disk where the Linux’s root(/) is on in Bash? The root may be on a LVM volume or on a raw disk.

# df -hT | grep /$ /dev/sda4 ext4 48G 32G 14G 71% / 
# df -hT | grep /$ /dev/mapper/fedora-root ext4 48G 45G 1.4G 98% / 

The it is a LVM volume in LVM group ‘fedora’:

# lvs | grep fedora | grep root root fedora -wi-ao---- 48.83g 

and ‘fedora’ is on the single disk partition ‘/dev/sda3’ of disk ‘/dev/sda’:

# pvs | grep fedora /dev/sda3 fedora lvm2 a-- 64.46g 4.00m 

For both cases above, we want to find out ‘/dev/sda’ (the root filesystem is on only one physical disk).

Читайте также:  Minecraft on linux crashes

To solve this problem, one straightforward way is to check every possible cases and handle each case following the format for each case (raw partition, or LVM partition). But in Linux, there is a more convenient tool to handle this problem – using lsblk .

lsblk and PKNAME

lsblk can show one important value here:

For a raw partition, the parent kernel device is the disk, and for an LVM partition, the parent kernel device is the physical volume (the partition). Here are examples of output of lsblk .

For a ‘/’ on a raw partition:

root@vm0:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT . sdc 8:32 0 1.8T 0 disk ├─sdc1 8:33 0 512M 0 part /boot/efi └─sdc2 8:34 0 1.8T 0 part /

For a ‘/’ on an LVM partition:

root@vm1:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 512M 0 part /boot/efi ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 19.5G 0 part ├─vgubuntu-root 253:0 0 18.5G 0 lvm / └─vgubuntu-swap_1 253:1 0 976M 0 lvm [SWAP]

PKNAME for raw or LVM partition backed root ‘/’

From lsblk ‘s manual, we can see it supports various output format. Here, we use the key/value pair format which is easy to parse in Bash.

# lsblk -oMOUNTPOINT,PKNAME -P | grep 'MOUNTPOINT="/"' MOUNTPOINT="/" PKNAME="sdc"
# lsblk -oMOUNTPOINT,PKNAME -P | grep 'MOUNTPOINT="/"' MOUNTPOINT="/" PKNAME="sda5"

We can easily get rid of the trailing numbers (so we get the disk device name) by

This can be applied to both cases. For the raw partition case, the sed command simply does not have any additional effect.

Wrap up to be a bash statement

Now, we can wrap all up into a bash statement using some Bash grammar and techniques

dev=$(eval $(lsblk -oMOUNTPOINT,PKNAME -P -M | grep 'MOUNTPOINT="/"'); echo $PKNAME | sed 's/1*$//')

For the raw partition case, we get

root@vm0:~# dev=$(eval $(lsblk -oMOUNTPOINT,PKNAME -P -M | grep 'MOUNTPOINT="/"'); echo $PKNAME | sed 's/2*$//') root@vm0:~# echo $dev sdc

For the LVM partition case, we get

root@vm1:~# dev=$(eval $(lsblk -oMOUNTPOINT,PKNAME -P | grep 'MOUNTPOINT="/"'); echo $PKNAME | sed 's/7*$//') root@vm1:~# echo $dev sda

Источник

Locating the Current Directory’s Root in Linux: A Guide

To return from a sub-directory to the parent directory, use the designated command, or alternatively, change the working directory to the user’s home directory. The inquiry pertains to the process of adding a system call to Ubuntu 13.10, which is running on Linux kernel version 3.11.0-12. The initial instruction mandates changing the current working directory to the kernel directory.

How do I find the root of the directory I’m currently in for Linux

Suppose I am currently in the directory named «makefile_assignment». Can you suggest a command that can show me the parent directories in a hierarchical manner?

The assignment’s makefile can be found in the following directory: /home/linux/ieng6/cs80w/public/.

Читайте также:  Linking files in linux

I believe you’re looking for:

Simply the $PWD environment variable.

The command you seek is pwd .

The following command, pwd , denotes the current working directory.

In most cases, the answer produced by echo $PWD is identical and functional.

Directory — cd .. on root folder, According to the Open Group (responsible for the POSIX standard): Each directory has exactly one parent directory which is represented by the name dot-dot in the first directory. What the filename dot-dot refers to relative to the root directory is implementation-defined. In Version 7 it refers to the root directory itself; this is …

How to return to default linux root (Home) folder in terminal?

As someone who is new to Linux and Python, I’m wondering if there is a way to return to the default root folder (Home) from the terminal without having to close and reopen it.

After activating the folder:

root@root:~/anaconda2# source bin/activate ~/anaconda2/ discarding /root/anaconda2/bin from PATH prepending /root/anaconda2/bin to PATH 
(/root/anaconda2)root@root:~/anaconda2 

After launching the IPython notebook, I completed my work and shut it down. Later, upon reopening it, I returned to:

What are the steps to recover my Home or root folder?

You’ve returned to your home directory.

Perhaps you intended to refer to either deactivate , which pertains to the virtual environment, or one of the following problems: deactivate or source deactivate .

(/root/anaconda2)root@root:~# source deactivate root@root:~# 

What is the reason behind using root initially?

It is not advisable to use sudo to avoid certain actions. It is essential to have control over the things being installed with root privileges, especially when logged in as root. Installing everything with root privileges is unnecessary and not recommended for security reasons.

Have you attempted running cd to return to your root folder? Is that the action you desire?

As you are logged in as the root user, your home directory defaults to /root. To use /home/username, you need to create a new user on Kali.

To return to parent directory from a sub-directory, you can employ .. . Alternatively, you can switch to the user’s home directory by utilizing cd ~ .

Root /home Directory vs ~ (tilde), /home is where all users usually get their home directories created under.. Examples: /home/marcelo /home/joe The /home may sometimes reside in a different filesystem (i.e., a separate harddisk, another partition in the same harddisk or even network mounted) than the / (main system’s filesystem).. For this (and …

Reaching the root directory of linux kernel source on ubuntu?

On version 3.11.0-12 of Linux kernel, I’m using Ubuntu 13.10. However, I’m having trouble adding a system call. The first step requires me to switch to the kernel directory, but I encountered an issue. When I tried using the command «cd linux-3.11.0-12,» it informed me that the file or directory exists couldn’t be found. Can you assist me in identifying my mistake and correcting it?

So, you’re interested in adding a system call to the Linux kernel. However, are you confident in your ability to locate the source code and make modifications, configurations, and boot the kernel?

In case you confirm your need for it, the initial step is to obtain the Linux source code. This can be achieved by either cloning https://github.com/torvalds/linux or downloading the specific version you require. Once obtained, extract the source code to a chosen location and follow by cd to the extracted path. After this, you can commence with any desired modifications.

Читайте также:  Найти файл через командную строку linux

This blog post might be of assistance to you.

If you are using Ubuntu 13.04 or later versions, you can employ a command to retrieve the origin of the installed kernel.

apt-get source linux-image-`uname -r` 

The recommended location for it is generally within the /usr/src directory.

The links provided are resources for compiling and building your own kernel in Ubuntu, with one link being from the Ubuntu Community and the other from the Ubuntu Wiki.

How to return to default linux root (Home) folder in, If that still doesn’t work you can easily create an alias pointing to the all path where you want to go.. for eg. first type alias cd1=»/root» then you can just run cd1 You need to put the right path in the alias and that should work.. Sorry, I don’t a kali linux for test it for you. – bySamo Nov 20, 2016 at 4:49 Thank you. cd … Code sample(/root/anaconda2)root@root:~# source deactivateroot@root:~#Feedback

How do you get to the root directory that I need to delete a file in?

How can I access the root directory to delete a file?

You can access the root directory through the command line using the following method.

FTP might lead you to the root of the FTP server rather than the root of your system.

As a cautionary measure, it is advisable to avoid creating files in the root directory. When removing files, it is important to use sudo before rm and ensure that you are logged in as an administrator.

To delete items from your root directory, assuming root privileges is necessary. If you are not familiar with command line interface (CLI) commands, open the file browser with root privileges by entering gksudo nautilus . However, be cautious while deleting items from the root directory as it may cause damage to your system.

Presuming that the graphical user interface is being utilized.

  • Access the «search» bar by clicking on the top left icon, then enter «term» which is the abbreviation for terminal.
  • Upon opening the terminal window, input the code mentioned previously: cd / .

When it comes to removing files, my recommendation would be to use.

rm -i /yourfilename /your/file/name 

In order to provide a preview of the deleted items, it is useful to implement this feature, especially when utilizing a wildcard such as * and/or ? .

How do I navigate between directories in terminal?, / at the beginning of file path refers to the root directory. The next nice thing is tab expansion. If you enter cd ~/Dow Tab (last is pressing Tabulator key), the bash automatically expands it to cd ~/Downloads. As the others said GNU/Linux is case sensitive. So it makes a difference if you enter Home, hOme or …

Источник

Оцените статью
Adblock
detector