Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I am trying to create a directory in my home directory on Linux using the mkdir command, but am getting a 'permission denied' error. I have recently installed Lubuntu on my laptop, and have the only user profile on the computer.
Here's what happened on my command line:
jdub#Snowball:~$ cd /home
jdub#Snowball:/home$ mkdir bin
mkdir: cannot create directory ‘bin’: Permission denied
jdub#Snowball:/home$
How do I gain access to this folder? I am trying to write a script and following a tutorial here: http://linuxcommand.org/wss0010.php
Thanks for your help!
As #kirbyfan64sos notes in a comment, /home is NOT your home directory (a.k.a. home folder):
The fact that /home is an absolute, literal path that has no user-specific component provides a clue.
While /home happens to be the parent directory of all user-specific home directories on Linux-based systems, you shouldn't even rely on that, given that this differs across platforms: for instance, the equivalent directory on macOS is /Users.
What all Unix platforms DO have in common are the following ways to navigate to / refer to your home directory:
Using cd with NO argument changes to your home dir., i.e., makes your home dir. the working directory.
e.g.: cd # changes to home dir; e.g., '/home/jdoe'
Unquoted ~ by itself / unquoted ~/ at the start of a path string represents your home dir. / a path starting at your home dir.; this is referred to as tilde expansion (see man bash)
e.g.: echo ~ # outputs, e.g., '/home/jdoe'
$HOME - as part of either unquoted or preferably a double-quoted string - refers to your home dir. HOME is a predefined, user-specific environment variable:
e.g.: cd "$HOME/tmp" # changes to your personal folder for temp. files
Thus, to create the desired folder, you could use:
mkdir "$HOME/bin" # same as: mkdir ~/bin
Note that most locations outside your home dir. require superuser (root user) privileges in order to create files or directories - that's why you ran into the Permission denied error.
you can try writing the command using 'sudo':
sudo mkdir DirName
Try running fuser command
[root#guest2 ~]# fuser -mv /home
USER PID ACCESS COMMAND
/home: root 2919 f.... automount
[root#guest2 ~]# kill -9 2919
autofs service is known to cause this issue.
You can use command
#service autofs stop
And try again.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I am writing a bash shell script which removes a file using the following command
rm abc.xsl
I handled the case of getting the prompts and providing the required 'y' or 'n' inputs.
In order to verify that the file has been removed, I validate the same by running the locate command in the following manner
locate */abc.xsl
Note : the desired file is present at a specific directory, so in my case this particular command is not giving me any other file's address
I noticed that despite of file being deleted, the locate command is still reflecting the deleted file's path.
I debugged the issue by manually executing each of the required commands
FYR
admin#sharad-server$ pwd
/usr/local/myserver/myapplication/lib
admin#sharad-server$ rm abc.xsl
rm: remove write-protected regular file 'abc.xsl'? y
admin#sharad-server$ locate */abc.xsl
/usr/local/myserver/myapplication/lib/abc.xsl
The file was deleted as it was not reflected when I executed the ls command and also the cat command as follows
admin#sharad-server$ cat /usr/local/myserver/myapplication/lib/abc.xsl
cat: /usr/local/myserver/myapplication/lib/abc.xsl: No such file or directory
FYR my application is deployed on GCP and my server's platform details are as follows:
admin#sharad-server$ uname -a
Linux sharad-server 3.10.0-1127.8.2.el7.x86_64 #1 SMP Tue May 12 16:57:42 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
The details of the shell where all these commands were executed in a standalone manner are as follows:
admin#sharad-server$ ps -p $$
PID TTY TIME CMD
32296 pts/0 00:00:00 bash
Why the locate command is still reflecting the deleted file's path?
Update:
As per one of the suggestion I tried the updatedb command as well but it gave me an error.
admin#sharad-server$ updatedb
updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db'
Final Update:
The updatedb command worked with the root user and has successfully updated the locate command functioning.
For performance reasons, Locate use an index where all file tree structure is stored to find something...
This file need to be updated with the command updatedb #root permision needed.
If you want to find a file or directory performing "live analyses" you'll need to use find.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I understand that cd .. goes up a directory, but what exactly does cd . do?
This is a question on my study guide, which is why I am asking.
Thanks!
As most people realize, cd . doesn't really do anything, because . means "the current directory". Changing to the current directory is seemingly pointless.
However, there is at least one interesting side effect:
When you cd to some directory, an environment variable OLDPWD is set, which allows you to execute cd - to return to the previous directory that you cd'ed from. When you execute cd ., OLDPWD actually gets set as the current directory, so it renders cd - ineffective in getting you back to the previous directory you were in.
Example:
$ cd /foo
$ cd /tmp
$ cd -
$ pwd
/foo
I'm in /foo just like I expected, but
$ cd /foo
$ cd /tmp
$ cd . # does nothing, right?
$ cd -
$ pwd
/tmp
Now I didn't return to /foo like I was hoping, due to this side effect!
Nothing. cd changes directory to the argument provided. And . means "the current directory" just as .. means "the parent of the current directory".
As others have said, cd . will change to the current directory, which has basically no effect in scripting/programming or to the operating system.
However that doesn't mean it will do nothing. In practice, you may be using a terminal to type this command. It will happily execute the command and - perhaps, though not likely - do something like echo the contents of the directory. If something else on your system (say a background process or another shell) have changed the contents of the directory, you may see modified output when the command echoes out the new directory listing.
In short: the cd . command doesn't have any real effect, but it could - in rare instances - have useful side effects that you could leverage in practical use.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I'm still a Linux newbie and I'm wondering: What is the Linux directory // ?
I can change dir (cd) to the root dir using cd /
~> cd /
/>
Using pwd (print name of working directory) tells me I'm in root (/)
/> pwd
/
Using ls (list directory contents) I see the following (using Raspbian Jessie)
/> ls
bin boot dev etc home include lib lost+found media mnt opt proc root run sbin share srv sys tmp usr var
By mistake I changed dir to // and found that it was valid:
~> cd //
//>
Also using pwd tells me I'm in a directory called // :
//> pwd
//
But using ls I see the that I'm probably still in 'something' looking like root.
//> ls
bin boot dev etc home include lib lost+found media mnt opt proc root run sbin share srv sys tmp usr var
... but telling me it's called // (rootroot ;-)
So what is directory // ?
In Linux (and most other platforms), multiple slashes in a path are interpreted the same as a single slash. However, the POSIX specification states that:
A pathname that begins with two successive slashes may be interpreted in an implementation-defined manner, although more than two leading slashes shall be treated as a single slash.
// may be reserved for a special purpose (e.g: accessing a network drive in Cygwin). However, if you check ls in / and // on Linux you should see the same content.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I had a brilliant idea to change my /usr file permissions to 0744 using 'sudo chmod 0744 /usr' while I was trying to install a program. So now I can't access any of my files, my home directory 'home/username' doesn't exist apparently (which isn't true), and all commands that are located in the /usr/bin folder are 'do not exist', which also isn't true.
I think the reason for the commands not existing is because I don't have write/execute permissions on the /usr/bin folder (owned by root), but I don't know why my home folder 'does not exist'.
My question is what exactly have I done, and how do I fix it, if possible?
As a side note, the computer is now having a problem when I try to turn it on. It immediately goes to a blinking cursor (top left) and black screen, but I can ssh into the machine. Finally, I don't have access to the root user or a root shell on this machine.
Solved:
So what happens when you run a command like sudo chmod 744 /usr is that all users on the network get locked out of the home folders as well as making it impossible for the computer to boot (hence the black screen with a blinking cursor). Also, more technically, your root file system (/dev/sda1 for me) becomes read-only.
Since you can't boot the computer, you need to go into single user mode from the grub menu. Next, run the command mount -o remount, rw /dev/(your root file system, possibly sda1). This will remount your root file system as read only. Then, run the command chmod 755 /usr. This will of course change the file permissions to read,write, and execute for the owner of the files and read/execute for group and world users.
You need to login as root, or boot the computer into single-user mode, and then execute:
chmod 755 /usr
You won't be able to do this with sudo because that command is in /usr, and without execute permission you can't access anything in it.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
when i copy files, execute the file in linux, I am Not quite understand the difference and how to use them.
please help. thanks.
. means current directory
./ means current directory, too
./* means all files in current directory
. means the current directory, and ./ is the same but more explicit, saying "Hey, I'm a directory!" It's like any other folder: TheFolder and TheFolder/ refer to the same object. One case where the meaning is different is when looking at a symlink pointing at a directory: TheLink can refer either to the link object or the directory that you pointed at, depending on the situation, while TheLink/ will always refer to the directory. Also, when you run the rsync command, it will treat TheFolder and TheFolder/ differently.
./* just means all the files in the current directory, same as *. Bash expands that asterisk before the command is run, so the program doesn't see the asterisk, instead seeing all the files as arguments. The difference between these two is that for the former, the command will see "./" prepended to each filename.
To see how these differ, echo is a safe command to run. It will just print the value of what you send it:
echo *
echo ./*
. and ./ both mean current working directory
../ means parent directory of the current working directory
./* means all files and directories in current working directory plus all files and directories in all directories in the current working directory.
./* is all files in current directory
./ is current directory