Skip to main content

Questions tagged [directory]

A file system structure in which to store computer files.

Filter by
Sorted by
Tagged with
528 votes
9 answers
395k views

Execute vs Read bit. How do directory permissions in Linux work?

In my CMS, I noticed that directories need the executable bit (+x) set for the user to open them. Why is the execute permission required to read a directory, and how do directory permissions in Linux ...
Nick.h's user avatar
  • 6,373
152 votes
6 answers
30k views

How does Linux handle multiple consecutive path separators (/home////username///file)?

I'm working on a python script that passes file locations to an scp subprocess. That's all fine, but I'm in a situation where I may end up concatenating a path with a filename such that there's a ...
Falmarri's user avatar
  • 13.2k
97 votes
5 answers
110k views

The result of ls * , ls ** and ls ***

I know using the command ls will list all the directories. But what does the ls * command do ? I used it and it just lists the directories. Does the star in front of ls mean how deep it will list the ...
Andy M's user avatar
  • 1,083
374 votes
5 answers
696k views

How to set default file permissions for all folders/files in a directory?

I want to set a folder such that anything created within it (directories, files) inherit default permissions and group. Lets call the group "media". And also, the folders/files created within the ...
Chris's user avatar
  • 8,630
57 votes
3 answers
51k views

Why does a new directory have a hard link count of 2 before anything is added to it?

Say I just create directory newDirectory and then I do ls -ld command. I see that the number of hard links is 2. What exactly makes the hard link 2 from the start? Also is the number of subdirectories ...
John's user avatar
  • 3,679
87 votes
4 answers
36k views

What does size of a directory mean in output of 'ls -l' command?

What does size of a directory mean in output of ls -l command?
Hemant's user avatar
  • 6,910
240 votes
4 answers
150k views

Do the parent directory's permissions matter when accessing a subdirectory?

If I have a root folder with some restrictive permission, let's say 600, and if the child folders/files have 777 permission will everybody be able to read/write/execute the child file even though the ...
Ken Li's user avatar
  • 2,535
141 votes
3 answers
334k views

Getting new files to inherit group permissions on Linux

I am having a problem with permissions on a Linux server. I am used to BSD. When a directory is owned by a group the user who owns it isn't in such as www-data, files created in it will be owned by ...
John Tate's user avatar
  • 1,990
34 votes
4 answers
38k views

How to run a command when a directory's contents are updated?

There is a directory A whose contents are changed frequently by other people. I have made a personal directory B where I keep all the files that have ever been in A. Currently, I just occasionally ...
oadams's user avatar
  • 2,335
222 votes
11 answers
411k views

Tool to monitor folder for new files and run command whenever new file is detected

How can I immediately detect when new files were added to a folder within a bash script? I would like the script to process files as soon as they are created in the folder. Are there any methods aside ...
norq's user avatar
  • 4,131
221 votes
8 answers
113k views

How to remove all empty directories in a subtree?

How can I remove all empty directories in a subtree? I used something like find . -type d -exec rmdir {} 2>/dev/null \; but I needs to be run multiple times in order to remove directories ...
maaartinus's user avatar
  • 5,159
158 votes
7 answers
81k views

Why are hard links to directories not allowed in UNIX/Linux?

I read in text books that Unix/Linux doesn't allow hard links to directories but does allow soft links. Is it because, when we have cycles and if we create hard links, and after some time we delete ...
user3539's user avatar
  • 4,408
88 votes
4 answers
67k views

When should I use a trailing slash on a directory? [duplicate]

Possible Duplicate: How linux handles multiple path separators (/home////username///file) Most commands I use in linux behave exactly the same whether I include the trailing slash / character on ...
Cory Klein's user avatar
  • 19.1k
31 votes
1 answer
3k views

When did directories stop being readable as files?

I have the 1st edition of The Unix Programming Environment book. In chapter 2, the authors state that directories are readable as files, and mention some facts about the format of these files. They ...
Tyler's user avatar
  • 683
28 votes
9 answers
8k views

Any way to sync directory structure when the files are already on both sides?

I have two drives with the same files, but the directory structure is totally different. Is there any way to 'move' all the files on the destination side so that they match the structure of the ...
d0g's user avatar
  • 847
257 votes
16 answers
326k views

Merging folders with mv?

If I use mv to move a folder called "folder" to a directory that already contains "folder" will they merge or will it be replaced?
Dominique's user avatar
  • 5,345
104 votes
6 answers
50k views

How can I create a /dev/null-like "blackhole" directory?

I would like to create a "/dev/null" directory (or a "blackhole" directory) such that any files written to it are not really written, but just disappear. I have an application that writes out large ...
dogbane's user avatar
  • 30.1k
77 votes
2 answers
92k views

Command to zip multiple directories into individual zip files

I have a single directory that contains dozens of directories inside of it. I'm new to command line and I'm struggling to come up with a command that will zip each sub-directory into a unique sub-...
Evster's user avatar
  • 1,715
16 votes
5 answers
7k views

List all directories that do NOT have a file with a given file name inside

How would I go into listing all directories that do not have a file with a given file name inside? e.g. given this tree / /a README file001 file002 /b README file001 /c ...
Renan's user avatar
  • 17.2k
83 votes
2 answers
6k views

Why does '/' have an '..' entry?

This has always puzzled me. Why does the root directory contain a reference to a parent directory? bob@bob:/$ ls -a . build home lib32 mnt .rpmdb sys vmlinuz .. cdrom ...
Nathan Osman's user avatar
  • 6,250
25 votes
3 answers
62k views

What are ./ and ../ directories?

Simple question, but I'm not sure where to look and google doesn't respond to periods and slashes. I'm just trying to count the # of files & directories in the current directory (not including ...
Adam's user avatar
  • 293
14 votes
10 answers
28k views

What's the best way to count the number of files in a directory?

If parsing the output of ls is dangerous because it can break on some funky characters (spaces, \n, ... ), what's the best way to know the number of files in a directory? I usualy rely on find to ...
rahmu's user avatar
  • 20.2k
170 votes
7 answers
81k views

What does the .d stand for in directory names?

I know many directories with .d in their name: init.d yum.repos.d conf.d Does it mean directory? If yes, from what does this disambiguate? UPDATE: I've had many interesting answers about what the ....
greg0ire's user avatar
  • 3,035
47 votes
9 answers
20k views

mkdir -p for files

mkdir -p will create a directory; it will also make parent directories as needed. Does a similar command exist for files, that will create a file and parent directories as needed?
Zombo's user avatar
  • 1
36 votes
2 answers
23k views

Where do the files go if you mount a drive to a folder that already contains files? [duplicate]

I just accidentally mounted a new drive to a folder that already contained files. I don't care about them and have them somewhere else, but that folder appears empty now. I'm curious what happened ...
T. Brian Jones's user avatar
15 votes
1 answer
2k views

Why directory with large amounts of entries does not shrink in size after entries are removed?

The question is why exactly does a directory shrink after directory entries are removed? Is it due to how ext4 filesystem configured to retain directory metadata? Obviously removing the directory and ...
Sergiy Kolodyazhnyy's user avatar
113 votes
8 answers
795k views

"Input/output error" when accessing a directory

I want to list and remove the content of a directory on a removable hard drive. But I have experienced "Input/output error": $ rm pic -R rm: cannot remove `pic/60.jpg': Input/output error rm: cannot ...
Tim's user avatar
  • 104k
28 votes
8 answers
25k views

How to set an alias on a per-directory basis?

Suppose you have an alias go, but want it to do different things in different directories? In one directory it should run cmd1, but in another directory it should run cmd2 By the way, I have an ...
B Seven's user avatar
  • 8,199
28 votes
1 answer
38k views

In Linux, is "write" permission equivalent to "execute" for directories?

The execute permission makes sense for files (which include scripts etc.), but when it comes to directories, the write (w) permission works the same way as execute (x), right? Which means, if we are ...
its_me's user avatar
  • 14.3k
18 votes
6 answers
22k views

Linux local directory permissions as question-marks for non-root

I've seen cases like that with faulty storage devices, with faults in remote storage (SAN, NAS), I think I've even seen something similar caused by mount permissions. But it's the first time I see ...
netikras's user avatar
  • 425
13 votes
1 answer
52k views

How can I make ls show information about the directory specified only, not info about its sub-files or folder contents?

Say I have folder "foo" residing, the home directory. I want to get some info of it, owner, group, permissions, etc... I then do this to try to get the information: cd ~ ls -l foo Of course it now ...
Tyilo's user avatar
  • 6,031
529 votes
14 answers
903k views

How do I loop through only directories in bash?

I have a folder with some directories and some files (some are hidden, beginning with dot). for d in *; do echo $d done will loop through all files and directories, but I want to loop only through ...
rubo77's user avatar
  • 29.6k
257 votes
5 answers
297k views

What is the 'working directory' when cron executes a job?

I have a script that works when I run it from the command line, but when I schedule it with cron I get errors that it cannot find files or commands. My question is twofold: When I schedule a cron ...
ProfessionalAmateur's user avatar
97 votes
5 answers
197k views

Determine what device a directory is located on

If I do # cd / # ln -s /home test # cd test # mount --bind $PWD /mnt the entry in /proc/mounts is /dev/sda2 /mnt ext4 rw,noatime,data=ordered 0 0 which is the device that is mounted to /home and ...
StrongBad's user avatar
  • 5,341
77 votes
8 answers
92k views

Converting relative path to absolute path without symbolic link

Is there a Unix command to get the absolute (and canonicalized) path from a relative path which may contain symbolic links?
Benjamin's user avatar
  • 1,515
54 votes
2 answers
4k views

Why is '.' a hard link in Unix?

I've seen many explanations for why the link count for an empty directory in Unix based OSes is 2 instead of 1. They all say that it's because of the '.' directory, which every directory has pointing ...
Joseph Garvin's user avatar
41 votes
2 answers
12k views

Why was '.' chosen to represent the current directory and '..' for parent directory?

After reading this question Why was '~' chosen to represent the home directory?, next obvious question on my mind was why '.' and '..' was used to represent current directory and parent ...
Manu's user avatar
  • 510
36 votes
4 answers
67k views

How can I move files by type recursively from a directory and its sub-directories to another directory?

What would be a good way to move a file type from a directory and all of its sub-directories? Like "move all *.ogg in /thisdir recursively to /somedir". I tried a couple of things; my best effort was ...
Steve Burdine's user avatar
23 votes
10 answers
46k views

How do I change folder timestamps recursively to the newest file?

I was wondering if anyone knows how to change the timestamps of folders recursively based on the latest timestamp found of the files in that folder. So for example: jon@UbuntuPanther:/media/media/...
MonkeyWrench32's user avatar
11 votes
2 answers
4k views

Trailing slashes on symbolic links to directories

I'm trying to emulate the process of path resolution (see man page path_resolution) in unix-like systems. My OS is Linux with GNU coreutils 8.7. In order to clarify the meaning of extra trailing '/' ...
ymfoi's user avatar
  • 383
8 votes
2 answers
3k views

What happens when the current directory is deleted?

In the first terminal A, I create a directory, enter the directory, and create a file: $ mkdir test $ cd test $ touch file1.txt $ ls file1.txt Then in another terminal B, I delete the directory: $ ...
wenzeslaus's user avatar
116 votes
4 answers
490k views

Create a symbolic link relative to the current directory

I'm trying to create a symbolic link in my home directory that points to a directory on my external HDD. It works fine when I specify it like this: cd ~ ln -s /run/media/name/exhdd/Data/ Data ...
jcora's user avatar
  • 3,884
51 votes
5 answers
98k views

Is there any way to prevent deletion of certain files from user owned directory?

Let's say user has Directory1 and it contains File1 File2 CantBeDeletedFile How to make so the user would never be allowed to delete the CantBeDeletedFile? If I change the ownership of Directory1 and ...
bakytn's user avatar
  • 2,961
26 votes
9 answers
6k views

Clipboard for copying and pasting files in command line?

In Bash, suppose I visit a directory, and then another directory. I would like to copy a file from the first directory to the second directory, but without specifying the long pathnames of them. Is it ...
Tim's user avatar
  • 104k
23 votes
4 answers
18k views

How are directories implemented in Unix filesystems?

My question is how directories are implemented? I can believe a data structure like a variable e.g. table, array or similar. Since UNIX is Open Source I can look in the source what the program does ...
Niklas Rosencrantz's user avatar
16 votes
1 answer
6k views

How to find all the links to a directory

When I stat a directory I get a listing that tell me there are 5 links to the directory. stat dir My question is how do I get information (names and locations) to all these 5 links?
Ankur Agarwal's user avatar
346 votes
5 answers
1.3m views

How can I get the current working directory? [duplicate]

I want to have a script that takes the current working directory to a variable. The section that needs the directory is like this dir = pwd. It just prints pwd how do I get the current working ...
user avatar
270 votes
21 answers
390k views

How do I get the MD5 sum of a directory's contents as one sum?

The md5sum program does not provide checksums for directories. I want to get a single MD5 checksum for the entire contents of a directory, including files in sub-directories. That is, one combined ...
user avatar
141 votes
5 answers
147k views

Difference between /bin and /usr/bin

I read this up on this website and it doesn't make sense. http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/basic/node32.html When UNIX was first written, /bin and /usr/bin physically resided ...
whoami's user avatar
  • 3,900
121 votes
7 answers
85k views

Flattening a nested directory

This is probably very simple, but I can't figure it out. I have a directory structure like this (dir2 is inside dir1): /dir1 /dir2 | --- file1 | --- file2 What is ...
turtle's user avatar
  • 2,717

1
2 3 4 5
7