The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [directory]

A file system structure in which to store computer files.

Filter by
Sorted by
Tagged with
10
votes
3answers
19k views

What means the dots on a path? [duplicate]

How is "/a/./b/../../c/" equal to /c? I saw this as a question on one of the Stack Exchange sites. Apparently .. means to pop the stack(?). Why is this the case?
10
votes
1answer
25k 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 ...
10
votes
4answers
16k views

Recursively add a file to all sub-directories

How do I recursively add(or touch) a file into the current directory, as well as all sub-directories? For example, I would like to turn this directory tree: . ├── 1 │   ├── A │   └── B ├── 2 │   └── ...
10
votes
1answer
12k views

how to view a directory's permission

What is the command with which you can directly view the permission bits of a directory?
10
votes
2answers
1k views

Is a directory removed when its number of hard links becomes 0?

Is a directory removed when its number of hard links becomes 0? A directory always has at least 2 as its number of hard links, because of .. When rm -r a directory, does it decrease the number of ...
10
votes
4answers
43k views

programmatically creating a remote directory using ssh

Using a shell script, how can I create a directory remotely from serverA -> serverB using ssh? Can I pass the create directory command with the ssh command? How? I'm basically looking to create a ...
10
votes
2answers
22k views

Path syntax rules

I'm writing a library for manipulation Unix path strings. That being the case, I need to understand a few obscure corners of the syntax that most people wouldn't worry about. For example, as best as ...
10
votes
5answers
1k 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 ...
10
votes
2answers
3k views

Can I access Nautilus's bookmarks in terminal?

I have made a some bookmarks in Nautilus, i.e. shortcut links to some directories. I would like to cd to a directory which has been bookmarked in Nautilus. I was wondering if that is possible?
10
votes
4answers
1k views

Keeping history per working directory (cf. per shell session)

Is there a way to make a modern shell's history feature be scoped to a path? My working contexts are split up as paths on the file system, and the pattern of shell activity, such as repeatedly issued ...
10
votes
3answers
4k views

How can I cd to the previous/next sibling directory?

I often have a project directory layout like this project `-- component-a | `-- files... `-- component-b | `-- files... `-- component-c `-- files... I'll usually be working in one of the ...
10
votes
4answers
12k views

Recursively rename subdirectories that match a regex

I have a media server with a folder called Series. (/media/Expansion2/Series/) In it, I have (surprise!) TV series. These are just the show names, e.g., /media/Expansion2/Series/The Big Bang Theory/ ...
10
votes
3answers
4k views

Delete all files except in a certain subdirectory with find

I want to recursively delete all files not accessed in a while in folder a, except all files in the subfolder b. find a \( -name b -prune \) -o -type f -delete However, I get an error message: ...
10
votes
2answers
400 views

Are there any filesystems for which `ln -d` succeeds?

From the manpage for ln: -d, -F, --directory allow the superuser to attempt to hard link directories (note: will probably fail due to system restrictions, even for the superuser) Are there any ...
10
votes
1answer
4k views

Find all folders in a directory with the same content

