Questions tagged [directory]

A file system structure in which to store computer files.

Filter by
Sorted by
Tagged with
15
votes
3answers
21k views

Replace symbolic link which linked to directory target

I want to upgrade tomcat server from 7.0.19 to 7.0.20. I've already ln -s apache-tomcat-7.0.19 tomcat7 before, so now I need to link tomcat7 to new target using the following command ln -s --force ...
15
votes
4answers
19k views

Recursively iterate through files in a directory

Recursively iterating through files in a directory can easily be done by: find . -type f -exec bar {} \; However, the above does not work for more complex things, where a lot of conditional branches,...
15
votes
2answers
16k views

How to zip directory with encryption for file names?

Using command line, I know that I can encrypt a directory with the following command: zip -er Directory.zip /path/to/directory However, this does not encrypt the filenames themselves. If someone ...
15
votes
1answer
4k 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?
15
votes
2answers
14k views

Problem with install command to copy a whole directory

So I have a repo with some of my config files and I'm trying to create a makefile to install them in the homedir. The problem I have is that when I run the following command straight in bash install -...
15
votes
1answer
21k views

quotas not linked to users but to directories

Usually, quotas are enforced per user, as related to the proprietary of the file. Is it possible to apply a quota on a folder basis, in such a way, that a folder contents are limited in disk space?
14
votes
1answer
23k 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 ...
14
votes
5answers
11k views

Bash CD up until in certain folder

I do a lot of work in Magento, and so do a lot of the people I work with, and it gets annoying to have to type: cd ../../../../../../ To only find you're still a few directories from your root '...
14
votes
2answers
12k views

execute bit on directories, but not files [duplicate]

Possible Duplicate: How to apply recursively chmod directories without affecting files? What is the command to apply execute permission for directories (for traversal), but leave the execute bit ...
14
votes
1answer
3k views

What exactly is dot dot (..)? Why is its behavior different with symlinks?

I am trying to understand the nature of .. (double dot). It seems to point to different targets depending on how you access it. Example:- /outer/ middle/ inner/ inner ...
14
votes
6answers
18k views

How do I shorten the current directory path shown on terminal?

If I am in a deep directory, let's say: ~/Desktop/Dropbox/School/2017/C/A3/ then when I open up terminal, it says bob@bob-ubuntu:~/Desktop/Dropbox/School/2017/C/A3/$ and then I write my command. ...
14
votes
7answers
25k 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/...
14
votes
5answers
26k views

Transform a directory into file or a file into directory

I wanted to create a file named test. Accidentally I run mkdir test instead of touch test. Is it possible to convert test directory in a file named test? What about converting a file named test into ...
14
votes
3answers
22k views

find with -execdir

When I run find with -execdir I don't get the results I was expecting. For example: mkdir -p a/b/c find . -type d -execdir touch foo \; $ tree a a ├── b │   ├── c │   └── foo └── foo Directory c ...
14
votes
5answers
794 views

How can I find the first missing directory in a long path?

Imagine I have a path that doesn't exist: $ ls /foo/bar/baz/hello/world ls: cannot access /foo/bar/baz/hello/world: No such file or directory But let's say /foo/bar does exist. Is there a quick way ...
14
votes
1answer
7k views

Why is this empty directory 3.5MB?

I've just read this question: What does size of a directory mean in output of 'ls -l' command? ...which doesn't quite answer my question. Basically, I'm moving files onto a NAS. The folders I'...
13
votes
5answers
60k views

Creating numerous directories using mkdir

I would like to create many directories using mkdir. Each directory name will consist of a prefix (a string) and an index (an integer). Suppose that I would like the prefix to be "s" and the indices ...
13
votes
3answers
17k views

what is wild card to select all directories in a directory

i want to set sticky bit for all directories in a directory excluding files. is there any wild card to do this? #sudo chmod g+s /var/www/<WILD_CARD_FOR_ALL_DIRECTORIES>
13
votes
3answers
3k views

Why is it rm -rf and not rmdir -rf

I've always been curious why the command for deleting everything in a directory is rm -rf. Why aren't there flags to do the same thing with rmdir? Wouldn't it be more intuitive to use rmdir for ...
13
votes
4answers
7k 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 :...
13
votes
6answers
6k views

Best way run a command on each file in a directory tree

There appear be a number of ways to do this including loops in shell script, find and xargs. Which of these is best, and which is most portable?
13
votes
1answer
1k views

How many directories can be nested?

I'm curious, how many folders can be nested, and why? Is there a limit? What I mean by nested is when folders are in this structure: folder |_ folder |_ folder |_ folder |...
13
votes
5answers
15k views

Move every file that is not a directory

I have a directory that I am trying to clean out that contains both files and subdirectories. What I am trying to do is simple: move all the files into another directory, but leave all the sub-...
13
votes
3answers
5k views

