A file system structure in which to store computer files.

learn more… | top users | synonyms

108
votes
3answers
41k views

Why do directories need the executable (X) permission to be opened?

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?
73
votes
1answer
87k 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 ...
70
votes
6answers
19k views

Why hard links not allowed to directories in UNIX/Linux

I read in text books that UNIX/Linux doesn't allows hard links to directories but soft links do. Is it because, when we have cycles and if we create hardlinks, and after some time we delete the ...
51
votes
4answers
3k views

Pronunciation for /usr directory

How do you pronunce /usr? I found in the net that someone reads it "user"... but, for what I know, this directory is not related to the user. The meaning of the acronym is "Unix specific (or system) ...
51
votes
3answers
2k views

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

This just baffles 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 ...
48
votes
6answers
7k views

How linux handles multiple 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 ...
44
votes
5answers
2k views

cd by just typing the directory's name?

I either had this somewhere 20 years ago or I dreamed about it. Basically: If if type blobblob I get blobblob: command not found Fair enough. I would like it so that when my shell gets those ...
40
votes
7answers
3k views

cd .. on root folder

Why cd .., typed at root folder, does not warn or fails with an error? I would expect: /$ cd .. -bash: cd: ..: No such file or directory Instead, I'm left at /. Of course, this is since .. does ...
38
votes
6answers
7k 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. Is the star in front of ls means how deep it can list the ...
37
votes
5answers
19k 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 ...
36
votes
7answers
9k 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 ...
35
votes
2answers
2k 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 ...
33
votes
4answers
27k 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 questions is twofold: When I schedule a cron ...
30
votes
5answers
20k views

How to XZ a directory with TAR using maximum compression?

So I need to compress a directory with max compression. How can I do it with xz? I mean I will need tar too because I can't compress a directory with only xz. Is there a oneliner to produce e.g. ...
30
votes
3answers
4k 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?
30
votes
8answers
4k views

How to delete this undeletable directory?

I untarred a corrupt tar file, and managed to end up with some directory that I can not delete, If I try to delete it, it seems like it can not be found, but ls shows it's present, both with bash and ...
30
votes
5answers
12k 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 ...
28
votes
9answers
25k 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 ...
28
votes
2answers
15k views

How can I calculate the size of a directory?

How to know the size of a directory? Including subdirectories and files.
27
votes
3answers
12k views

Why unix mv program doesn't need -R (recursive) option for directories but cp does need it?

This is a kind of "wtf?" question, so I'm sorry if I will disturb someone's vision of how things should be or if I will just annoy you with the "stupid" question. I always get messed up when need to ...
27
votes
2answers
16k 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 ...
24
votes
12answers
5k views

What's the most resource efficient way to count how many files are in a directory?

CentOS 5.9 I came across an issue the other day where a directory had a lot of files. To count it, I ran ls -l /foo/foo2/ | wc -l Turns out that there were over 1 million files in a single ...
24
votes
1answer
3k views

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

After reading this question Design question: Why was '~' chosen to represent the home directory?, next obvious question on my mind was why '.' and '..' was used to represent current directory ...
22
votes
8answers
28k 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, but I want to loop only through directories. ...
22
votes
4answers
978 views

Is there any way attacker could use mkdir to compromise a system?

I'm setting up a restricted user account for user ricardo, a troublesome user on my system. I want to grant him the right to make directories using sudo, which he sometimes needs to do. I'm ...
22
votes
3answers
5k 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 ...
20
votes
2answers
2k views

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

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 ...
19
votes
6answers
5k views

What's the most “correct” mount point for a permanent NTFS partition?

I have an NTFS partition (containing a Windows installation from which I dual boot) that I would like to permanently mount from my Linux installation. Problem is, I can't figure out what the ...
18
votes
4answers
12k views

Converting relative path to absolute path

Is there a *nix command to get absolute(and canonicalized) path from relative path(with current path) or symbolic link?
18
votes
1answer
46k 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 ...
17
votes
3answers
8k 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 ...
17
votes
6answers
2k views

Why do I have to cd out of a deleted directory?

On my server I have a directory structure looking something like this: /myproject/code I normally have an ssh connection to the server and 'stand' in that directory: root@machine:/myproject/code# ...
17
votes
3answers
5k 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 / ...
16
votes
7answers
6k views

Merging folders with mv?

If I move a folder with mv called "folder" to a directory that already contains "folder" will they merge or will it be replaced?
16
votes
5answers
29k views

Script to monitor folder for new files?

How do I detect new files in a folder with a bash script? I would like to process the files as soon as they are created in the folder. Is this possible to do so or do I have to schedule a script with ...
16
votes
6answers
2k 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 ...
15
votes
3answers
60k 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 ...
14
votes
3answers
4k 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 ...
13
votes
4answers
2k views

Best method to collect a random sample from a collection of files

Suppose there is a directory holding 300 data files. I want to randomly select 200 of those files and move them into another directory. Is there a way to do that under Unix/Linux?
12
votes
5answers
3k views

How can I copy a file and create the target directories at the same time?

I want to cp aaa/deep/sea/blob.psd to bbb/deep/sea/blob.psd How do I do the copy if the deep and sea directories don't exist under bbb so that the copy both creates the directories that are needed ...
12
votes
3answers
338 views

Finding the correct tmp dir on multiple platforms

I have a script that needs to create temporary files for its work, and clean up after itself. My question is about finding the right base directory for the temporary files. The script needs to work ...
12
votes
1answer
1k 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?
12
votes
1answer
155 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 ...
11
votes
4answers
1k views

How do I choose specific files in a different directory using bash?

I want to list (or delete, or do some other operation) on certain files in a directory, like this: $ ls /opt/somedir/ aa bb cc aa.txt bb.txt cc.txt $ ls /opt/somedir/(aa|bb|cc) ## pseudo-bash ...
11
votes
1answer
210 views

How to log all the events performed on directory?

How can I log all the events performed on a particular directory? I want to log the entry of each directory modified within some time duration. I am using find . -type d -mmin -5 command. In ...
10
votes
6answers
42k views

How to remove all the files in a directory?

I am trying to remove all files and subdirectories in a directory. I used rm -r to remove all files, but I want to remove all files and subdirectories, excluding the top directory itself. For ...
10
votes
4answers
5k views

symbolic link to a directory and relative path

I've created symlink with absolute path to the directory (Blink) and have for example following tree: $ ls -l /tmp/A total 0 lrwxrwxrwx 1 root root 6 Apr 3 12:27 Blink -> /tmp/B -rw-r--r-- 1 root ...
10
votes
3answers
9k 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 ...
10
votes
4answers
1k views

Include / in symlink to a directory?

Symlinking to a directory gives to different results with ls -l depending on whether I ln -s dir or ln -s dir/. But what's the actual difference, and which one should I prefer why?
10
votes
3answers
6k views

Simplest way to password protect a directory and its contents without having to create new files?

I would like to password protect or encrypt a directory and all the files within it (for the whole directory tree below it). I do not want to bother the whole home directory, I want a specific ...