In Ubuntu, is there any to find duplicate folders in a directory (i. e., folders with the same content)? I think there are already some command-line tools available for finding duplicate files (such ...
9
votes
6answers
70k views

Why do I get permission denied when using mv although directory rights are correct?

I get permission denied when trying to move folder Music via mv although directory owner is set to my user and user permissions are set to 7. What's going on? (I know that I could use sudo but I want ...
9
votes
1answer
26k views

What does “execute” permission mean on a folder? [duplicate]

I have read this topic, which gave me some info but I feel I am not fully getting it. What does the execute permission actually mean on a folder? I fully understand what it means on a file, but on a ...
9
votes
3answers
20k views

cp --no-target-directory explained

Question: I need a simple example of how to use cp --no-target-directory. I do experience some difficulties in understanding cp --no-target-directory. I do understand the explanation for mv --no-...
9
votes
4answers
6k views

What are the advantages of the Unix file system structure

If I install an application in Linux for example Debian/Gnu Linux, the files of the applications are copied to many different directories in the file system. Some scripts goes into /usr/share .. /usr/...
9
votes
5answers
4k views

Making a directory protected from 'rm -rf'

I just lost some data in folder A which was inside folder B after doing rm -rf B. Before I could realize what have I done, it was all over. Now a lesson is learnt, I wish to make some of my folder ...
9
votes
3answers
54k views

How can I determine if an NFS remote is exporting a directory?

In my script, I have several layers of statusing: remote is available (ping) remote NFS service is active remote NFS is exporting a certain directory remote NFS is mounted (mount) For (2) and (3), I ...
9
votes
2answers
1k views

How to spoof/mock a directory used by a binary application as another directory?

Suppose there's a binary application that always writes its data to /tmp. How could I spoof/mock /tmp for the sake of this binary as some other directory (e.g. home/tmp)? Let's assume I have no ...
9
votes
2answers
10k views

I want to tar X directory not including its parents

tar cvf /var/lib/backup/sample.tar /home/user/.project However, when I extract, I get its parents as well /backup/ - /home/ - /user/ - .project/ This tar commands does it job because ...
9
votes
2answers
12k views

Is there a correct way to list the subdirectories of the current directory?

I can find the subdirectories of a directory by ls -d -- */ or ls -l | grep "^d" but both of these seem indirect, and I would imagine that there would be a standard way to find just the ...
9
votes
5answers
8k views

How can I use locate only for a directory

This finds a large number of files that are under various subdirectories of "Dropnot" $ locate Dropnot Can I find just the directory location with locate? (which directory "Dropnot" is in) So if ...
9
votes
3answers
24k views

What is the difference between path and directory?

I don't understand the difference between path and directory. Could someone explain to me with examples?
9
votes
4answers
5k views

Find directories that do not contain subdirectories

I'm writing script is ksh. Need to find all directory names directly under the current directory which contain only files, not subdirectories. I know that I could use ls -alR and recursively parse ...
9
votes
3answers
22k views

How do I search all subdirectories to find one with a certain name?

Let's say I have a top level directory called /dir and many sub directories. How do I search the subdirectories of /dir to find the one called x/x/dir/x/x/x/target? This question is similar to, but ...
9
votes
2answers
4k views

Difference between rmdir and rm -r

I usually delete directories by using rm: rm -r myDir However I am aware of another command, rmdir, which seems to do the job just as well: rmdir myDir What is the difference between these two ...
9
votes
1answer
3k views

Why could the size of the “dot” file “.” exceed 4096?

Today I found an "empty" directory with a size of 4MB. It had no visible contents, so I tried ls -lah. This showed me some hidden files (not very large). Searching for the reason why the directory ...
9
votes
3answers
5k views

Symlink aliasing files in subdirectories without changing current directory

It seems like it should be simple to symlink one file to a new file in a subdirectory.... ....without moving subdirectories. But something about the syntax is perplexing and counter to what I would ...
9
votes
4answers
9k views

Passing multiple directories to the -prune option in find

I am using find to locate and delete backup files but wish to exclude certain directories from the search. The backup filenames could terminate in .bck, bak, ~, or backup. The Minimal Working Example ...
9
votes
3answers
10k views

How do get ls to list directories with a trailing forward-slash?

My shell is bash. How can I get the output of ls to show directories with a trailing forward-slash? When I do ls in tcsh it gives the desired output. How can I get this to occur in bash without ...
9
votes
4answers
4k views

Find files with same name but different content?

I want to generate a list of files that have: Same name Different content in a directory (including all children directories and content). How to do? Bash, perl, anything is fine. So, two files ...
9
votes
1answer
2k views

Why are rmdir and unlink two separate system calls?

Here's something that kept me wondering for a while: [15:40:50][/tmp]$ mkdir a [15:40:52][/tmp]$ strace rmdir a execve("/usr/bin/rmdir", ["rmdir", "a"], [/* 78 vars */]) = 0 brk(0) ...
9
votes
1answer
3k views

Can rm recursively remove empty directories?

In an old version of Unix, the rm command would delete directories if they were empty. From the Research Unix Eighth Edition man page for rm: "If an entry is a directory it is removed only if empty." ...
9
votes
1answer
3k views

ls -l --group-directories-first (act on symlinks as well)

ls option --group-directories-first causes directories to be listed on the top, which makes the output of ls nice and clean: ls -l --group-directories-first However, it does not act on symlinks, ...
9
votes
2answers
3k views

Folder with ONLY write permission is useless… right?

Having worked with Linux for years, and finding myself with some free time, I decided to revisit some basics. So I re-read the stuff about permissions (without checking source code), and its special ...
8
votes
5answers
17k views

Get the parent directory of a given file [duplicate]

Suppose file stores the pathname of a non-dir file. How can I get its parent directory? why does the following way by appending /.. to its value not work $ cd $file/.. cd: ./Tools/build.bat/..: ...
8
votes
6answers
2k views

Checking for the existence of multiple directories

I want to check for the existence of multiple directories, say, dir1, dir2 and dir3, in the working directory. I have the following if [ -d "$PWD/dir1" ] && [ -d "$PWD/dir2" ] && [ -...
8
votes
6answers
637 views

Find only those folders that contain a File with the same name as the Folder

I want to find all subfolders, that contains a markdown file with the same name (and extension .md). For example: I want to Find following subfolders: Apple/Banana/Orange #Apple/Banana/Orange/...
8
votes
3answers
672 views

Flattening directory hierarchy preserving directory names in new directory name

I basically want to go from this: . ├── Alan Walker │   ├── Different World │   │ ├── 01 Intro.mp3 │   │ ├── 02 Lost Control.mp3 │   │ └── cover.jpg │   └── Same World │   ├── 01 Intro.mp3 │...
8
votes
4answers
5k views

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

Okay, that's a new one. 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 ...
8
votes
4answers
28k views

Bash script detecting change in files from a directory

I am trying to make a script that detects if any of the files in a directory were changed within a 2 seconds interval. What I have so far is: #!/bin/bash for FILE in "${PWD}/*" do SUM1="$(md5sum $...
8
votes
3answers
5k views

Bulk remove a large directory on a ZFS without traversing it recursively

I want to remove a directory that has large amounts of data on it. This is my backup array, which is a ZFS filesystem, linear span, single pool called "san". San is mounted on /san so I want to bulk ...
8
votes
3answers
822 views

“mkdir foo; svn mv * foo”

I often want to do some variant of this idiom: $ mkdir 2010 $ svn mv * 2010 Of course, I get an error because the glob matches 2010 as well: svn: Cannot copy path '2010' into its own child '2010/...
8
votes
3answers
3k views

Encrypt directory with GnuPG?

Is there any way to encrypt a directory using gpg? It seems to only accept files as arguments.
8
votes
2answers
3k views

Why does '/' have the inode 2?

On many *nix systems like OS X and Ubuntu, We can see the inode of root directory is 2. Then what is the inode 1 used for?
8
votes
2answers
6k views

Get directory from which script was called from

I have a script doSmth in /usr/bin. Is it possible to get and print the directory the script was called from? So if I call doSmth from /home/me the output will be /home/me.
8
votes
2answers
3k 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 '/' ...