Why does the filesystem not recognize a file named ../blah.sh - linux

I am using Ubuntu 16.04.3 LTS with ext4 filesystem.
When I make a file like:
touch ../blah.sh
It does not show up when I use:
ls -al
When I try to delete the file with:
rm * --> : rm: cannot remove '*': No such file or directory.
However when I delete it with:
rm ../blah.sh ---> it succeeds.
Besides this I am able to edit the file with vim, put code in there and then run it like:
./../blah.sh
How is this behavior possible? Is this bash specific behaviour or from the operating system? and is it possible to hide a file like this?

When you use .. you are creating the file in the parent directory of where you currently are.
If you try this it should show the file:
ls -al ..
Also for rm you'd have to do the following, though it's dangerous obviously.
rm ../*

Related

What is the meaning of the rm -fv command?? using it for csf installation

I want to know what exactly the following command means ??
rm -fv csf.tgz
I'm typing this command as the first step for installing csf on my virtualmin, but I dont know the exact meaning. I just now copied and pasted it.
rm -rf / – Deletes Everything!
Never use this command in your Linux computer because it deletes every file in your system.
sudo - sudo (Super User DO) is generally used as a prefix of some command that only superuser are allowed to run.
rm – Remove the following files.
-rf – Run rm recursively (delete all files and folders inside the specified folder) and force-remove all files without prompting you.
/ – Tells rm to start at the root directory, which contains all the files on your computer and all mounted media devices, including remote file shares and removable drives.

All files made by root is write-protected

Is it normal that all files and folders, which is made by root, is write-protected?
For instance, take a look at terminal log below:
shine#Shine-Ubuntu:~$ sudo -s
root#Shine-Ubuntu:~# echo >> 1.txt
root#Shine-Ubuntu:~# exit
exit
shine#Shine-Ubuntu:~$ rm 1.txt
rm: remove write-protected regular file '1.txt'?
(As you might know, echo >> FILE_NAME creates a file and names it FILE_NAME.)
When a file is made by root, and i want to delete it via user, it says remove write-protected regular file 'FILE_NAME'?
What should i do so the files and folders made by root won't be write-protected?
UMASK is the default permissions given when a new file or folder is created on a Linux machine. Detailed documentation/usage of umask can be seen here. Check umask setting on your system

Linux folder move access

Is a Linux file system able to allow or deny the right to move a folder? Active Directory does not, as far as I can tell. I'm curious, and 3 different wordings generated no results.
Yes. If you have a folder foo/bar/, you could make the folder foo read-only, which would prevent people from moving bar:
$ chmod a-w foo
$ mv foo/bar ack
mv: cannot move ‘foo/bar’ to ‘ack’: Permission denied
The can't move bar, but they can still change what's inside of it:
$ echo hello > foo/bar/hello.txt
$ rm foo/bar/hello.txt
In linux you can use chattr to make a file or folder immutable like so:
chattr +i file
This way, not even the super can move, modify or delete the file.
To revert it you can use:
chattr -i file
This works for on ext filesystems

Linux : How to delete locked file

I want to remove xyz_DB.lock.db file. I tried as root but couldn't delete it. How to remove it in terminal. My initial requirement was remove a folder. but it includes this locked file. And is there anyway to delete folder directly which include a locked file ?
Check with lsattr command if the immutable bit is set for the file, it will show (i)
# lsattr file
----i--------e- file
If so, change it using following command:
# chattr -i file
And then try to remove it.
Try either changing the files permissions through the GUI or use rm -rf on the directory that contains it.
try "chown" to provide permission to your file/folder and then delete it,
e.g: assume username= amol and filename=myfile.txt,,
For File:--- sudo chown amol:amol myfile.txt
For Folder:-- sudo chown -R amol:amol directory_name

Remove a symlink to a directory

I have a symlink to an important directory. I want to get rid of that symlink, while keeping the directory behind it.
I tried rm and get back rm: cannot remove 'foo'.
I tried rmdir and got back rmdir: failed to remove 'foo': Directory not empty
I then progressed through rm -f, rm -rf and sudo rm -rf
Then I went to find my back-ups.
Is there a way to get rid of the symlink with out throwing away the baby with the bathwater?
# this works:
rm foo
# versus this, which doesn't:
rm foo/
Basically, you need to tell it to delete a file, not delete a directory. I believe the difference between rm and rmdir exists because of differences in the way the C library treats each.
At any rate, the first should work, while the second should complain about foo being a directory.
If it doesn't work as above, then check your permissions. You need write permission to the containing directory to remove files.
use the "unlink" command and make sure not to have the / at the end
$ unlink mySymLink
unlink() deletes a name from the file system. If that name was the last link to a file and no processes have the file open the file is deleted and the space it was using is made available for reuse.
If the name was the last link to a file but any processes still have the file open the file will remain in existence until the last file descriptor referring to it is closed.
I think this may be problematic if I'm reading it correctly.
If the name referred to a symbolic link the link is removed.
If the name referred to a socket, fifo or device the name for it is removed but processes which have the object open may continue to use it.
https://linux.die.net/man/2/unlink
rm should remove the symbolic link.
skrall#skrall-desktop:~$ mkdir bar
skrall#skrall-desktop:~$ ln -s bar foo
skrall#skrall-desktop:~$ ls -l foo
lrwxrwxrwx 1 skrall skrall 3 2008-10-16 16:22 foo -> bar
skrall#skrall-desktop:~$ rm foo
skrall#skrall-desktop:~$ ls -l foo
ls: cannot access foo: No such file or directory
skrall#skrall-desktop:~$ ls -l bar
total 0
skrall#skrall-desktop:~$
Use rm symlinkname but do not include a forward slash at the end (do not use: rm symlinkname/). You will then be asked if you want to remove the symlink, y to answer yes.
Assuming it actually is a symlink,
$ rm -d symlink
It should figure it out, but since it can't we enable the latent code that was intended for another case that no longer exists but happens to do the right thing here.
If rm cannot remove a symlink, perhaps you need to look at the permissions on the directory that contains the symlink. To remove directory entries, you need write permission on the containing directory.
Assuming your setup is something like: ln -s /mnt/bar ~/foo, then you should be able to do a rm foo with no problem. If you can't, make sure you are the owner of the foo and have permission to write/execute the file. Removing foo will not touch bar, unless you do it recursively.
I also had the same problem. So I suggest to try unlink <absolute path>.
For example unlink ~/<USER>/<SOME OTHER DIRECTORY>/foo.
On CentOS, just run rm linkname and it will ask to "remove symbolic link?". Type Y and Enter, the link will be gone and the directory be safe.
I had this problem with MinGW (actually Git Bash) running on a Windows Server. None of the above suggestions seemed to work. In the end a made a copy of the directory in case then deleted the soft link in Windows Explorer then deleted the item in the Recycle Bin. It made noises like it was deleting the files but didn't. Do make a backup though!
you can use unlink in the folder where you have created your symlink
If rm cannot remove a link, perhaps you need to look at the permissions on the directory that contains the link. To remove directory entries, you need write permission on the containing directory.

Resources