Listing directory with NGINX, but disallow traversing parent directories - nginx

I've got it so I can see directories by turning the autoindex on; directive, but I want to disallow people traversing to parent directories, namely clicking the "../" to go back a directory. How is this possible?
../
Directory 1
Directory 2
Directory 3
File.txt
File2.txt
File3.txt
I cannot find a solution for this.

Related

Navigating directories when you don't know the name of the directory

I have a directory that is created through an external process. The directory is named 2021-12-08_1345 (YYYY-MM-DD_HHMM) based on the date and time when the process is executed. While this is the only directory in the path, I won't know the precise name of the directory. Is there a way to navigate to this folder knowing that it's the first and only directory?
The solution is cd $(ls -d -1 */ |sed -n '1p') where 1p is the nth directory that you want to navigate to. I came across the solution on an Ubuntu StackExchange https://askubuntu.com/questions/454688/how-do-you-cd-into-the-first-available-folder-without-typing-out-the-name#comment1800653_455113
I verified that this works on macOS 11.5.2+
If you are sure it is the only directory you can use
cd */
or
cd /path/to/*/
but this will fail if there is more than one directory.
Otherwise I suggest to use the solution from Ed Knittel's answer.
If you know that there is only one directory and no files you can even omit the trailing / from these commands, e.g. cd *.

How do I ls a directory to get it's data, but none of its files?

I wish to run ls -alh on a directory, so that I can get when the directory was last modified.
I do NOT want to get the ls information for the files in that directory, just that directory.
Is this possible?
Turn's out it's easy
ls -alhd
The -d flag reports on directories, not their files

Find files > 30 days, Delete and log

Based on lot of research below is what I have come up with
find /Some_Dir -type f -mtime +30 -delete -printf "%TD %p\n" >> /Logfile.txt 2>&1
This is doing a good job of deleting the files and it also deletes files with spaces. One concern I have is that this is deleting the files which is just ready only or even files with 000 permission. Is that expected result?
Yes. You are not modifying the files, you are modifying the containing directory.
To forbid deletion of files, you need to either deny write access to the directory, or set the sticky bit (more accurately but less mnemonically known as the "restricted deletion flag") on the directory and ensure the user trying to delete the file does not own the file or the directory. World-writable directories like /tmp will generally have the sticky bit already turned on.
If you just want to change the behavior of the find command, use -writable or -perm.

Seemingly invalid No such file or directory error

I'm attempting to open a directory in Unix. If I enter the command
ls
I see the directory listed in my current directory but if I endter
cd [directory_name]
I get the error
No such file or directory
I'm also not able to auto complete the directory name using the 'tab' key. Does anyone know what may be causing this?
Check whether you are using the right capitalization? It's case sensitive. Add this to your ~/.inputrc if you want bash to not care about the case of the file.
set completion-ignore-case on
This is example:
user#stackoverflow:~$ ls
users questions file.txt
user#stackoverflow:~$ cd /questions
user#stackoverflow:~/questions$
Make sure that you're trying to access a valid folder and not a file.
To further explain:
List the current directory's contents (either one):
ls .
ls
List the home directory's contents (wherever you are):
ls ~
List the root directory's contents (wherever you are):
ls /

Will Symlink do as im hoping - treat one folder same as another

I want to symlink:
/var/www/ThisFolder
to this folder
/var/www/htdocs/Thisfolder
I.e Symlink the folder that is in a non web accessible directory to link to one that is.
I plan to do this via:
ln -s /var/www/ThisFolder /var/www/htdocs/Thisfolder
Will my server then treat the folder outside the root as if it were inside the root?
Permissions on symbolic links are kind of funny. If you don't have permissions to view your target folder (/var/www/htdocs/Thisfolder) you wont be able to access it through the symlink. The permissions you will see by doing an ls -l on your symlink will show its permissions for renaming/unlinking the symlink, not for the target.

Resources