Boot into a chroot?

I have Linux (Debian Jessie) installed on a hard drive. Drive - sda1, ext4fs, and sda2 - swap I have a /chroot folder. There is installed another system, in /chroot folder. Question: How to tell ...
12
votes
7answers
12k views

Is it possible to remove folder prefix from a `ls` command

I am in a bash script and I want to get the list of all files (let say all jar files). I execute the command ls -1 lib/*.jar and I get the output: lib/mylib_1.jar lib/mylib_2.jar ... Is there any ...
12
votes
6answers
8k views

Remove empty directory trees (removing as many directories as possible but no files)

Suppose I have a dir tree like this: ROOTDIR └--SUBDIR1 └----SUBDIR2 └----SUBDIR3 I am looking for a command such that when I input: $ [unknown command] ROOTDIR The whole ...
12
votes
6answers
15k views

progress information via pv for directory copy

I need to copy a very large directory (talking in terabytes here) and want to monitor the progress. I found that pv is a nice utility, but how can I use it for copying directories recursively? (pv ...
12
votes
3answers
5k views

Why are some files and folders hidden?

I can understand the rationale of hiding files and folders in the /home/user directory to prevent users from messing around with things. However, I do not see how the same rationale can be applied to ...
12
votes
4answers
3k views

Lowercasing all directories under a directory

I want to lowercase every directories' name under a directory. With which commands can I do that?
12
votes
1answer
9k views

gpg: WARNING: unsafe ownership on homedir '/home/user/.gnupg'

System: I am testing Linux Mint 19 Beta based on Ubuntu 18.04. I got this warning while installing an unrelated package: gpg: WARNING: unsafe ownership on homedir '/home/vlastimil/.gnupg' This is ...
12
votes
1answer
250 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 ...
12
votes
6answers
5k views

Exclude directories in locate search

A search with locate finds paths in the filesystem. Often, you know a priori you are interested in either files only, or directories only. A 'locate' search often returns many results. It would be ...
11
votes
4answers
39k views

Opening current directory from a terminal onto a file browser?

My current directory is buried deep in multiple subfolder layers from my home directory. If I want to open this directory in a gui-based file browser, I have to double click folder after folder to ...
11
votes
4answers
26k views

How to recursively list all hidden files and directories?

I want to list all hidden files and directories and then save result to file. Is there any command for this?
11
votes
1answer
3k views

What is the difference between 'ls' and 'ls -l' when I don't have execute permission on that directory?

I created a directory called folder and took away execute permission. $ mkdir folder $ touch folder/innerFile $ mkdir folder/innerFolder $ chmod -x folder Now if I do $ ls folder it outputs a list ...
11
votes
2answers
12k views

Difference between /usr/bin and /usr/local/bin [duplicate]

What is the difference between /usr/bin and /usr/local/bin? Why are there both directories and why do some executable programs exist in both directories?
11
votes
1answer
2k views

What is the significance of the dot in bash commands and how is it different from an asterisk?

I'm trying to understand the significance of the dot in bash and how it differs from an asterisk. Can someone please elaborate? For example, what's the difference between cp -ar /foo/. /foo2/ and cp ...
11
votes
2answers
4k views

the slash (/) after a directory name on shell commands

I have a little question here. If I have two files, say filea and fileb, mv filea fileb would delete fileb rename filea to fileb Then if I have two directories, say dira and dirb, mv dira dirb ...
11
votes
1answer
44k views

Delete files/ folders with .nfs files [duplicate]

A lot of time when I delete a folder, it says cannot be deleted because of .nfs files Error - Device or resource busy How can I delete a folder ignoring these errors ( is there any flag in rm ...
10
votes
10answers
17k 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 ...
10
votes
6answers
14k views

How do you check if a file exists within awk? [-d 'filename'] failing

I'm trying to generate a list of users who have a home directory set which does not exist. It seems I should be able to do this with awk, but something is wrong with my syntax. It keeps telling me "...
10
votes
4answers
520 views

How to extract a specifically named folder from a recursive directory, delete the others?

I have this kind of directory tree that is obtained from unzipping a zip file: x -> y -> z -> run -> FILES AND DIRECTORIES HERE So there are 4 directories, 3 of whom are empty of files (x, y, z) ...
10
votes
7answers
9k views

Find list of directories one level deep from matching directory

I'm trying to get a list of directories that are contained within a specific folder. Given these example folders: foo/bar/test foo/bar/test/css foo/bar/wp-content/plugins/XYZ foo/bar/wp-content/...
10
votes
2answers
5k views

How can I stop ls from descending into directories, similar to prune for find?

If I type ls *ro* I also get files in subdirectories that match the *ro* pattern. Is there any option for ls similar to prune? Ideally a flag, otherwise perhaps an exec?
10
votes
1answer
23k 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
11k 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
978 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
2answers
21k 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 ...