Skip to main content

Questions tagged [directory]

A file system structure in which to store computer files.

Filter by
Sorted by
Tagged with
529 votes
14 answers
904k 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
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
374 votes
5 answers
697k 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
347 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
391k 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
257 votes
16 answers
327k 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
257 votes
12 answers
514k views

How can I calculate the size of a directory?

How to know the size of a directory? Including subdirectories and files.
Juanjo Conti's user avatar
  • 2,733
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
256 votes
14 answers
367k views

Find the total size of certain files within a directory branch

Assume there's an image storage directory, say, ./photos/john_doe, within which there are multiple subdirectories, where many certain files reside (say, *.jpg). How can I calculate a summary size of ...
mbaitoff's user avatar
  • 5,161
254 votes
14 answers
513k views

How to recursively find the amount stored in directory?

I know you are able to see the byte size of a file when you do a long listing with ll or ls -l. But I want to know how much storage is in a directory including the files within that directory and the ...
Rob Avery IV's user avatar
  • 3,175
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
228 votes
10 answers
302k views

How to copy-merge two directories?

I have two directories images and images2 with this structure in Linux: /images/ad /images/fe /images/foo ... and other 4000 folders and the other is like: /images2/ad /images2/fe /...
ssierral's user avatar
  • 2,383
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
9 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
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
165 votes
13 answers
172k 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. foo....
LanceBaynes's user avatar
  • 40.7k
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
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
142 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
  • 2,000
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
122 votes
7 answers
188k views

rsync compare directories?

Is it possible to compare two directories with rsync and only print the differences? There's a dry-run option, but when I increase verbosity to a certain level, every file compared is shown. ls -alR ...
chris's user avatar
  • 1,695
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,727
118 votes
3 answers
107k views

How to make tree output only directories?

150 directories I can handle but 900 files is too many for a review. I've no manual entry for tree so maybe I can ask you if you know how to output only directories since files get too detailed? . ├──...
Niklas Rosencrantz'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
113 votes
8 answers
796k 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
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
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
97 votes
5 answers
198k 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
97 votes
14 answers
522k 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 example,...
whiterose's user avatar
  • 1,079
92 votes
3 answers
102k views

Difference between "cd -" and "cd ~-"

The Bash command cd - prints the previously used directory and changes to it. On the other hand, the Bash command cd ~- directly changes to the previously used directory, without echoing ...
dr_'s user avatar
  • 30.4k
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
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
86 votes
10 answers
136k 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. ...
K Split X's user avatar
  • 1,763
83 votes
11 answers
365k views

Using sftp to Transfer a Directory?

When I try to use sftp to transfer a directory containing files, I get an error message: skipping non-regular file directory_name The directory contains a couple of files and two subdirectories. ...
haziz's user avatar
  • 2,241
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,260
80 votes
6 answers
205k views

How do I remove all sub-directories from within a directory?

This question is kind of a phase II to the first question I posted at here I have a directory that contains a bunch of sub-directories, .zip files, and other random files not contained within a sub-...
Evster's user avatar
  • 1,715
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
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
75 votes
5 answers
11k 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) ...
bluish's user avatar
  • 973
74 votes
9 answers
195k views

Get a list of directory names with find

I know I can do this to get a list of directory names: find . -type d -maxdepth 1 The output looks like this: . ./foo ./bar I prefer the listing without ./. Is there a way to get find to output ...
joachim's user avatar
  • 7,767
71 votes
1 answer
104k views

How to create a file and parent directories in one command? [duplicate]

Is there a flag/option for touch, mkdir, >, or some other command that will allow me to create a file and any non-existent parent directories at the same time? For instance, let's say I'm in an ...
Jeff Puckett's user avatar
65 votes
6 answers
210k views

How can I list subdirectories recursively?

The obvious ls -dR does not work. I am currently using find /path/ -type d -ls but the output is not what I need (plain listing of sub-folders) Is there a way out?
Nemo's user avatar
  • 788
65 votes
3 answers
46k 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 ...
janos's user avatar
  • 11.5k
64 votes
5 answers
7k 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 ...
Michael Durrant's user avatar
60 votes
14 answers
47k 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 ...
Mike B's user avatar
  • 9,000
59 votes
4 answers
269k views

How can I delete all files with a particular extension in a particular folder?

If I set the current/working directory (navigating to it using cd) to some particular directory and then type: rm *.xvg What will this command do? Is it true that the above command will only delete ...
Andrew's user avatar
  • 17.2k
58 votes
5 answers
118k views

Create target directory when extracting tarball

Is it possible to create a target directory, similar to mkdir -p, where I can define a non-existent target directory within my tar command, and tar will create the directory for me? I know I can ...
wulfgarpro's user avatar
58 votes
2 answers
176k views

cat files in current folder and all subfolders [duplicate]

I want to cat a file in current folder and all files in all subfolders (and subsubfolders). Here is my directory structure $ tree . ├── f │   └── foo └── yo I want to cat foo and yo. I've tried ...
Mohsen's user avatar
  • 2,625
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
56 votes
6 answers
147k views

Better way to copy multiple directories to new directory

Is there a better way on the command line to essentially accomplish the following but with a single command cp -r css/ ar/ cp -r images/ ar/ cp -r js/ ar/ cp -r backups/ ar/ I've just been stringing ...
user avatar

1
2 3 4 5
36